48 lines
1.3 KiB
Markdown
48 lines
1.3 KiB
Markdown
# @mintel/next-utils
|
|
|
|
A collection of reusable utilities and helpers for Mintel Next.js projects, focusing on internationalization, environment safety, and security.
|
|
|
|
## ✨ Features
|
|
|
|
### 🌍 Internationalization (i18n)
|
|
Standardized helpers for `next-intl`:
|
|
- `createMintelMiddleware`: A logging-enabled middleware wrapper.
|
|
- `createMintelI18nRequestConfig`: Centralized request configuration for server-side translations.
|
|
|
|
### 🔐 Environment Validation
|
|
Zod-based validation to ensure your app never boots with missing secrets:
|
|
- `validateMintelEnv`: Validates standard Mintel variables (Mail, Sentry, Umami).
|
|
|
|
### 🛡 Rate Limiting
|
|
- `rateLimit`: A simple in-memory rate limiter for protecting server actions and form submissions.
|
|
|
|
## 🚀 Usage
|
|
|
|
### i18n Middleware (`src/middleware.ts`)
|
|
```typescript
|
|
import { createMintelMiddleware } from "@mintel/next-utils";
|
|
|
|
export default createMintelMiddleware({
|
|
locales: ["en", "de"],
|
|
defaultLocale: "en",
|
|
logRequests: true,
|
|
});
|
|
```
|
|
|
|
### Env Validation (`scripts/validate-env.ts`)
|
|
```typescript
|
|
import { validateMintelEnv } from "@mintel/next-utils";
|
|
|
|
validateMintelEnv();
|
|
```
|
|
|
|
### Rate Limiting
|
|
```typescript
|
|
import { rateLimit } from "@mintel/next-utils";
|
|
|
|
export async function myAction(data: any) {
|
|
await rateLimit(data.email);
|
|
// ... logic
|
|
}
|
|
```
|