B2B-88: add starter kit structure and elements

This commit is contained in:
devmc-ee
2025-06-08 16:18:30 +03:00
parent 657a36a298
commit e7b25600cb
1280 changed files with 77893 additions and 5688 deletions

View File

@@ -0,0 +1,12 @@
import { MAILER_PROVIDER } from './provider-enum';
import { mailerRegistry } from './registry';
/**
* @name getMailer
* @description Get the mailer based on the environment variable using the registry internally.
*/
export function getMailer() {
return mailerRegistry.get(MAILER_PROVIDER);
}
export { MAILER_PROVIDER };

View File

@@ -0,0 +1,16 @@
import { z } from 'zod';
const MAILER_PROVIDERS = [
'nodemailer',
'resend',
// add more providers here
] as const;
const MAILER_PROVIDER = z
.enum(MAILER_PROVIDERS)
.default('nodemailer')
.parse(process.env.MAILER_PROVIDER);
export { MAILER_PROVIDER };
export type MailerProvider = (typeof MAILER_PROVIDERS)[number];

View File

@@ -0,0 +1,26 @@
import { Mailer } from '@kit/mailers-shared';
import { createRegistry } from '@kit/shared/registry';
import { MailerProvider } from './provider-enum';
const mailerRegistry = createRegistry<Mailer, MailerProvider>();
mailerRegistry.register('nodemailer', async () => {
if (process.env.NEXT_RUNTIME === 'nodejs') {
const { createNodemailerService } = await import('@kit/nodemailer');
return createNodemailerService();
} else {
throw new Error(
'Nodemailer is not available on the edge runtime. Please use another mailer.',
);
}
});
mailerRegistry.register('resend', async () => {
const { createResendMailer } = await import('@kit/resend');
return createResendMailer();
});
export { mailerRegistry };