From d36703b637f7d8c17cc3b2e62f79b355754e3aef Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Thu, 14 Sep 2023 05:35:41 +0100 Subject: [PATCH 1/4] chore: setup types --- accessible/dry.js | 2 +- jsconfig.json | 17 +++++++++++ types/index.d.ts | 72 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 jsconfig.json create mode 100644 types/index.d.ts diff --git a/accessible/dry.js b/accessible/dry.js index 900a91e..e35cf6c 100644 --- a/accessible/dry.js +++ b/accessible/dry.js @@ -35,6 +35,6 @@ const expandedPgInfoBySlug = reduceLibraryContents(LIBRARY_CONTENTS) /** * accessible/dry * - * @type {Dictionary} + * @type {Object} */ module.exports = expandedPgInfoBySlug diff --git a/jsconfig.json b/jsconfig.json new file mode 100644 index 0000000..d15c7ca --- /dev/null +++ b/jsconfig.json @@ -0,0 +1,17 @@ +{ + "include": ["lib/**/*", "types/index.d.ts"], + "compilerOptions": { + "types": ["node"], + "typeRoots": ["./types", "./node_modules/@types"], + "lib": ["es2016"], + // silences wrong TS error, we don't compile, we only typecheck + "outDir": "./irrelevant/unused", + "allowJs": true, + "checkJs": true, + "noImplicitThis": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noEmitOnError": true, + "noErrorTruncation": true + } +} diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..7284d31 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,72 @@ +interface Sails { + log: LogMethod & LogObject + helpers: Helper + on(event: string, listener: (...args: any[]) => void): void + off(event: string, listener: (...args: any[]) => void): void + emit(event: string, ...args: any[]): void + lift(cb?: (err: Error, sails: Sails) => void): Sails + lower(cb?: (err?: Error) => void): void + load(): Sails + config: Config + renderView: ( + relPathToView: string, + _options: Dictionary, + optionalCb?: (err: Error | null, compiledHtml: string) => void + ) => Sails & Promise + intercept(callback: (err: Error) => Error): Sails & Promise +} + +interface Helper { + mail: { + send: { + with: (params: EmailParams) => Promise + } + } +} +interface EmailParams { + mailer?: string + to: string + subject?: string + template?: string + templateData?: object +} + +interface Hook { + inertia: Inertia +} +interface LogMethod { + (...args: any[]): void +} + +interface LogObject { + info: LogMethod + warn: LogMethod + error: LogMethod + debug: LogMethod + silly: LogMethod + verbose: LogMethod +} + +interface Config { + mailer: string + mail: { + default: string + mailers: { + log: object + smtp: { + transport: 'smtp' + host: string + port: number + encryption: 'tls' | 'ssl' + username?: string + password?: string + } + } + from: { + name: string + address: string + } + } +} + +declare const sails: Sails From 4500d4418c8044af50f64bdf8135364ec9b46b5d Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Thu, 14 Sep 2023 06:05:52 +0100 Subject: [PATCH 2/4] feat: add cc and bcc for SMTP transport (#11) --- lib/private/mail/send.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/private/mail/send.js b/lib/private/mail/send.js index 33c32e1..ad99814 100644 --- a/lib/private/mail/send.js +++ b/lib/private/mail/send.js @@ -51,6 +51,18 @@ module.exports = { required: true, isEmail: true }, + cc: { + type: 'ref', + description: + 'Comma separated list or an array of recipients email addresses that will appear on the Cc: field', + defaultsTo: [] + }, + bcc: { + type: 'ref', + description: + 'Comma separated list or an array of recipients email addresses that will appear on the Bcc: field', + defaultsTo: [] + }, toName: { description: 'Name of the primary recipient as displayed in their inbox.', example: 'Nola Thacker' @@ -109,7 +121,9 @@ module.exports = { mailer, from: fromAddress, fromName, - text + text, + cc, + bcc }) { if (template && !template.startsWith('email-')) { sails.log.warn( @@ -202,7 +216,9 @@ module.exports = { to, subject, text, - html + html, + cc, + bcc }) sails.log.debug('Message sent: %s', smtpInfo.messageId) break From 8f81ce3bb6584bde5a0c75cef6ddc6904d468191 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Thu, 14 Sep 2023 07:02:59 +0100 Subject: [PATCH 3/4] feat: add attachments support for SMTP transport (#12) --- lib/private/mail/send.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/private/mail/send.js b/lib/private/mail/send.js index ad99814..07b2903 100644 --- a/lib/private/mail/send.js +++ b/lib/private/mail/send.js @@ -42,6 +42,11 @@ module.exports = { type: {}, defaultsTo: {} }, + attachments: { + type: 'ref', + description: 'An array of attachment objects', + defaultsTo: [] + }, to: { description: 'The email address of the primary recipient.', extendedDescription: @@ -123,7 +128,8 @@ module.exports = { fromName, text, cc, - bcc + bcc, + attachments }) { if (template && !template.startsWith('email-')) { sails.log.warn( @@ -218,7 +224,8 @@ module.exports = { text, html, cc, - bcc + bcc, + attachments }) sails.log.debug('Message sent: %s', smtpInfo.messageId) break From 636ff12e60a41c35ce896b9816ef21c9ee77ca2e Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Thu, 14 Sep 2023 07:05:33 +0100 Subject: [PATCH 4/4] chore: bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e539099..72442de 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sails-hook-mail", - "version": "0.0.6", + "version": "0.0.7", "description": "The simple elegant way to send emails from a Sails application", "main": "lib/sails-hook-mail.js", "scripts": {