chore: manually committing auth module to remoter

This commit is contained in:
Balu Babu
2023-01-09 19:02:14 +05:30
parent 90bc0483ae
commit 0c154be04e
16 changed files with 468 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
export type MailDescription = {
template: 'team-invitation';
variables: {
invitee: string;
invite_team_name: string;
action_url: string;
};
};
export type UserMagicLinkMailDescription = {
template: 'code-your-own'; //Alias of template in Postmark, change this to env variable
variables: {
inviteeEmail: string;
magicLink: string;
};
};

View File

@@ -0,0 +1,8 @@
import { Module } from '@nestjs/common';
import { MailerService } from './mailer.service';
@Module({
providers: [MailerService],
exports: [MailerService],
})
export class MailerModule {}

View File

@@ -0,0 +1,40 @@
import { Injectable, OnModuleInit } from '@nestjs/common';
import { Email } from 'src/types/Email';
import {
MailDescription,
UserMagicLinkMailDescription,
} from './MailDescriptions';
import * as postmark from 'postmark';
import { throwErr } from 'src/utils';
import * as TE from 'fp-ts/TaskEither';
import { EMAIL_FAILED } from 'src/errors';
@Injectable()
export class MailerService implements OnModuleInit {
client: postmark.ServerClient;
onModuleInit() {
this.client = new postmark.ServerClient(
process.env.POSTMARK_SERVER_TOKEN ||
throwErr('No Postmark Server Token defined'),
);
}
sendMail(
to: string,
mailDesc: MailDescription | UserMagicLinkMailDescription,
) {
return TE.tryCatch(
() =>
this.client.sendEmailWithTemplate({
To: to,
From:
process.env.POSTMARK_SENDER_EMAIL ||
throwErr('No Postmark Sender Email defined'),
TemplateAlias: mailDesc.template,
TemplateModel: mailDesc.variables,
}),
() => EMAIL_FAILED,
);
}
}