UNPKG

@softkit/mail

Version:

The Mailgun Mail Module is a comprehensive solution for integrating Mailgun's email functionality into NestJS applications. It provides a seamless way to send emails using Mailgun with minimal setup and configuration.

80 lines 3.33 kB
"use strict"; var SendgridMailModule_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.SendgridMailModule = void 0; const tslib_1 = require("tslib"); const common_1 = require("@nestjs/common"); const services_1 = require("../../services"); const constants_1 = require("../../constants"); let SendgridMailModule = SendgridMailModule_1 = class SendgridMailModule { static forRoot(sendgridConfig, global = true) { const mailProvider = { provide: constants_1.SENDGRID_CONFIG_TOKEN, useValue: sendgridConfig, }; const defaultProvidersAndExports = this.createDefaultProvidersAndExports(); if (defaultProvidersAndExports.providers) { defaultProvidersAndExports.providers.push(mailProvider); } return { global, ...defaultProvidersAndExports, }; } static forRootAsync(options, global = true) { const defaultProvidersAndExports = this.createDefaultProvidersAndExports(); const asyncConfigProvider = this.createAsyncProvider(options); const providers = [ asyncConfigProvider, ...(defaultProvidersAndExports.providers || []), ]; return { global, module: SendgridMailModule_1, imports: options.imports || [], providers, exports: [...(defaultProvidersAndExports.exports || [])], }; } static createDefaultProvidersAndExports() { return { module: SendgridMailModule_1, providers: [ { provide: services_1.AbstractMailService, useClass: services_1.SendgridService, }, { provide: constants_1.SENDGRID_CLIENT_TOKEN, useFactory: async (authCredentials) => { // eslint-disable-next-line unicorn/no-await-expression-member const MailService = await Promise.resolve().then(() => tslib_1.__importStar(require('@sendgrid/mail'))); // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore const mailService = new MailService.MailService(); const client = mailService['client']; mailService.setApiKey(authCredentials.apiKey); if (authCredentials.dataResidency) { client.setDataResidency(authCredentials.dataResidency); } return mailService; }, inject: [constants_1.SENDGRID_CONFIG_TOKEN], }, ], exports: [services_1.AbstractMailService, constants_1.SENDGRID_CLIENT_TOKEN], }; } }; exports.SendgridMailModule = SendgridMailModule; SendgridMailModule.createAsyncProvider = (options) => { return { provide: constants_1.SENDGRID_CONFIG_TOKEN, useFactory: options.useFactory, inject: options.inject, }; }; exports.SendgridMailModule = SendgridMailModule = SendgridMailModule_1 = tslib_1.__decorate([ (0, common_1.Module)({}) ], SendgridMailModule); //# sourceMappingURL=sendgrid.module.js.map