Skip to content

Feature/initial api #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.env
.yarn

# compiled output
/dist
/node_modules

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn lint
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
29 changes: 29 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2020 Concepta Technologies, LLC
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14 changes: 14 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: "3.4"

volumes:
rockets:

services:
rockets-playground-postgres:
image: postgres
ports:
- 5432:5432
environment:
POSTGRES_DB: rockets-playground
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
44 changes: 44 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "rockets-playground",
"license": "proprietary",
"private": true,
"workspaces": {
"packages": [
"packages/*"
]
},
"scripts": {
"start": "yarn start:api",
"start:dev": "yarn start:api:dev",
"start:debug": "yarn start:api:debug",
"start:api": "yarn workspace rockets-playground-api start",
"start:api:dev": "yarn workspace rockets-playground-api start:dev",
"start:api:debug": "yarn workspace rockets-playground-api start:debug",
"dev:web": "yarn workspace web dev --force",
"build": "yarn build:common && yarn build:api && yarn build:web",
"build:common": "yarn workspace rockets-playground-common build",
"build:api": "yarn workspace rockets-playground-api build",
"build:web": "yarn workspace web build",
"test": "yarn test:common && yarn test:api",
"test:common": "yarn workspace rockets-playground-common test",
"test:api": "yarn workspace rockets-playground-api test",
"lint": "yarn lint:common && yarn lint:api",
"lint:fix": "yarn lint:common:fix && yarn lint:api:fix",
"lint:common": "yarn workspace rockets-playground-common lint",
"lint:common:fix": "yarn workspace rockets-playground-common lint:fix",
"lint:api": "yarn workspace rockets-playground-api lint",
"lint:api:fix": "yarn workspace rockets-playground-api lint:fix",
"prepare": "husky"
},
"dependencies": {
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"pg": "^8.12.0",
"rxjs": "^7.8.1",
"typeorm": "^0.3.20"
},
"devDependencies": {
"husky": "^9.0.11"
},
"packageManager": "[email protected]"
}
36 changes: 36 additions & 0 deletions packages/api/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# DATABASE
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/rockets-starter
DATABASE_SSL=
DATABASE_MIGRATIONS_RUN=

# SENTRY
SENTRY_LOG_LEVEL="log,error"
SENTRY_DSN=

# SWAGGER
SWAGGER_ENABLED=

# JWT
JWT_MODULE_ACCESS_SECRET=
JWT_MODULE_REFRESH_SECRET=
JWT_MODULE_ACCESS_EXPIRES_IN=
JWT_MODULE_REFRESH_EXPIRES_IN=

# MAILGUN
MAILGUN_DOMAIN=
MAILGUN_API_KEY=
MAILGUN_SMTP_SERVER=
MAILGUN_SMTP_PORT=587
MAILGUN_SMTP_LOGIN=
MAILGUN_SMTP_PASSWORD=

# MAIL
NODEMAILER_FROM_EMAIL=
NODEMAILER_TEMPLATE_PATH=

# AUTH RESET URL
AUTH_URL_RESET_PASSWORD=

# SERVER
PORT=
CORS_ORIGIN=
9 changes: 9 additions & 0 deletions packages/api/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
extends: ['@concepta/eslint-config/nest'],
parserOptions: {
tsconfigRootDir: __dirname,
},
rules: {
"@darraghor/nestjs-typed/param-decorator-name-matches-route-param": "off"
}
};
7 changes: 7 additions & 0 deletions packages/api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# compiled output
/dist
/node_modules

# Tests
/coverage
/.nyc_output
3 changes: 3 additions & 0 deletions packages/api/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('@concepta/prettier-config/node'),
};
Empty file added packages/api/README.md
Empty file.
10 changes: 10 additions & 0 deletions packages/api/nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"assets": ["/assets/**/*"],
"watchAssets": true,
"deleteOutDir": true
}
}
120 changes: 120 additions & 0 deletions packages/api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
{
"name": "rockets-playground-api",
"version": "0.0.1",
"description": "Rockets Playground API",
"author": "Concepta Team",
"license": "BSD-3-Clause",
"private": true,
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"src/**/*.ts\"",
"lint:fix": "yarn lint --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"typeorm": "typeorm -d ./dist/ormconfig.js",
"schema:drop": "yarn typeorm schema:drop",
"schema:sync": "yarn typeorm schema:sync",
"schema:rebuild": "yarn schema:drop && yarn schema:sync",
"migration:create": "yarn typeorm migration:create",
"migration:generate": "yarn typeorm migration:generate",
"migration:show": "yarn typeorm migration:show",
"migration:run": "yarn typeorm migration:run",
"migration:revert": "yarn typeorm migration:revert",
"migration:rebuild": "yarn schema:drop && yarn migration:run",
"seed:config": "typeorm-seeding config -r ./dist -c seeding.js",
"seed:run": "typeorm-seeding seed -r ./dist -c seeding.js",
"seed:rebuild": "yarn migration:rebuild && yarn seed:run",
"sandbox:init": "yarn migration:run && yarn seed:run",
"sandbox:rebuild": "yarn seed:rebuild"
},
"dependencies": {
"@concepta/nestjs-access-control": "^v6.0.0-alpha.0",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i believe Marshal released a new version recently we are on v6.0.0-alpha.1 now

"@concepta/nestjs-auth-jwt": "^v6.0.0-alpha.0",
"@concepta/nestjs-auth-local": "^v6.0.0-alpha.0",
"@concepta/nestjs-auth-recovery": "^v6.0.0-alpha.0",
"@concepta/nestjs-auth-refresh": "^v6.0.0-alpha.0",
"@concepta/nestjs-authentication": "^v6.0.0-alpha.0",
"@concepta/nestjs-common": "v6.0.0-alpha.0",
"@concepta/nestjs-crud": "^v6.0.0-alpha.0",
"@concepta/nestjs-email": "v6.0.0-alpha.0",
"@concepta/nestjs-exception": "^v6.0.0-alpha.0",
"@concepta/nestjs-jwt": "^v6.0.0-alpha.0",
"@concepta/nestjs-logger": "v6.0.0-alpha.0",
"@concepta/nestjs-logger-sentry": "v6.0.0-alpha.0",
"@concepta/nestjs-otp": "^v6.0.0-alpha.0",
"@concepta/nestjs-password": "^v6.0.0-alpha.0",
"@concepta/nestjs-role": "^v6.0.0-alpha.0",
"@concepta/nestjs-swagger-ui": "^v6.0.0-alpha.0",
"@concepta/nestjs-typeorm-ext": "^v6.0.0-alpha.0",
"@concepta/nestjs-user": "^v6.0.0-alpha.0",
"@concepta/typeorm-common": "^v6.0.0-alpha.0",
"@concepta/typeorm-seeding": "^4.0.0-beta.1",
"@nestjs-modules/mailer": "^2.0.2",
"@nestjs/axios": "^3.1.0",
"@nestjs/common": "^10.4.1",
"@nestjs/config": "^3.2.3",
"@nestjs/core": "^10.4.1",
"@nestjs/platform-express": "^10.4.1",
"accesscontrol": "^2.2.1",
"axios": "^1.7.7",
"reflect-metadata": "^0.2.0",
"rockets-playground-common": "*",
"typeorm": "*"
},
"devDependencies": {
"@concepta/eslint-config": "1.1.4",
"@concepta/prettier-config": "^1.1.5",
"@darraghor/eslint-plugin-nestjs-typed": "^5.0.18",
"@faker-js/faker": "^8.4.1",
"@nestjs/cli": "^10.4.1",
"@nestjs/schematics": "^10.1.4",
"@nestjs/testing": "^10.4.1",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
"@types/supertest": "^6.0.0",
"@typescript-eslint/parser": "^7.0.0",
"eslint": "^8.56.0",
"jest": "27.0.6",
"prettier": "^2.3.2",
"source-map-support": "^0.5.21",
"supertest": "^7.0.0",
"ts-jest": "^27.0.3",
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typescript": "^4.9.4"
},
"peerDependencies": {
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"pg": "^8.12.0",
"rxjs": "^7.8.1"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
62 changes: 62 additions & 0 deletions packages/api/src/app.acl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { AccessControl } from 'accesscontrol';
import { UserResource } from '@concepta/nestjs-user';
import { RoleAssignmentResource, RoleResource } from '@concepta/nestjs-role';
import { createResources } from './common/utils/create-resources.util';
import { UserProfileResource } from './modules/user-profile/user-profile.types';
import { StoreResource } from './modules/store/store.types';
import { MeResource } from './modules/me/me.types';
import { ProductResource } from './modules/product/product.types';

export enum AppRole {
SuperAdmin = 'SuperAdmin',
User = 'User',
}

const allResources = createResources(
UserResource,
RoleAssignmentResource,
RoleResource,
UserProfileResource,
StoreResource,
ProductResource,
MeResource,
);

const userResources = createResources(MeResource);

export const acRules: AccessControl = new AccessControl();

acRules
.grant(AppRole.SuperAdmin)
.resource(allResources)
.createOwn()
.createAny()
.readOwn()
.readAny()
.updateOwn()
.updateAny()
.deleteOwn()
.deleteAny();

const allRoles = Object.values(AppRole);

acRules
.grant(AppRole.User)
.resource(userResources)
.readOwn()
.resource([UserResource.One, UserProfileResource.One])
.updateOwn()
.resource([
StoreResource.One,
StoreResource.Many,
ProductResource.One,
ProductResource.Many,
])
.readAny();

acRules
.grant(allRoles)
.resource([UserProfileResource.One, MeResource.One])
.readOwn();

acRules.deny(allRoles).resource(UserResource.One).deleteOwn();
Loading