nestjs-mailable
Version:
A comprehensive NestJS mail package with design patterns for email handling, templating, and multi-provider support
86 lines • 2.28 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Mailable = void 0;
class Mailable {
constructor() {
this.content = {};
}
view(template, context) {
this.content.template = template;
if (context) {
this.content.context = { ...this.content.context, ...context };
}
return this;
}
with(keyOrData, value) {
if (!this.content.context) {
this.content.context = {};
}
if (typeof keyOrData === 'string') {
this.content.context[keyOrData] = value;
}
else {
this.content.context = { ...this.content.context, ...keyOrData };
}
return this;
}
subject(subject) {
this.content.subject = subject;
return this;
}
from(address, name) {
this.content.from = { address, name };
return this;
}
replyTo(address, name) {
this.content.replyTo = { address, name };
return this;
}
attach(path, options) {
if (!this.content.attachments) {
this.content.attachments = [];
}
this.content.attachments.push({ path, ...options });
return this;
}
attachData(data, filename, options) {
if (!this.content.attachments) {
this.content.attachments = [];
}
this.content.attachments.push({ content: data, filename, ...options });
return this;
}
header(key, value) {
if (!this.content.headers) {
this.content.headers = {};
}
this.content.headers[key] = value;
return this;
}
tag(tag) {
if (!this.content.tags) {
this.content.tags = [];
}
this.content.tags.push(tag);
return this;
}
metadata(key, value) {
if (!this.content.metadata) {
this.content.metadata = {};
}
this.content.metadata[key] = value;
return this;
}
build() {
return this.content;
}
getContent() {
return this.build();
}
render() {
const built = this.build();
return { ...this.content, ...built };
}
}
exports.Mailable = Mailable;
//# sourceMappingURL=mailable.js.map