Skip to content
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 apps/temporary-admin/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ RUN chown -R nginx:nginx /var/run/nginx.pid \
USER nginx

# expose a specific port on the docker container
ENV PORT=80
ENV PORT=3001
EXPOSE ${PORT}

# start the server using the previously build application
Expand Down
4 changes: 2 additions & 2 deletions apps/temporary-admin/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<p align="right">
<a href="https://amplication.com" target="_blank">
<img alt="amplication-logo" height="70" alt="Amplication Logo" src="https://amplication.com/images/amplication-logo-purple.svg"/>
<img alt="amplication-logo" height="70" alt="Amplication Logo" src="https://amplication.com/images/logo.svg"/>
</a>
</p>

# Introduction

This service was generated with Amplication. It serves as the client-side for the generated server component. The client-side consist of a React application with ready-made forms for creating and editing the different data models of the application. It is pre-conffigured to work with the server and comes with the boilerplate and foundation for the client - i.e., routing, navigation, authentication, premissions, menu, breadcrumbs, error handling and much more. Additional information about the admin component and the architecture around it, can be found on the [documentation](https://docs.amplication.com/guides/getting-started) site. This side of the generated project was bootstrapped with [create-react-app](https://github.com/facebook/create-react-app) and built with [react-admin](https://marmelab.com/react-admin/).
This service was generated with Amplication. It serves as the client-side for the generated server component. The client-side consist of a React application with ready-made forms for creating and editing the different data models of the application. It is pre-conffigured to work with the server and comes with the boilerplate and foundation for the client - i.e., routing, navigation, authentication, permissions, menu, breadcrumbs, error handling and much more. Additional information about the admin component and the architecture around it, can be found on the [documentation](https://docs.amplication.com/guides/getting-started) site. This side of the generated project was bootstrapped with [create-react-app](https://github.com/facebook/create-react-app) and built with [react-admin](https://marmelab.com/react-admin/).


<p align="center">
Expand Down
2 changes: 1 addition & 1 deletion apps/temporary-admin/configuration/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
server_tokens off;

server {
listen 8080;
listen 3001;
server_name localhost;
location / {
root /usr/share/nginx/html;
Expand Down
3 changes: 1 addition & 2 deletions apps/temporary-admin/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
// @ts-ignore
// eslint-disable-next-line import/no-unresolved

import App from "./App";
import reportWebVitals from "./reportWebVitals";

Expand Down
1 change: 0 additions & 1 deletion apps/temporary-admin/src/user/RolesOptions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//@ts-ignore
import { ROLES } from "./roles";

declare interface Role {
Expand Down
10 changes: 5 additions & 5 deletions apps/temporary/.env
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
BCRYPT_SALT=10
COMPOSE_PROJECT_NAME=amp_clmypp40t05ojm801iwsykclg
PORT=3000
DB_URL=postgres://admin:admin@localhost:5432/my-db
DB_USER=admin
DB_NAME=my-db
DB_PASSWORD=admin
DB_PORT=5432
DB_NAME=my-db
DB_URL=postgres://admin:admin@localhost:5432/my-db
DB_USER=admin
JWT_EXPIRATION=2d
JWT_SECRET_KEY=Change_ME!!!
JWT_EXPIRATION=2d
PORT=3000
2 changes: 1 addition & 1 deletion apps/temporary/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p align="right">
<a href="https://amplication.com" target="_blank">
<img alt="amplication-logo" height="70" alt="Amplication Logo" src="https://amplication.com/images/amplication-logo-purple.svg"/>
<img alt="amplication-logo" height="70" alt="Amplication Logo" src="https://amplication.com/images/logo.svg"/>
</a>
</p>

Expand Down
1 change: 1 addition & 0 deletions apps/temporary/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ services:
DB_URL: postgres://${DB_USER}:${DB_PASSWORD}@db:5432/${DB_NAME}
depends_on:
- migrate
restart: on-failure
migrate:
build:
context: .
Expand Down
6 changes: 5 additions & 1 deletion apps/temporary/nest-cli.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"sourceRoot": "src",
"compilerOptions": {
"assets": ["swagger"]
"assets": [
{
"include": "swagger/**/*"
}
]
}
}
76 changes: 39 additions & 37 deletions apps/temporary/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"seed": "ts-node scripts/seed.ts",
"db:migrate-save": "prisma migrate dev",
"db:migrate-up": "prisma migrate deploy",
"db:clean": "ts-node scripts/clean.ts",
"db:clean": "prisma migrate reset",
"db:init": "run-s \"db:migrate-save -- --name 'initial version'\" db:migrate-up seed",
"prisma:generate": "prisma generate",
"docker:dev": "docker-compose -f docker-compose.dev.yml up -d",
Expand All @@ -19,57 +19,59 @@
"compose:down": "docker-compose down --volumes"
},
"dependencies": {
"@nestjs/common": "8.4.7",
"@nestjs/config": "1.1.5",
"@nestjs/core": "8.4.7",
"@nestjs/graphql": "9.1.2",
"@nestjs/platform-express": "8.4.7",
"@nestjs/serve-static": "2.2.2",
"@nestjs/swagger": "5.1.5",
"@apollo/server": "^4.9.4",
"@nestjs/apollo": "12.0.9",
"@nestjs/common": "10.2.7",
"@nestjs/config": "3.1.1",
"@nestjs/core": "10.2.7",
"@nestjs/graphql": "12.0.9",
"@nestjs/jwt": "^10.1.1",
"@nestjs/passport": "^10.0.2",
"@nestjs/platform-express": "10.2.7",
"@nestjs/serve-static": "4.0.0",
"@nestjs/swagger": "7.1.13",
"@prisma/client": "^5.4.2",
"@types/bcrypt": "5.0.0",
"@prisma/client": "4.6.1",
"apollo-server-express": "3.6.1",
"bcrypt": "5.0.1",
"bcrypt": "5.1.1",
"class-transformer": "0.5.1",
"class-validator": "0.14.0",
"dotenv": "^16.1.4",
"graphql": "15.7.2",
"dotenv": "16.3.1",
"graphql": "^16.8.1",
"graphql-type-json": "0.3.2",
"nest-access-control": "2.0.3",
"nest-morgan": "1.0.1",
"nest-access-control": "^3.1.0",
"npm-run-all": "4.1.5",
"reflect-metadata": "0.1.13",
"swagger-ui-express": "4.3.0",
"ts-node": "10.9.1",
"type-fest": "0.13.1",
"validator": "^13.9.0",
"@nestjs/jwt": "^10.0.2",
"@nestjs/passport": "^9.0.0",
"passport": "0.6.0",
"passport-http": "0.3.0",
"passport-jwt": "4.0.1"
"passport-jwt": "4.0.1",
"reflect-metadata": "0.1.13",
"ts-node": "10.9.2",
"type-fest": "2.19.0",
"validator": "13.11.0"
},
"devDependencies": {
"@nestjs/cli": "8.2.5",
"@nestjs/testing": "8.4.7",
"@types/express": "4.17.9",
"@types/graphql-type-json": "0.3.2",
"@types/jest": "26.0.19",
"@nestjs/cli": "^10.1.18",
"@nestjs/testing": "^10.2.7",
"@types/express": "^4.17.19",
"@types/graphql-type-json": "0.3.3",
"@types/jest": "^29.5.5",
"@types/normalize-path": "3.0.0",
"@types/supertest": "2.0.11",
"@types/validator": "^13.7.15",
"jest": "27.0.6",
"jest-mock-extended": "^2.0.4",
"prisma": "4.6.1",
"supertest": "4.0.2",
"ts-jest": "27.0.3",
"typescript": "4.3.5",
"@types/passport-http": "0.3.9",
"@types/passport-jwt": "3.0.8"
"@types/passport-jwt": "3.0.10",
"@types/supertest": "^2.0.14",
"@types/validator": "^13.11.2",
"jest": "^29.7.0",
"jest-mock-extended": "^3.0.5",
"prisma": "^5.4.2",
"supertest": "^6.3.3",
"ts-jest": "^29.1.1",
"typescript": "^5.4.3"
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"moduleNameMapper": {
"@app/custom-validators": "<rootDir>/src/validators"
},
"modulePathIgnorePatterns": ["<rootDir>/dist/"]
}
}
58 changes: 0 additions & 58 deletions apps/temporary/scripts/clean.ts

This file was deleted.

19 changes: 6 additions & 13 deletions apps/temporary/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { Module, Scope } from "@nestjs/common";
import { APP_INTERCEPTOR } from "@nestjs/core";
import { MorganInterceptor, MorganModule } from "nest-morgan";
import { Module } from "@nestjs/common";
import { UserModule } from "./user/user.module";
import { HealthModule } from "./health/health.module";
import { PrismaModule } from "./prisma/prisma.module";
Expand All @@ -9,6 +7,7 @@ import { ServeStaticModule } from "@nestjs/serve-static";
import { ServeStaticOptionsService } from "./serveStaticOptions.service";
import { ConfigModule, ConfigService } from "@nestjs/config";
import { GraphQLModule } from "@nestjs/graphql";
import { ApolloDriver, ApolloDriverConfig } from "@nestjs/apollo";

import { ACLModule } from "./auth/acl.module";
import { AuthModule } from "./auth/auth.module";
Expand All @@ -22,13 +21,13 @@ import { AuthModule } from "./auth/auth.module";
HealthModule,
PrismaModule,
SecretsManagerModule,
MorganModule,
ConfigModule.forRoot({ isGlobal: true }),
ServeStaticModule.forRootAsync({
useClass: ServeStaticOptionsService,
}),
GraphQLModule.forRootAsync({
useFactory: (configService) => {
GraphQLModule.forRootAsync<ApolloDriverConfig>({
driver: ApolloDriver,
useFactory: (configService: ConfigService) => {
const playground = configService.get("GRAPHQL_PLAYGROUND");
const introspection = configService.get("GRAPHQL_INTROSPECTION");
return {
Expand All @@ -42,12 +41,6 @@ import { AuthModule } from "./auth/auth.module";
imports: [ConfigModule],
}),
],
providers: [
{
provide: APP_INTERCEPTOR,
scope: Scope.REQUEST,
useClass: MorganInterceptor("combined"),
},
],
providers: [],
})
export class AppModule {}
1 change: 1 addition & 0 deletions apps/temporary/src/auth/IAuthStrategy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { UserInfo } from "./UserInfo";

export interface IAuthStrategy {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
validate: (...any: any) => Promise<UserInfo>;
}
7 changes: 6 additions & 1 deletion apps/temporary/src/auth/abac.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ export function getInvalidAttributes(
// eslint-disable-next-line @typescript-eslint/ban-types
data: Object
): string[] {
const filteredData = permission.filter(data);
// The structuredClone call is necessary because the
// `Permission.filter` function doesn't consider objects
// with null prototypes. And in graphql requests, the
// object passed here by the request interceptor is an object
// with a null prototype.
const filteredData = permission.filter(structuredClone(data));
return Object.keys(data).filter((key) => !(key in filteredData));
}
3 changes: 1 addition & 2 deletions apps/temporary/src/auth/acl.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { AccessControlModule, RolesBuilder } from "nest-access-control";
// @ts-ignore
// eslint-disable-next-line import/no-unresolved

import grants from "../grants.json";

// eslint-disable-next-line @typescript-eslint/naming-convention
Expand Down
7 changes: 5 additions & 2 deletions apps/temporary/src/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { forwardRef, Module } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { JwtModule } from "@nestjs/jwt";
import { PassportModule } from "@nestjs/passport";
import { JWT_EXPIRATION, JWT_SECRET_KEY } from "../constants";
import { JWT_EXPIRATION } from "../constants";
import { SecretsManagerModule } from "../providers/secrets/secretsManager.module";
import { SecretsManagerService } from "../providers/secrets/secretsManager.service";
import { EnumSecretsNameKey } from "../providers/secrets/secretsNameKey.enum";
import { AuthController } from "./auth.controller";
import { AuthResolver } from "./auth.resolver";
import { AuthService } from "./auth.service";
Expand All @@ -25,7 +26,9 @@ import { UserModule } from "../user/user.module";
secretsService: SecretsManagerService,
configService: ConfigService
) => {
const secret = await secretsService.getSecret<string>(JWT_SECRET_KEY);
const secret = await secretsService.getSecret<string>(
EnumSecretsNameKey.JwtSecretKey
);
const expiresIn = configService.get(JWT_EXPIRATION);
if (!secret) {
throw new Error("Didn't get a valid jwt secret");
Expand Down
2 changes: 1 addition & 1 deletion apps/temporary/src/auth/auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const USER: any = {
const SIGN_TOKEN = "SIGN_TOKEN";

const authEntityService = {
findOne(args: { where: { username: string } }): any | null {
user(args: { where: { username: string } }): any | null {
if (args.where.username === VALID_CREDENTIALS.username) {
return USER;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/temporary/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class AuthService {
username: string,
password: string
): Promise<UserInfo | null> {
const user = await this.userService.findOne({
const user = await this.userService.user({
where: { username },
});
if (user && (await this.passwordService.compare(password, user.password))) {
Expand Down
4 changes: 1 addition & 3 deletions apps/temporary/src/auth/gqlDefaultAuth.guard.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { ExecutionContext } from "@nestjs/common";
import { GqlExecutionContext } from "@nestjs/graphql";
import type { Request } from "express";
// @ts-ignore
// eslint-disable-next-line
import { DefaultAuthGuard } from "./defaultAuth.guard";

export class GqlDefaultAuthGuard extends DefaultAuthGuard {
// This method is required for the interface - do not delete it.
getRequest(context: ExecutionContext): Request {
getRequest<Request>(context: ExecutionContext): Request {
const ctx = GqlExecutionContext.create(context);
return ctx.getContext<{ req: Request }>().req;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/temporary/src/auth/jwt/base/jwt.strategy.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class JwtStrategyBase

async validate(payload: UserInfo): Promise<UserInfo> {
const { username } = payload;
const user = await this.userService.findOne({
const user = await this.userService.user({
where: { username },
});
if (!user) {
Expand Down
Loading