chore: manually committing auth module to remoter
This commit is contained in:
16
packages/hoppscotch-backend/src/mailer/MailDescriptions.ts
Normal file
16
packages/hoppscotch-backend/src/mailer/MailDescriptions.ts
Normal 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;
|
||||
};
|
||||
};
|
||||
8
packages/hoppscotch-backend/src/mailer/mailer.module.ts
Normal file
8
packages/hoppscotch-backend/src/mailer/mailer.module.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { MailerService } from './mailer.service';
|
||||
|
||||
@Module({
|
||||
providers: [MailerService],
|
||||
exports: [MailerService],
|
||||
})
|
||||
export class MailerModule {}
|
||||
40
packages/hoppscotch-backend/src/mailer/mailer.service.ts
Normal file
40
packages/hoppscotch-backend/src/mailer/mailer.service.ts
Normal 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,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user