Skip to content

Commit

Permalink
Merge pull request #37 from loryblu/refactor/change-email-service
Browse files Browse the repository at this point in the history
refactor/change email service
  • Loading branch information
viniciuscosmome committed Nov 12, 2023
2 parents 6de2558 + e95374a commit 72b36a4
Show file tree
Hide file tree
Showing 7 changed files with 8,588 additions and 6,745 deletions.
12 changes: 7 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ PORT=5500
NODE_ENV=development

SALT_DATA_HASH=[string]
SALT_DATA_PASS=[string]
SALT_DATA_PASS=[number]

SECRET_JWT=[string]

MAIL_API_KEY=[string]
MAIL_PORT=[number]
MAIL_HOST=[string]
MAIL_USER=[string]
MAIL_PASS=[string]
MAIL_NAME=[string]
MAIL_FROM=[string]
MAIL_TEST_DELIVERED=[string]
MAIL_TEST_BOUNCED=[string]
MAIL_TEST_COMPLAINED=[string]
MAIL_WHITELIST=email_1,email_2,email_3

POSTGRES_USER=admin
POSTGRES_PASSWORD=admin
Expand Down
124 changes: 100 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<summary>Descrição em <b>pt-BR</b></summary>

### Requisitos

1. [Node.js 18.x LTS](https://nodejs.org/en) Instalado.
1. [PostgreSQL](https://www.postgresql.org/) ou [docker + docker-compose](https://docs.docker.com/compose/) instalado.
1. [Resend](https://resend.com/home) Serviço de e-mail usado na aplicação.

> ⚠ Se você tem o `docker` e `docker-compose` instalados, não precisa instalar o `PostgreSQL` (banco de dados), há um arquivo configurado para usar o PostgreSQL no docker, o `docker-compose.dev.yml`
Expand All @@ -25,63 +25,94 @@ git clone https://github.com/loryblu/loryblu-api.git loryblu-api
Este comando vai clonar o repositório para o destino definido. Você pode omitir o destino.

## Configurar ambiente

1. Duplique o arquivo `.env.example` do projeto principal;
1. Renomeie para `.env`;

Atualize o novo `.env` com as instruções a seguir:

```md
# Substitua os exemplos dentro dos colchetes "[Database username]" pelo valor final "root"

PORT=[Porta que o servidor expõe]

# ex: 8080

NODE_ENV=[Ambiente atual]

# ex: development

SALT_DATA_HASH=[Chave secreta para mesclar com o hash de dados sensíveis]

# ex: secret.salt.data

SALT_DATA_PASS=[Chave secreta para randomizar a senha]

# ex: 8

MAIL_API_KEY=[Chave do serviço Resend]
# ex: re_123456789
SECRET_JWT=[Senha para os tokens de acesso]

MAIL_FROM=[Email de contato da aplicação]
# ex: [email protected]
# ex: example123#

MAIL_PORT=[Porta de acesso do serviço de e-mail]

# ex: 1234

MAIL_HOST=[Domínio do serviço de e-mail]

# ex: smtp.email.com.br

MAIL_USER=[Nome do usuário de e-mail]

# ex: User123

MAIL_PASS=[Senha de acesso ao serviço de e-mail]

# ex: abcde123456

MAIL_NAME=[Nome da API]

# ex: LoryBlu

MAIL_TEST_DELIVERED=[Email para teste : sucesso]
# ex: [email protected]
MAIL_FROM=[E-mail de contato da aplicação]

MAIL_TEST_BOUNCED=[Email para teste : erro]
# ex: [email protected]
# ex: [email protected]

MAIL_WHITELIST=[Lista de e-mails para teste]

MAIL_TEST_COMPLAINED=[Email para teste : marcado como spam]
# ex: [email protected]
# ex: [email protected],[email protected],[email protected]

POSTGRES_USER=[Nome de usuário do banco de dados]

# ex: admin

POSTGRES_PASSWORD=[Senha do banco de dados]

# ex: strongPass

POSTGRES_DB=[Nome da base de dados]

# ex: loryblu-clone-api

POSTGRES_HOST=[Host do banco de dados]

# ex: localhost

POSTGRES_PORT=[Porta do banco de dados]

# ex: 5432

DATABASE_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}?schema=public"

# ! Este valor não precisa ser alterado, use-o como está.
```

## Instalação

### Submódulos

Depois de clonar este repositório, e se for adicionado ou atualizado um dos submódulos, execute o comando abaixo para atualizar e iniciar todos os submódulos.

```bash
$ git submodule update --init --recursive
```
Expand All @@ -100,11 +131,13 @@ $ yarn
<summary><b>Está usando docker?</b></summary>

Use o comando abaixo para baixar a imagem do PostgreSQL:14-alpine e configurar as credenciais.

```bash
docker-compose -f docker-compose.dev.yml up -d
```

Se preferir, há um script configurado para realizar este comando e todos os outros de desenvolvimento. Ele também inicia a aplicação:

```bash
yarn docker:dev
```
Expand All @@ -114,23 +147,27 @@ yarn docker:dev
---

Esse comando executa tudo o que é necessário para configurar o banco de dados de desenvolvimento.

```bash
$ yarn dev
```

Esse comando apenas inicia a aplicação no modo de desenvolvimento.

```bash
$ yarn start:dev
```

Esse comando inicia a aplicação no modo de produção.

```bash
$ yarn run start:prod
```

## Testes

Testes unitários

```bash
$ yarn test
```
Expand All @@ -141,19 +178,19 @@ LoryBlu tem [licença MIT](LICENSE).

</details>


Description in <b>en</b>

### Requirements

1. [Node.js 18.x LTS](https://nodejs.org/en) Installed.
1. [PostgreSQL](https://www.postgresql.org/) or [docker + docker-compose](https://docs.docker.com/compose/) installed.
1. [Resend](https://resend.com/home) Email service used in the application.

> ⚠ If you have `docker` and `docker-compose` intalled, you do not need to install `PostgreSQL` (database), there is a configured file to use PostgreSQL in docker, `docker-compose.dev.yml`
> ⚠ If you have `docker` and `docker-compose` intalled, you do not need to install `PostgreSQL` (database), there is a configured file to use PostgreSQL in docker, `docker-compose.dev.yml`
## Clone the repository

Unit tests

```bash
# git clone <repo-url> <dist>
git clone https://github.com/loryblu/loryblu-api.git loryblu-api
Expand All @@ -162,69 +199,102 @@ git clone https://github.com/loryblu/loryblu-api.git loryblu-api
This comamnd will clone the repository to the specified destination. You can omit the destination.

## Set up the enviroment

1. Duplicate the `.env.example` file from the main project;
1. Rename it to `.env`;

Update the new `.env` with the following instructions:

```md
# Replace the examples inside square brackets "[Database username]" with the final value "root"

PORT=[Port that the server exposes]

# e.g.: 8080

NODE_ENV=[Current environment]

# e.g.: development

SALT_DATA_HASH=[Secret key to merge with the sensitive data hash]

# e.g.: secret.salt.data

SALT_DATA_PASS=[Secret key to randomize the password]

# e.g.: 8

MAIL_API_KEY=[Resend service key]
# e.g.: re_123456789
SECRET_JWT=[Access token password]

# e.g.: example123#

MAIL_PORT=[Email service access port]

# ex: 1234

MAIL_HOST=[Email service domainl]

# ex: smtp.email.com.br

MAIL_USER=[Email user name]

# ex: User123

MAIL_PASS=[Email service access password]

# ex: abcde123456

MAIL_NAME=[API name]

# ex: LoryBlu

MAIL_FROM=[Application contact email]
# e.g.: [email protected]

MAIL_TEST_DELIVERED=[Test email : success]
# e.g.: [email protected]
# ex: [email protected]

MAIL_TEST_BOUNCED=[Test email : error]
# e.g.: [email protected]
MAIL_WHITELIST=[List of test emails]

MAIL_TEST_COMPLAINED=[Test email: marked as spam]
# e.g.: [email protected]
# ex: [email protected],[email protected],[email protected]

POSTGRES_USER=[Database username]

# e.g.: admin

POSTGRES_PASSWORD=[Database password]

# e.g.: strongPass

POSTGRES_DB=[Database name]

# e.g.: loryblu-clone-api

POSTGRES_HOST=[Database host]

# e.g.: localhost

POSTGRES_PORT=[Database port]

# e.g.: 5432

DATABASE_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}?schema=public"
# ! This value does not need to be changed, use it as is.

# ! This value does not need to be changed, use it as is.
```

## Installation

### Submodules

After cloning this repository, and if one of the submodules is added or updated, run the following command to update and initialize all submodules.

```bash
$ git submodule update --init --recursive
```

### Dependencies

After cloning and whenever you update the repository, run the following command to keep the dependencies up to date.

```bash
$ yarn
```
Expand All @@ -235,11 +305,13 @@ $ yarn
<summary><b>Are you using Docker?</b></summary>

Use the command below to download the PostgreSQL:14-alpine image and configure the credentials.

```bash
docker-compose -f docker-compose.dev.yml up -d
```

If you prefer, there is a script configured to perform this command and all other development commands. It also starts the application:

```bash
yarn docker:dev
```
Expand All @@ -249,23 +321,27 @@ yarn docker:dev
---

This command performs everything necessary to set up the development database.

```bash
$ yarn dev
```

This command only starts the application in development mode.

```bash
$ yarn start:dev
```

This command starts the application in production mode.

```bash
$ yarn run start:prod
```

## Tests

Unit tests

```bash
$ yarn test
```
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"prepare": "husky install"
},
"dependencies": {
"@nestjs-modules/mailer": "1.9.1",
"@nestjs/common": "10.0.0",
"@nestjs/config": "3.1.1",
"@nestjs/core": "10.0.0",
Expand All @@ -36,8 +37,8 @@
"class-validator": "0.14.0",
"email-templates": "file:src/modules/mail/templates/",
"helmet": "7.0.0",
"nodemailer": "6.9.7",
"reflect-metadata": "0.1.13",
"resend": "1.0.0",
"rxjs": "7.8.1"
},
"devDependencies": {
Expand All @@ -49,6 +50,7 @@
"@types/express": "4.17.17",
"@types/jest": "29.5.2",
"@types/node": "20.3.1",
"@types/nodemailer": "6.4.14",
"@types/supertest": "2.0.12",
"@typescript-eslint/eslint-plugin": "6.0.0",
"@typescript-eslint/parser": "6.0.0",
Expand Down
Loading

0 comments on commit 72b36a4

Please sign in to comment.