2.0.1 • Published 9 months ago

@jagu.cz/email-layer v2.0.1

Weekly downloads
-
License
-
Repository
-
Last release
9 months ago

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-layer

Usage

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 install

Working 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 public

Once done, your users will only have to run:

npm install --save your-layer

Then add the dependency to their extends in nuxt.config:

defineNuxtConfig({
  extends: 'your-layer',
})

Development Server

Start the development server on http://localhost:3000

pnpm dev

Production

Build the application for production:

pnpm build

Or statically generate it with:

pnpm generate

Locally preview production build:

pnpm preview

Checkout the deployment documentation for more information.

2.0.1

9 months ago

2.0.0

10 months ago

1.0.4

10 months ago

1.0.3

11 months ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago