Skip to content
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

[LAYER] Feature: Layer Version Implementation 💹 #1

Merged
merged 9 commits into from
Jul 27, 2023
Merged
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
21 changes: 17 additions & 4 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,24 @@ jobs:
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
- uses: actions/setup-python@v2
- uses: aws-actions/setup-sam@v1
- uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Verify secrets
run: echo ${{ secrets.AWS_REGION }}
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Eslint
run: yarn lint
- name: Compilation
run: yarn compile
- name: FN Eslint
run: cd lambdas && yarn && yarn lint
- name: Layers Eslint
run: cd layers/general && yarn && yarn lint
- name: Layers Compilation
run: cd layers/general && yarn build
- name: Building
run: yarn build
# - name: Tests
# run: yarn test
21 changes: 17 additions & 4 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,24 @@ jobs:
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
- uses: actions/setup-python@v2
- uses: aws-actions/setup-sam@v1
- uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Verify secrets
run: echo ${{ secrets.AWS_REGION }}
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Eslint
run: yarn lint
- name: Compilation
run: yarn compile
- name: FN Eslint
run: cd lambdas && yarn && yarn lint
- name: Layers Eslint
run: cd layers/general && yarn && yarn lint
- name: Layers Compilation
run: cd layers/general && yarn build
- name: Building
run: yarn build
# - name: Tests
# run: yarn test
4 changes: 0 additions & 4 deletions .husky/pre-push

This file was deleted.

120 changes: 120 additions & 0 deletions lambdas/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
{
"name": "users-api",
"version": "1.0.0",
"description": "Exception Users microservice",
"author": "Exception Corporation",
"license": "ISC",
"scripts": {
"start": "yarn build && sam local start-api --docker-network sam-user-api -n .env.json",
"start:prod": "yarn build && sam local start-api --template-file .aws-sam/build/template.yaml --docker-network sam-user-api -n .env.json",
"build": "sam build --beta-features",
"deploy:production": "yarn build && sam deploy --template-file .aws-sam/build/template.yaml --stack-name user-service-production --s3-bucket user-bags-service-production --capabilities CAPABILITY_IAM --no-fail-on-empty-changeset --parameter-overrides TableName=BgUsers DeployEnviroment=prod IsOffline=false DynamoHost=dynamodb.us-east-1.amazonaws.com AWSRegion=us-east-1 Expiration=2 SecretKey=shhh",
"delete:production": "sam delete --stack-name user-service-production",
"deploy:staging": "yarn build && sam deploy --template-file .aws-sam/build/template.yaml --stack-name user-service-staging --s3-bucket user-bags-service-staging --capabilities CAPABILITY_IAM --no-fail-on-empty-changeset --parameter-overrides TableName=BgUsers DeployEnviroment=prod IsOffline=false DynamoHost=dynamodb.us-east-1.amazonaws.com AWSRegion=us-east-1 Expiration=2 SecretKey=shhh",
"delete:staging": "sam delete --stack-name user-service-staging",
"invoke:create": "yarn build && sam local invoke 'CreateUser' --docker-network sam-user-api -e events/event.json -n .env.json",
"invoke:update": "yarn build && sam local invoke 'UpdateUsers' --docker-network sam-user-api -e events/event.json -n .env.json",
"invoke:getAll": "yarn build && sam local invoke 'GetUsers' --docker-network sam-user-api -e events/event.json -n .env.json",
"invoke:getById": "yarn build && sam local invoke 'GetUserById' --docker-network sam-user-api -e events/event.json -n .env.json",
"invoke:delete": "yarn build && sam local invoke 'DeleteUser' --docker-network sam-user-api -e events/event.json -n .env.json",
"invoke:login": "yarn build && sam local invoke 'LoginUser' --docker-network sam-user-api -e events/event.json -n .env.json",
"invoke:noti": "yarn build && sam local invoke 'NotificationUser' --docker-network sam-user-api -e events/event.json -n .env.json",
"invoke:all": "yarn invoke:create && yarn invoke:update && yarn invoke:getAll && yarn invoke:getById && yarn invoke:delete",
"format": "prettier 'src/**/*.ts' --write",
"compile": "tsc",
"compile:watch": "tsc -w --preserveWatchOutput true",
"lint": "eslint ./src --ext .ts",
"test": "jest --runInBand",
"test:watch": "jest --watch",
"run-checks": "yarn lint && yarn test && yarn compile"
},
"dependencies": {
"esbuild": "0.14.14"
},
"devDependencies": {
"@types/jest": "29.2.0",
"@types/node": "18.11.4",
"@typescript-eslint/eslint-plugin": "5.10.2",
"@typescript-eslint/parser": "5.10.2",
"eslint": "8.8.0",
"eslint-config-airbnb-typescript": "14.0.2",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-import": "2.25.2",
"eslint-plugin-jest": "25.2.4",
"eslint-plugin-prettier": "4.0.0",
"jest": "29.2.1",
"prettier": "2.5.1",
"rimraf": "3.0.2",
"ts-jest": "29.0.5",
"ts-node": "10.9.1",
"typescript": "4.8.4"
},
"jest": {
"moduleFileExtensions": [
"ts",
"js"
],
"rootDir": ".",
"collectCoverageFrom": [
"src/**/*.{js,ts}"
],
"testRegex": ".(e2e-)?spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"coverageDirectory": "./coverage",
"testEnvironment": "node",
"collectCoverage": true,
"coverageThreshold": {
"global": {
"branches": 80,
"functions": 80,
"lines": 80,
"statements": 80
}
}
},
"prettier": {
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"trailingComma": "none",
"endOfLine": "auto"
},
"eslintConfig": {
"parser": "@typescript-eslint/parser",
"env": {
"jest": true,
"browser": true,
"commonjs": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
"warnOnUnsupportedTypeScriptVersion": false
},
"extends": [
"prettier",
"eslint:recommended"
],
"plugins": [
"prettier"
],
"rules": {
"prettier/prettier": "warn",
"no-var": "warn",
"no-unused-vars": "off",
"no-console": [
"error",
{
"allow": [
"info",
"warn",
"error"
]
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { APIGatewayProxyResult, Handler } from 'aws-lambda';
import { User, UserPrimitives } from '@/domain/entities/User';
import {
APIGatewayProxyResult,
RequestDTO,
Handler,
formatErrorResponse,
formatJSONResponse
} from '@/domain/response/formatJSONResponse';
import middify from '@/infrastructure/middlewares/middify';
import { RequestDTO } from '@/infrastructure/middlewares/RequestDTO';
import { GlobalFunctions } from '@/infrastructure/utils';
formatJSONResponse,
middify,
DomainError,
GlobalFunctions,
UserRepository,
User,
HttpStatus,
UserPrimitives
} from '/opt/infra/index';
import { CreateUserDTO } from '@/functions/dtos/create-user.dto';
import HttpStatus from '@/domain/types/HttpStatus';
import { DomainError } from '@/domain/errors/DomainError';
import { UserRepository } from '@/infrastructure/database';

const createUser = async (
event: RequestDTO<CreateUserDTO>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { APIGatewayProxyResult, APIGatewayEvent, Handler } from 'aws-lambda';
import { IDPathParameterMissing } from '@/domain/errors/IDPathParameterMissing';
import {
APIGatewayProxyResult,
APIGatewayEvent,
Handler,
formatErrorResponse,
formatJSONResponse
} from '@/domain/response/formatJSONResponse';
import { UserId } from '@/domain/entities/value-objects/user.id';
import { DomainError } from '@/domain/errors/DomainError';
import middify from '@/infrastructure/middlewares/middify';
import HttpStatus from '@/domain/types/HttpStatus';
import { UserRepository } from '@/infrastructure/database';
import { ADMINISTRATORS } from '@/domain/types/user.role';
formatJSONResponse,
middify,
DomainError,
IDPathParameterMissing,
UserRepository,
UserId,
HttpStatus,
ADMINISTRATORS
} from '/opt/infra/index';

const deleteUser = async (
event: APIGatewayEvent & { body: any }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'reflect-metadata';
import { IsString, IsNumber, IsOptional, MinLength } from 'class-validator';
import { UserRole } from '@/domain/types/user.role';
import { IsString, IsNumber, IsOptional, MinLength } from '/opt/infra/index';
import { UserRole } from '/opt/infra/index';

export class CreateUserDTO {
@IsString()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'reflect-metadata';
import { IsOptional, IsString } from 'class-validator';
import { IsOptional, IsString } from '/opt/infra/index';

export class LoginDTO {
@IsString()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'reflect-metadata';
import { IsString, IsNumber, IsOptional, MinLength } from 'class-validator';
import { UserRole } from '@/domain/types/user.role';
import { IsString, IsNumber, IsOptional, MinLength } from '/opt/infra/index';
import { UserRole } from '/opt/infra/index';

export class UpdateUserDTO {
@IsString()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { APIGatewayProxyResult, APIGatewayEvent, Handler } from 'aws-lambda';
import { IDPathParameterMissing } from '@/domain/errors/IDPathParameterMissing';
import {
APIGatewayProxyResult,
APIGatewayEvent,
Handler,
formatErrorResponse,
formatJSONResponse
} from '@/domain/response/formatJSONResponse';
import { UserId } from '@/domain/entities/value-objects/user.id';
import { DomainError } from '@/domain/errors/DomainError';
import middify from '@/infrastructure/middlewares/middify';
import HttpStatus from '@/domain/types/HttpStatus';
import { UserRepository } from '@/infrastructure/database';
import { ALL_ROLES } from '@/domain/types/user.role';
formatJSONResponse,
middify,
DomainError,
IDPathParameterMissing,
UserRepository,
UserId,
HttpStatus,
ALL_ROLES
} from '/opt/infra/index';

const getUseById = async (
event: APIGatewayEvent & { body: any }
Expand Down
21 changes: 12 additions & 9 deletions src/functions/get-users.ts → lambdas/src/functions/get-users.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { APIGatewayProxyResult, APIGatewayEvent, Handler } from 'aws-lambda';
import {
APIGatewayProxyResult,
APIGatewayEvent,
Handler,
formatErrorResponse,
formatJSONResponse
} from '@/domain/response/formatJSONResponse';
import { DomainError } from '@/domain/errors/DomainError';
import middify from '@/infrastructure/middlewares/middify';
import HttpStatus from '@/domain/types/HttpStatus';
import { UserRepository } from '@/infrastructure/database';
import { ADMINISTRATORS } from '@/domain/types/user.role';
formatJSONResponse,
middify,
DomainError,
UserRepository,
User,
HttpStatus,
ADMINISTRATORS
} from '/opt/infra/index';

const getUsers = async (
event: APIGatewayEvent & { body: any }
Expand All @@ -24,7 +27,7 @@ const getUsers = async (
return formatJSONResponse(HttpStatus.OK, {
success: true,
...data,
users: data.users.map((user) => user.toPrimitives())
users: data.users.map((user:User) => user.toPrimitives())
});
} catch (error: DomainError | any) {
console.error(error);
Expand Down
19 changes: 10 additions & 9 deletions src/functions/login.ts → lambdas/src/functions/login.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { APIGatewayProxyResult, Handler } from 'aws-lambda';
import {
APIGatewayProxyResult,
RequestDTO,
Handler,
formatErrorResponse,
formatJSONResponse
} from '@/domain/response/formatJSONResponse';
import middify from '@/infrastructure/middlewares/middify';
import { RequestDTO } from '@/infrastructure/middlewares/RequestDTO';
formatJSONResponse,
middify,
DomainError,
DTOPropertiesError,
UserRepository,
HttpStatus
} from '/opt/infra/index';
import { LoginDTO } from '@/functions/dtos/login.dto';
import HttpStatus from '@/domain/types/HttpStatus';
import { DomainError } from '@/domain/errors/DomainError';
import { UserRepository } from '@/infrastructure/database';
import { DTOPropertiesError } from '@/domain/errors/DTOPropertiesError';

const loginUser = async (
event: RequestDTO<LoginDTO>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { APIGatewayProxyResult, Handler } from 'aws-lambda';
import { User } from '@/domain/entities/User';
import { IDPathParameterMissing } from '@/domain/errors/IDPathParameterMissing';
import {
APIGatewayProxyResult,
RequestDTO,
Handler,
formatErrorResponse,
formatJSONResponse
} from '@/domain/response/formatJSONResponse';
import { UserId } from '@/domain/entities/value-objects/user.id';
import middify from '@/infrastructure/middlewares/middify';
import { RequestDTO } from '@/infrastructure/middlewares/RequestDTO';
formatJSONResponse,
middify,
DomainError,
IDPathParameterMissing,
UserRepository,
User,
HttpStatus,
UserId,
BASIC
} from '/opt/infra/index';
import { UpdateUserDTO } from '@/functions/dtos/update-user.dto';
import HttpStatus from '@/domain/types/HttpStatus';
import { DomainError } from '@/domain/errors/DomainError';
import { UserRepository } from '@/infrastructure/database';
import { BASIC } from '@/domain/types/user.role';

const updateUser = async (
event: RequestDTO<UpdateUserDTO>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { SQSEvent, Handler } from 'aws-lambda';
import { DomainError } from '@/domain/errors/DomainError';
import { SQSEvent, Handler, DomainError } from '/opt/infra/index';

const notification = async (event: SQSEvent): Promise<void> => {
try {
Expand Down
Loading
Loading