@jagu.cz/email-layer v2.0.1
Nuxt Email layer
To use this layer you have to allow access to private GitLab repositories.
Create new (or use existing) gitlab access token ACCESS_TOKEN with scope read_api. This token will be used globally by pnpm for all projects.
pnpm config set -- //gitlab.jagu.cz/:\_authToken=<ACCESS_TOKEN>Add this to .npmrc, to access private repositories with needed packages.
@jagu-nuxt:registry=https://gitlab.jagu.cz/api/v4/projects/379/packages/npm/
@jagus:registry=https://gitlab.jagu.cz/api/v4/projects/373/packages/npm/pnpm add @jagu-nuxt/email-layerUsage
Config
To use this layer add extends: ['@jagu-nuxt/email-layer'] to nuxt.config.ts.
To send emails you need to add Zimbra config to nuxt.config.ts:
zimbra: {
email: 'web@jagu.cz',
password: 'add to .env',
}If you need to add ratelimiting you need to add Upstash config to nuxt.config.ts:
upstash: {
url: 'add to .env',
token: 'add to .env',
prefix: 'choose prefix for your project',
}Functions
sendEmail(name: string, to: string, subject: string, template: string)
Sends email.
ratelimitSendEmail(event: H3Event, errorMessage?: string)
Ratelimits endpoint. Throws if limit was reached. Set to 5 requests per 60s per user.
Example
export default defineEventHandler(async (event) => {
await ratelimitSendEmail(event)
const { firstName, lastName, firmName, email, phone, message } = await readBody<Form>(event)
const template = await render(EmailTemplate, {
firstName,
lastName,
firmName,
email,
phone,
message,
})
if (process.env.NODE_ENV === 'development') return { ok: true }
return await sendEmail('Jagu', 'web@jagu.cz', 'Nový zájemce o služby', template)
})Setup
Make sure to install the dependencies:
pnpm installWorking on your layer
Your layer is at the root of this repository, it is exactly like a regular Nuxt project, except you can publish it on NPM.
The .playground directory should help you on trying your layer during development.
Running pnpm dev will prepare and boot .playground directory, which imports your layer itself.
Distributing your layer
Your Nuxt layer is shaped exactly the same as any other Nuxt project, except you can publish it on NPM.
To do so, you only have to check if files in package.json are valid, then run:
npm publish --access publicOnce done, your users will only have to run:
npm install --save your-layerThen add the dependency to their extends in nuxt.config:
defineNuxtConfig({
extends: 'your-layer',
})Development Server
Start the development server on http://localhost:3000
pnpm devProduction
Build the application for production:
pnpm buildOr statically generate it with:
pnpm generateLocally preview production build:
pnpm previewCheckout the deployment documentation for more information.