diff --git a/packages/mailer_old/.gitignore b/packages/mailer_old/.gitignore deleted file mode 100644 index 9fd356af..00000000 --- a/packages/mailer_old/.gitignore +++ /dev/null @@ -1,102 +0,0 @@ - -# Created by https://www.gitignore.io/api/node,visualstudiocode -# Edit at https://www.gitignore.io/?templates=node,visualstudiocode - -### Node ### -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules/ -jspm_packages/ -dist/ -output/ - -# TypeScript v1 declaration files -typings/ - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variables file -.env -.env.test - -# parcel-bundler cache (https://parceljs.org/) -.cache - -# next.js build output -.next - -# nuxt.js build output -.nuxt - -# vuepress build output -.vuepress/dist - -# Serverless directories -.serverless/ - -# FuseBox cache -.fusebox/ - -# DynamoDB Local files -.dynamodb/ - -### VisualStudioCode ### -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json - -### VisualStudioCode Patch ### -# Ignore all local history of files -.history - -# End of https://www.gitignore.io/api/node,visualstudiocode - -documentation/ \ No newline at end of file diff --git a/packages/mailer_old/.npmignore b/packages/mailer_old/.npmignore deleted file mode 100644 index 3c9fb518..00000000 --- a/packages/mailer_old/.npmignore +++ /dev/null @@ -1,18 +0,0 @@ -# source -lib -test -tests -index.ts -package-lock.json -yarn.lock -tslint.json -tsconfig.json -tsconfig*.json -.prettierrc -.eslintrc.js -.eslintignore - -.vscode/ - -*.js.map -**/*.js.map diff --git a/packages/mailer_old/.vscode/settings.json b/packages/mailer_old/.vscode/settings.json deleted file mode 100644 index ee274540..00000000 --- a/packages/mailer_old/.vscode/settings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "typescript.preferences.importModuleSpecifier": "relative", - "typescript.preferences.quoteStyle": "single", - "editor.formatOnSave": true, - "jest.jestCommandLine": "yarn test" -} diff --git a/packages/mailer_old/README.md b/packages/mailer_old/README.md deleted file mode 100644 index 1978ecf0..00000000 --- a/packages/mailer_old/README.md +++ /dev/null @@ -1,37 +0,0 @@ -# devon4ts_node - -[devonfw](https://www.devonfw.com/) is a platform which provides solutions to building business applications which combine best-in-class frameworks and libraries as well as industry proven practices and code conventions. devonfw is 100% Open Source (Apache License version 2.0) since the beginning of 2018. - -devon4ts_node is the NodeJS stack of devonfw. It allows you to build business applications (backends) using NodeJS technology in standardized way based on established best-practices. - -![License](https://img.shields.io/npm/l/@devon4ts_node/mailer) -![License](https://img.shields.io/npm/v/@devon4ts_node/mailer) -![License](https://img.shields.io/librariesio/release/npm/@devon4ts_node/mailer) -![License](https://img.shields.io/npm/dt/@devon4ts_node/mailer) - -## devon4ts_node mailer - -This package contains the devon4ts_node mailer module. This module allows you to send emails in your devon4ts_node application in a easy way. - -## Documentation - -You can find all documentation in our [wiki](https://github.com/devonfw/devon4ts_node/wiki). - -## Code of conduct - -Visit [code of conduct document](https://github.com/devonfw/.github/blob/master/CODE_OF_CONDUCT.md). - -## Contributing guide - -Visit [contributing guide document](https://github.com/devonfw/.github/blob/master/CONTRIBUTING.asciidoc). - -## Key Principles - -Visit [key principles document](https://github.com/devonfw/.github/blob/master/key-principles.asciidoc). - -## Samples - -- [Employee example](https://github.com/devonfw-sample/devon4ts_node-samples/tree/develop/employee): simple backend example for a employee management application. -- [Components example](https://github.com/devonfw-sample/devon4ts_node/tree/develop/components-example): simple backend example which will show you the execution order of the devon4ts_node components. -- [GraphQL example](https://github.com/devonfw-sample/devon4ts_node/tree/develop/graphql): simple GraphQL example with starter configuration. -- [My Thai Star](https://github.com/devonfw/my-thai-star/tree/develop/node): realistic example about the management of a restaurant. This example has also a frontend and it is compatible with other devonfw stacks. diff --git a/packages/mailer_old/lib/index.ts b/packages/mailer_old/lib/index.ts deleted file mode 100644 index 484b6b54..00000000 --- a/packages/mailer_old/lib/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from './mailer.constants'; -export * from './mailer.module'; -export * from './mailer.service'; -export * from './mailer.types'; diff --git a/packages/mailer_old/lib/mailer.constants.ts b/packages/mailer_old/lib/mailer.constants.ts deleted file mode 100644 index 49db80b4..00000000 --- a/packages/mailer_old/lib/mailer.constants.ts +++ /dev/null @@ -1,2 +0,0 @@ -export const MAILER_TRANSPORT_PROVIDER_NAME = 'NODEMAILER_TRANSPORT'; -export const MAILER_OPTIONS_PROVIDER_NAME = 'MailerModuleOptions'; diff --git a/packages/mailer_old/lib/mailer.module.ts b/packages/mailer_old/lib/mailer.module.ts deleted file mode 100644 index 67ac8fe0..00000000 --- a/packages/mailer_old/lib/mailer.module.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { DynamicModule, Module } from '@nestjs/common'; -import * as nodemailer from 'nodemailer'; -import { MAILER_OPTIONS_PROVIDER_NAME, MAILER_TRANSPORT_PROVIDER_NAME } from './mailer.constants'; -import { MailerService } from './mailer.service'; -import { MailerModuleAsyncOptions, MailerModuleOptions } from './mailer.types'; - -@Module({ - providers: [MailerService], - exports: [MailerService], -}) -export class MailerModule { - private static defaultOptions: MailerModuleOptions = { - hbsOptions: { - templatesDir: './templates/views', - }, - mailOptions: { streamTransport: true, newline: 'windows' }, - emailFrom: 'noreply@capgemini.com', - }; - - static register(options?: MailerModuleOptions): DynamicModule { - return { - module: MailerModule, - providers: [ - { - provide: MAILER_OPTIONS_PROVIDER_NAME, - useValue: options || this.defaultOptions, - }, - { - provide: MAILER_TRANSPORT_PROVIDER_NAME, - useFactory: (opts: MailerModuleOptions): any => { - return nodemailer.createTransport(opts.mailOptions); - }, - inject: [MAILER_OPTIONS_PROVIDER_NAME], - }, - ], - exports: [MAILER_TRANSPORT_PROVIDER_NAME], - }; - } - - static registerAsync(options: MailerModuleAsyncOptions): DynamicModule { - const transportProvider = { - provide: MAILER_TRANSPORT_PROVIDER_NAME, - useFactory: (mailerOptions: MailerModuleOptions): nodemailer.Transporter => { - const opts = mailerOptions || this.defaultOptions; - return nodemailer.createTransport(opts.mailOptions); - }, - inject: [MAILER_OPTIONS_PROVIDER_NAME], - }; - - const optionsProvider = { - provide: MAILER_OPTIONS_PROVIDER_NAME, - useFactory: options.useFactory, - inject: options.inject || [], - }; - - return { - module: MailerModule, - imports: options.imports, - providers: [transportProvider, optionsProvider], - exports: [transportProvider], - }; - } -} diff --git a/packages/mailer_old/lib/mailer.service.ts b/packages/mailer_old/lib/mailer.service.ts deleted file mode 100644 index c1c03219..00000000 --- a/packages/mailer_old/lib/mailer.service.ts +++ /dev/null @@ -1,168 +0,0 @@ -import { Inject, Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common'; -import { Transporter, SentMessageInfo, SendMailOptions } from 'nodemailer'; -import { MAILER_OPTIONS_PROVIDER_NAME, MAILER_TRANSPORT_PROVIDER_NAME } from './mailer.constants'; -import { MailerModuleOptions, IHandlebarsOptions } from './mailer.types'; -import * as fs from 'fs-extra'; -import { join } from 'path'; - -@Injectable() -export class MailerService implements OnModuleInit, OnModuleDestroy { - private hbsOptions: IHandlebarsOptions = { - templatesDir: join(__dirname, '../../../../templates/views'), - extension: '.handlebars', - }; - private hbs: any; - private readonly templates: { - [T: string]: Handlebars.TemplateDelegate; - } = {}; - - constructor( - @Inject(MAILER_TRANSPORT_PROVIDER_NAME) - readonly transporter: Transporter, - @Inject(MAILER_OPTIONS_PROVIDER_NAME) - private readonly options: MailerModuleOptions, - ) {} - - async onModuleInit(): Promise { - if (this.options.hbsOptions) { - const hbs = await import('handlebars'); - - this.hbs = hbs.create(); - - Object.assign(this.hbsOptions, this.options.hbsOptions); - - if (this.hbsOptions.extension![0] !== '.') { - this.hbsOptions.extension = '.' + this.hbsOptions.extension; - } - - this.addPartials(); - - this.addHelpers(); - - this.addTemplates(); - } - } - - onModuleDestroy(): void { - this.transporter.close(); - } - - async sendPlainMail(emailOptions: SendMailOptions): Promise; - async sendPlainMail(to: string, subject: string, mail: string): Promise; - async sendPlainMail( - firstParam: string | SendMailOptions, - secondParam?: string, - thirdParam?: string, - ): Promise { - const mailOptions: SendMailOptions = { - from: this.options.emailFrom, - }; - - if (typeof firstParam === 'string') { - Object.assign(mailOptions, { - from: this.options.emailFrom, - to: firstParam, - subject: secondParam, - html: thirdParam, - }); - } else { - Object.assign(mailOptions, firstParam); - } - - return await this.transporter.sendMail(mailOptions); - } - - async sendTemplateMail( - emailOptions: SendMailOptions, - templateName: string, - emailData: any, - hbsOptions?: RuntimeOptions, - ): Promise; - async sendTemplateMail( - to: string, - subject: string, - templateName: string, - emailData: any, - hbsOptions?: RuntimeOptions, - ): Promise; - sendTemplateMail( - firstParam: string | SendMailOptions, - secondParam?: string, - thirdParam?: string, - fourthParam?: any, - fifthParam?: RuntimeOptions, - ): Promise { - const mailOptions: SendMailOptions = { - from: this.options.emailFrom, - }; - - if (typeof firstParam === 'string') { - Object.assign(mailOptions, { - from: this.options.emailFrom, - to: firstParam, - subject: secondParam, - }); - } else { - Object.assign(mailOptions, firstParam); - } - - if (thirdParam && typeof firstParam === 'string') { - mailOptions.html = this.templates[thirdParam!](fourthParam, fifthParam); - } else { - mailOptions.html = this.templates[secondParam!](thirdParam, fourthParam); - } - - return this.transporter.sendMail(mailOptions); - } - - addTemplate(name: string, template: string, options?: CompileOptions): void { - this.templates[name] = this.hbs.compile(template, options); - } - - registerPartial(name: string, partial: Handlebars.Template): void { - this.hbs.registerPartial(name, partial); - } - - registerHelper(name: string, helper: Handlebars.HelperDelegate): void { - this.hbs.registerHelper(name, helper); - } - - private addHelpers(): void { - if (this.hbsOptions.helpers && this.hbsOptions.helpers.length) { - this.hbsOptions.helpers.forEach(helper => { - this.hbs.registerHelper(helper.name, helper.func); - }); - } - } - - private addTemplates(): void { - if (fs.existsSync(this.hbsOptions.templatesDir)) { - const templates = fs.readdirSync(this.hbsOptions!.templatesDir, { - withFileTypes: true, - }); - templates - .filter(value => value.name.endsWith(this.hbsOptions!.extension!) && value.isFile()) - .forEach(element => { - this.templates[element.name.substring(0, element.name.indexOf('.'))] = this.hbs.compile( - fs.readFileSync(join(this.hbsOptions.templatesDir, element.name)).toString(), - ); - }); - } - } - - private addPartials(): void { - if (this.hbsOptions.partialsDir && fs.existsSync(this.hbsOptions.partialsDir)) { - const partials = fs.readdirSync(this.hbsOptions!.partialsDir, { - withFileTypes: true, - }); - partials - .filter(value => value.name.endsWith(this.hbsOptions!.extension!) && value.isFile()) - .forEach(element => { - this.hbs.registerPartial( - element.name.substring(0, element.name.indexOf('.')), - fs.readFileSync(join(this.hbsOptions.partialsDir!, element.name)).toString(), - ); - }); - } - } -} diff --git a/packages/mailer_old/lib/mailer.types.ts b/packages/mailer_old/lib/mailer.types.ts deleted file mode 100644 index c904b2d3..00000000 --- a/packages/mailer_old/lib/mailer.types.ts +++ /dev/null @@ -1,76 +0,0 @@ -import * as nodemailer from 'nodemailer'; -import * as JSONTransport from 'nodemailer/lib/json-transport'; -import * as SendmailTransport from 'nodemailer/lib/sendmail-transport'; -import * as SESTransport from 'nodemailer/lib/ses-transport'; -import * as SMTPPool from 'nodemailer/lib/smtp-pool'; -import * as SMTPTransport from 'nodemailer/lib/smtp-transport'; -import * as StreamTransport from 'nodemailer/lib/stream-transport'; -import { ModuleMetadata } from '@nestjs/common/interfaces'; -import * as Handlebars from 'handlebars'; - -// Copied from Handlebars, they do not export it -export interface ICompileOptions { - data?: boolean; - compat?: boolean; - knownHelpers?: { - helperMissing?: boolean; - blockHelperMissing?: boolean; - each?: boolean; - if?: boolean; - unless?: boolean; - with?: boolean; - log?: boolean; - lookup?: boolean; - }; - knownHelpersOnly?: boolean; - noEscape?: boolean; - strict?: boolean; - assumeObjects?: boolean; - preventIndent?: boolean; - ignoreStandalone?: boolean; - explicitPartialContext?: boolean; -} - -// Copied from handlebars, they do not export it -export interface IPrecompileOptions extends ICompileOptions { - srcName?: string; - destName?: string; -} - -export type MailerModuleOptions = IMailerModuleOptions; - -interface IMailerModuleOptions { - hbsOptions?: IHandlebarsOptions; - mailOptions?: - | nodemailer.TransportOptions - | SESTransport.Options - | JSONTransport.Options - | StreamTransport.Options - | SendmailTransport.Options - | SMTPPool.Options - | SMTPTransport.Options - | string; - emailFrom: string; -} - -export interface IHandlebarsOptions { - templatesDir: string; - extension?: string; - partialsDir?: string; - helpers?: IHelperFunction[]; - compilerOptions?: ICompileOptions; -} - -export type HelperFunction = IHelperFunction; - -interface IHelperFunction { - name: string; - func: Handlebars.HelperDelegate; -} - -export type MailerModuleAsyncOptions = IMailerModuleAsyncOptions; - -interface IMailerModuleAsyncOptions extends Pick { - useFactory: (...args: any[]) => Promise | MailerModuleOptions; - inject?: any[]; -} diff --git a/packages/mailer_old/package.json b/packages/mailer_old/package.json deleted file mode 100644 index 5e2c53de..00000000 --- a/packages/mailer_old/package.json +++ /dev/null @@ -1,66 +0,0 @@ -{ - "name": "@devon4ts_node/mailer", - "version": "5.0.1", - "description": "devon4ts_node module that allows you to send emails in a easy way.", - "main": "dist/index.js", - "scripts": { - "build": "rm -rf dist && tsc -p tsconfig.build.json", - "prepublish:npm": "npm run build", - "publish:npm": "npm publish --access public", - "prepublish:next": "npm run build", - "publish:next": "npm publish --access public --tag next", - "test": "jest", - "format": "prettier --write \"lib/**/*.ts\"", - "lint": "eslint lib/**/*.ts --fix" - }, - "keywords": [ - "nestjs", - "devon4ts_node", - "devonfw" - ], - "author": { - "name": "Capgemini", - "url": "https://www.capgemini.com/" - }, - "contributors": [ - "Dario Rodriguez Gonzalez " - ], - "license": "Apache-2.0", - "dependencies": { - "fs-extra": "^10.1.0", - "nodemailer": "^6.7.5" - }, - "peerDependencies": { - "@nestjs/common": "^9.0.0", - "@nestjs/core": "^9.0.0", - "handlebars": "^4.0.0", - "reflect-metadata": "^0.1.13", - "rxjs": "^7.0.0" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/devonfw/devon4ts_node.git" - }, - "bugs": { - "url": "https://github.com/devonfw/devon4ts_node/issues" - }, - "homepage": "https://github.com/devonfw/devon4ts_node", - "jest": { - "moduleFileExtensions": [ - "js", - "json", - "ts" - ], - "roots": [ - "lib", - "test" - ], - "testRegex": ".spec.ts$", - "transform": { - "^.+\\.(t|j)s$": "ts-jest" - }, - "coverageDirectory": "./coverage", - "testEnvironment": "node" - }, - "gitHead": "1f351bcc0fbad70f9c25fa73a398a538ca0c8e55" -} \ No newline at end of file diff --git a/packages/mailer_old/test/mailer.service.spec.ts b/packages/mailer_old/test/mailer.service.spec.ts deleted file mode 100644 index f052a44b..00000000 --- a/packages/mailer_old/test/mailer.service.spec.ts +++ /dev/null @@ -1,159 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { Transporter } from 'nodemailer'; -import { join } from 'path'; -import { MAILER_OPTIONS_PROVIDER_NAME, MAILER_TRANSPORT_PROVIDER_NAME } from '../lib/mailer.constants'; -import { MailerService } from '../lib/mailer.service'; - -describe('MailerService', () => { - let service: MailerService; - let transporter: Pick; - - beforeEach(async () => { - transporter = { - sendMail: jest.fn(), - }; - const module: TestingModule = await Test.createTestingModule({ - providers: [ - MailerService, - { - provide: MAILER_TRANSPORT_PROVIDER_NAME, - useValue: transporter, - }, - { - provide: MAILER_OPTIONS_PROVIDER_NAME, - useValue: { - emailFrom: 'someone@whatever.com', - hbsOptions: { - templatesDir: join(__dirname, './templates/views'), - partialsDir: join(__dirname, './templates/partials'), - }, - mailOptions: {}, - }, - }, - ], - }).compile(); - - service = module.get(MailerService); - await service.onModuleInit(); - }); - - afterEach(() => { - jest.clearAllMocks(); - }); - - it('should be created and register all templates, partials and helpers', () => { - expect(service).toBeDefined(); - }); - - it('should send a plain text email using the provided transporter providing an emailOptions object', () => { - const input = { - to: 'to@to.com', - subject: 'subject', - text: 'text', - }; - - const expected = { ...input, from: 'someone@whatever.com' }; - - service.sendPlainMail(input); - expect(transporter.sendMail).toBeCalledWith(expected); - }); - - it('should send a plain text email using the provided transporter providing all params', () => { - const input = { - to: 'to@to.com', - subject: 'subject', - html: 'text', - }; - - const expected = { ...input, from: 'someone@whatever.com' }; - - service.sendPlainMail(input.to, input.subject, input.html); - expect(transporter.sendMail).toBeCalledWith(expected); - }); - - it('should send email from a handlebars template by using the provided transporter providing emailOptions object', () => { - const input = { - to: 'to@to.com', - subject: 'subject', - }; - - const expected = { - ...input, - from: 'someone@whatever.com', - html: ` - - - - - - my title - - - -

Hello

-

This is a test

- - - -`, - }; - - service.sendTemplateMail(input, 'test', { title: 'my title' }); - expect(transporter.sendMail).toBeCalledWith(expected); - }); - - it('should register a template and should be ready to use', () => { - const input = { - to: 'to@to.com', - subject: 'subject', - }; - - const expected = { - ...input, - from: 'someone@whatever.com', - html: `My view`, - }; - - service.addTemplate('my-view', `My view`); - service.sendTemplateMail(input, 'my-view', {}); - expect(transporter.sendMail).toBeCalledWith(expected); - }); - - it('should register a partial and should be ready to use', () => { - const input = { - to: 'to@to.com', - subject: 'subject', - }; - - const expected = { - ...input, - from: 'someone@whatever.com', - html: `this is my partial: My view`, - }; - - service.addTemplate('my-view', `{{#> my-partial }}My view{{/my-partial}}`); - service.registerPartial('my-partial', `this is my partial: {{> @partial-block }}`); - service.sendTemplateMail(input, 'my-view', {}); - expect(transporter.sendMail).toBeCalledWith(expected); - }); - - it('should register a helper and should be ready to use', () => { - const input = { - to: 'to@to.com', - subject: 'subject', - }; - - const expected = { - ...input, - from: 'someone@whatever.com', - html: `My view`, - }; - - service.registerHelper('bold', function (options) { - return '' + options.fn(this) + ''; - }); - service.addTemplate('my-view', `{{#bold}}My view{{/bold}}`); - service.sendTemplateMail(input, 'my-view', {}); - expect(transporter.sendMail).toBeCalledWith(expected); - }); -}); diff --git a/packages/mailer_old/test/templates/partials/layout.handlebars b/packages/mailer_old/test/templates/partials/layout.handlebars deleted file mode 100644 index ccdca815..00000000 --- a/packages/mailer_old/test/templates/partials/layout.handlebars +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - {{ title }} - - - - {{> @partial-block }} - - - diff --git a/packages/mailer_old/test/templates/views/test.handlebars b/packages/mailer_old/test/templates/views/test.handlebars deleted file mode 100644 index 4affa89b..00000000 --- a/packages/mailer_old/test/templates/views/test.handlebars +++ /dev/null @@ -1,4 +0,0 @@ -{{#> layout }} -

Hello

-

This is a test

-{{/layout}} diff --git a/packages/mailer_old/tsconfig.build.json b/packages/mailer_old/tsconfig.build.json deleted file mode 100644 index 2ff0226c..00000000 --- a/packages/mailer_old/tsconfig.build.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "compilerOptions": { - "noImplicitThis": true, - }, - "extends": "./tsconfig.json", - "exclude": [ - "node_modules", - "dist", - "./**/*.spec.ts", - "test" - ] -} diff --git a/packages/mailer_old/tsconfig.json b/packages/mailer_old/tsconfig.json deleted file mode 100644 index 4b938201..00000000 --- a/packages/mailer_old/tsconfig.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "noImplicitAny": false, - "sourceMap": false, - "outDir": "./dist", - "baseUrl": "./", - "incremental": false, - "noImplicitThis": false, - "types": [ - "node", - "jest" - ] - }, - "include": [ - "./lib/**/*", - "./test/**/*" - ] -}