Skip to content

Commit 7b2d3c2

Browse files
author
Frantz Kati
committed
feat(mail): pull in latest version of @adonis/mail into @tensei/mail package
- Add new Ethereal driver to @adonis/mail - Switch to pino logger - Add @tensei/mail tests to github actions - Add mongodb tests to github actions
1 parent 3c3e751 commit 7b2d3c2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+5626
-3021
lines changed

.github/workflows/tests.yml

+4
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,9 @@ jobs:
6060
env:
6161
DATABASE_TYPE: sqlite
6262
DATABASE_NAME: tensei
63+
- name: Run package tests on mongodb database
64+
run: cd /home/runner/work/tensei/tensei/packages/tests && yarn test
6365
- name: Run express-session-mikro-orm package tests
6466
run: cd /home/runner/work/tensei/tensei/packages/express-session-mikro-orm && yarn test
67+
- name: Run @tensei/mail package tests
68+
run: cd /home/runner/work/tensei/tensei/packages/mail && yarn test

packages/common/typings/config.d.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
declare module '@tensei/common/config' {
2-
import { Signale } from 'signale'
3-
import { Mail } from '@tensei/mail'
2+
import { Logger } from 'pino'
43
import { Request, Response } from 'express'
54
import { EntityManager } from '@mikro-orm/core'
65
import { sanitizer, validator } from 'indicative'
76
import { ResourceContract } from '@tensei/common/resources'
87
import { ExecutionParams } from 'subscriptions-transport-ws'
98
import { DashboardContract } from '@tensei/common/dashboards'
9+
import { MailConfig, MailManagerContract } from '@tensei/mail'
1010
import { IResolvers, ITypedef, PubSub } from 'apollo-server-express'
1111
import { IMiddleware, IMiddlewareGenerator } from 'graphql-middleware'
1212
import { DocumentNode, GraphQLSchema, GraphQLResolveInfo } from 'graphql'
@@ -39,6 +39,10 @@ declare module '@tensei/common/config' {
3939

4040
interface RouteExtendContract extends Record<string, any> {}
4141

42+
interface LoggerContract {
43+
trace: any
44+
}
45+
4246
interface RouteContract {
4347
config: RouteConfig & {
4448
extend: RouteExtendContract
@@ -288,7 +292,8 @@ declare module '@tensei/common/config' {
288292
name: string
289293
serverUrl: string
290294
clientUrl: string
291-
mailer: Mail
295+
viewsPath: string
296+
mailer: MailManagerContract
292297
storage: StorageManager
293298
rootBoot: PluginSetupFunction
294299
rootRegister: PluginSetupFunction
@@ -310,7 +315,7 @@ declare module '@tensei/common/config' {
310315
scripts: Asset[]
311316
styles: Asset[]
312317
orm: MikroORM | null
313-
logger: Signale
318+
logger: Logger
314319
databaseConfig: DatabaseConfiguration & AdditionalEntities
315320
dashboardPath: string
316321
resourcesMap: {

packages/core/Tensei.ts

+23-13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import Path from 'path'
2-
import { Signale } from 'signale'
2+
import pino from 'pino'
33
import BodyParser from 'body-parser'
44
import CookieParser from 'cookie-parser'
55
import { createServer, Server } from 'http'
66
import Express, { Application } from 'express'
77
import AsyncHandler from 'express-async-handler'
88
import { validator, sanitizer } from 'indicative'
9-
import { mail, SupportedDrivers } from '@tensei/mail'
9+
import { mail, MailConfig } from '@tensei/mail'
1010
import { responseEnhancer } from 'express-response-formatter'
1111
import { StorageManager, Storage } from '@slynova/flydrive'
1212

@@ -55,6 +55,15 @@ export class Tensei implements TenseiContract {
5555
}
5656
}
5757

58+
private mailerConfig: MailConfig = {
59+
mailers: {
60+
ethereal: {
61+
driver: 'ethereal'
62+
}
63+
},
64+
mailer: 'ethereal' as never,
65+
}
66+
5867
public ctx: Config = {
5968
schemas: [],
6069
routes: [],
@@ -64,9 +73,10 @@ export class Tensei implements TenseiContract {
6473
graphQlMiddleware: [],
6574
rootBoot: () => {},
6675
rootRegister: () => {},
76+
viewsPath: Path.resolve(process.cwd(), 'views'),
6777
storage: new StorageManager(this.defaultStorageConfig),
6878
storageConfig: this.defaultStorageConfig,
69-
mailer: mail().connection('ethereal'),
79+
mailer: mail(this.mailerConfig),
7080
databaseClient: null,
7181
serverUrl: '',
7282
clientUrl: '',
@@ -93,7 +103,9 @@ export class Tensei implements TenseiContract {
93103
path: Path.resolve(__dirname, 'public', 'app.css')
94104
}
95105
],
96-
logger: new Signale(),
106+
logger: pino({
107+
prettyPrint: process.env.NODE_ENV !== 'production'
108+
}),
97109
indicative: {
98110
validator,
99111
sanitizer
@@ -126,6 +138,12 @@ export class Tensei implements TenseiContract {
126138
return this
127139
}
128140

141+
public viewsPath(path: string) {
142+
this.ctx.viewsPath = path
143+
144+
return this
145+
}
146+
129147
public graphQlQueries(graphQlQueries: GraphQlQueryContract[]) {
130148
this.ctx.graphQlQueries = [
131149
...this.ctx.graphQlQueries,
@@ -248,7 +266,7 @@ export class Tensei implements TenseiContract {
248266
const port = process.env.PORT || 4500
249267

250268
this.server.listen(port, () => {
251-
this.ctx.logger.success(
269+
this.ctx.logger.info(
252270
`🚀 Access your server on ${this.ctx.serverUrl ||
253271
`http://127.0.0.1:${port}`}`
254272
)
@@ -538,14 +556,6 @@ export class Tensei implements TenseiContract {
538556
return this
539557
}
540558

541-
private mail(driverName: SupportedDrivers, mailConfig = {}) {
542-
this.ctx.mailer = mail()
543-
.connection(driverName)
544-
.config(mailConfig)
545-
546-
return this
547-
}
548-
549559
private storageDriver<
550560
StorageDriverImplementation extends Storage,
551561
DriverConfig extends unknown

packages/core/core.d.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import { Signale } from 'signale'
22
import { Mail } from '@tensei/mail'
3-
import { ResourceContract, User, Config, Asset } from '@tensei/common'
4-
5-
declare module '@tensei/common' {
6-
interface Config {
7-
logger: Signale
8-
}
9-
}
3+
import { ResourceContract, User, Asset } from '@tensei/common'
104

115
declare global {
126
namespace Express {

packages/core/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"@tensei/common": "^0.4.4",
3838
"@tensei/mail": "^0.4.4",
3939
"@types/cookie-parser": "^1.4.2",
40+
"@types/pino": "^6.3.4",
4041
"@types/signale": "^1.4.1",
4142
"body-parser": "^1.19.0",
4243
"change-case": "^4.1.1",
@@ -49,6 +50,7 @@
4950
"graphql-middleware": "^4.0.2",
5051
"indicative": "^7.4.4",
5152
"mustache": "^4.0.1",
53+
"pino": "^6.8.0",
5254
"pluralize": "^8.0.0",
5355
"signale": "^1.4.0"
5456
},

packages/core/typings/tensei.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ declare module '@tensei/core' {
2525
db(databaseConfig: DatabaseConfiguration): this
2626
serverUrl(url: string): this
2727
clientUrl(url: string): this
28+
viewsPath(path: string): this
2829
resources(resources: ResourceContract[]): this
2930
dashboards(dashboards: DashboardContract[]): this
3031
plugins(plugins: PluginContract[]): this
@@ -43,6 +44,7 @@ declare module '@tensei/core' {
4344
db(databaseConfig: DatabaseConfiguration): this
4445
serverUrl(url: string): this
4546
clientUrl(url: string): this
47+
viewsPath(path: string): this
4648
resources(resources: ResourceContract[]): this
4749
dashboards(dashboards: DashboardContract[]): this
4850
plugins(plugins: PluginContract[]): this

packages/mail/.gitignore

100755100644
+17-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1-
build/
1+
node_modules
2+
coverage
3+
.DS_STORE
4+
.nyc_output
5+
.idea
6+
.vscode/
7+
*.sublime-project
8+
*.sublime-workspace
9+
*.log
10+
build
11+
dist
12+
package-lock.json
13+
yarn.lock
14+
shrinkwrap.yaml
15+
.env
16+
!test/fixtures/.env
17+
emails/

packages/mail/.prettierignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
build
2+
README.md
3+
docs
4+
*.md
5+
*.html
6+
config.json
7+
.eslintrc.json
8+
package.json

packages/mail/.prettierrc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"trailingComma": "es5",
3+
"semi": false,
4+
"singleQuote": true,
5+
"useTabs": true,
6+
"quoteProps": "consistent",
7+
"bracketSpacing": true,
8+
"arrowParens": "always",
9+
"printWidth": 100
10+
}

packages/mail/CHANGELOG.md

-78
This file was deleted.

packages/mail/LICENSE.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# The MIT License
2+
3+
Copyright 2020 Harminder virk, contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

packages/mail/README.md

+18-23
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,29 @@
11
<div align="center">
2-
<br />
3-
<br />
4-
<img src="https://res.cloudinary.com/bahdcoder/image/upload/v1604236130/Asset_1_4x_fhcfyg.png" width="450px">
2+
<img src="https://res.cloudinary.com/adonisjs/image/upload/q_100/v1558612869/adonis-readme_zscycu.jpg" width="600px">
53
</div>
64

75
<br />
86

9-
<br />
10-
117
<div align="center">
12-
<h3>
13-
<strong>
14-
The fastest and easiest way to build powerful and secure APIs
15-
</strong>
16-
</h3>
17-
<p>Open source Node.js Headless CMS 🚀. </p>
8+
<h3>Mailer</h3>
9+
<p>AdonisJS mailer built on top of nodemailer. Uses driver based approach to support multiple email providers.</p>
1810
</div>
1911

2012
<br />
2113

2214
<div align="center">
2315

24-
25-
[![github-actions-image]][github-actions-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url]
16+
[![circleci-image]][circleci-url] [![typescript-image]][typescript-url] [![npm-image]][npm-url] [![license-image]][license-url] [![audit-report-image]][audit-report-url]
2617

2718
</div>
2819

2920
<div align="center">
3021
<h3>
31-
<a href="https://tenseijs.com">
22+
<a href="https://preview.adonisjs.com">
3223
Website
3324
</a>
3425
<span> | </span>
35-
<a href="https://tenseijs.com/docs">
26+
<a href="https://preview.adonisjs.com/guides/mail/introduction">
3627
Guides
3728
</a>
3829
<span> | </span>
@@ -43,16 +34,20 @@
4334
</div>
4435

4536
<div align="center">
46-
<sub>Built with ❤︎ by <a href="https://github.com/bahdcoder">Kati Frantz</a>
37+
<sub>Built with ❤︎ by <a href="https://twitter.com/AmanVirk1">Harminder Virk</a>
4738
</div>
4839

49-
[github-actions-image]: https://img.shields.io/github/workflow/status/tenseijs/tensei/Tests?style=for-the-badge
50-
[github-actions-url]: https://github.com/tenseijs/tensei/actions?query=workflow%3ATests "github-actions"
51-
52-
[npm-image]: https://img.shields.io/npm/v/@tensei/core.svg?style=for-the-badge&logo=npm
53-
[npm-url]: https://www.npmjs.com/package/@tensei/core "npm"
40+
[circleci-image]: https://img.shields.io/circleci/build/github/adonisjs/mail/master.svg?style=for-the-badge&logo=circleci
41+
[circleci-url]: https://circleci.com/gh/adonisjs/mail "circleci"
5442

5543
[typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
44+
[typescript-url]: "typescript"
45+
46+
[npm-image]: https://img.shields.io/npm/v/@adonisjs/mail/alpha.svg?style=for-the-badge&logo=npm
47+
[npm-url]: https://www.npmjs.com/package/@adonisjs/mail/v/alpha "npm"
48+
49+
[license-image]: https://img.shields.io/npm/l/@adonisjs/mail?color=blueviolet&style=for-the-badge
50+
[license-url]: LICENSE.md "license"
5651

57-
[license-url]: LICENSE.md
58-
[license-image]: https://img.shields.io/github/license/tenseijs/tensei?style=for-the-badge
52+
[audit-report-image]: https://img.shields.io/badge/-Audit%20Report-blueviolet?style=for-the-badge
53+
[audit-report-url]: https://htmlpreview.github.io/?https://github.com/adonisjs/mail/blob/develop/npm-audit.html "audit-report"

0 commit comments

Comments
 (0)