npm package: @juliodevelop/services
Description: Integrações externas: Email (Resend/SendGrid/SMTP), WhatsApp, Cloudinary, MercadoPago, Upstash
Latest version: 0.1.0

# @juliodevelop/services

Integrações externas unificadas: Email, WhatsApp, Cloudinary, Mercado Pago e Upstash Redis.

Instale apenas os providers que usar — todas as deps são peer deps opcionais.

## Instalação

```bash
npm install @juliodevelop/services
# + instale o provider que for usar:
npm install resend            # para email com Resend
npm install @sendgrid/mail    # para email com SendGrid
npm install cloudinary        # para Cloudinary
npm install mercadopago       # para Mercado Pago
npm install @upstash/redis @upstash/ratelimit  # para Upstash
```

> Requer `.npmrc` configurado com o registry `@juliodevelop`. Veja o [README raiz](../README.md#setup-para-consumir-os-pacotes).

## Sub-exports

```
@juliodevelop/services/email       → createEmailService
@juliodevelop/services/whatsapp    → whatsapp (standalone, sem deps)
@juliodevelop/services/cloudinary  → createCloudinaryService
@juliodevelop/services/mercadopago → createMercadoPagoService
@juliodevelop/services/upstash     → createCacheService, createRateLimiter
```

## Uso

### Email

```typescript
import { createEmailService } from '@juliodevelop/services/email'

const email = createEmailService({
  provider: 'resend',
  apiKey: process.env.RESEND_API_KEY!,
  from: 'noreply@meuapp.com',
})

await email.send({
  to: 'user@email.com',
  subject: 'Bem-vindo!',
  html: '<h1>Olá!</h1>',
})
```

### WhatsApp (standalone)

```typescript
import { whatsapp } from '@juliodevelop/services/whatsapp'

const link = whatsapp.createLink({
  phone: '5592991234567',
  message: 'Olá! Tenho interesse no produto X',
})

const orderMsg = whatsapp.createOrderMessage({
  items: [{ name: 'Coxinha', qty: 5, price: 5.00 }],
  total: 25.00,
  customerName: 'João',
})
```

### Cloudinary

```typescript
import { createCloudinaryService } from '@juliodevelop/services/cloudinary'

const cloud = createCloudinaryService({
  cloudName: process.env.CLOUDINARY_CLOUD_NAME!,
  apiKey: process.env.CLOUDINARY_API_KEY!,
  apiSecret: process.env.CLOUDINARY_API_SECRET!,
})

const result = await cloud.upload(file, { folder: 'products' })
const url = cloud.getUrl('products/foto.jpg', { width: 400, format: 'webp' })
```

### Mercado Pago

```typescript
import { createMercadoPagoService } from '@juliodevelop/services/mercadopago'

const mp = createMercadoPagoService({
  accessToken: process.env.MERCADOPAGO_ACCESS_TOKEN!,
})

const checkout = await mp.createCheckout({
  items: [{ title: 'Inscrição', quantity: 1, unitPrice: 89.90 }],
  payer: { email: 'user@email.com' },
  backUrls: { success: 'https://meusite.com/sucesso' },
})
```

### Upstash (Cache + Rate Limit)

```typescript
import { createCacheService, createRateLimiter } from '@juliodevelop/services/upstash'

const cache = createCacheService({
  url: process.env.UPSTASH_REDIS_URL!,
  token: process.env.UPSTASH_REDIS_TOKEN!,
})

await cache.set('user:123', data, { ttl: 3600 })
const user = await cache.get<User>('user:123')

const limiter = createRateLimiter({
  url: process.env.UPSTASH_REDIS_URL!,
  token: process.env.UPSTASH_REDIS_TOKEN!,
  limiter: { requests: 10, window: '60s' },
})

const { success, remaining } = await limiter.check('user-ip')
```