@miguelmorales13/nestkit 0.18.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +88 -40
- package/dist/auth/index.cjs +4 -4
- package/dist/auth/index.js +2 -2
- package/dist/auth/oauth/index.cjs +6 -6
- package/dist/auth/oauth/index.js +2 -2
- package/dist/bootstrap/index.cjs +4 -4
- package/dist/bootstrap/index.js +3 -3
- package/dist/{chunk-FNUZGYUF.cjs → chunk-FQRF37NG.cjs} +3 -3
- package/dist/{chunk-UNEVXCFW.js → chunk-PLEY5EZT.js} +3 -3
- package/dist/email/adapters/brevo.email.d.ts +22 -0
- package/dist/email/adapters/memory.email.d.ts +14 -0
- package/dist/email/adapters/message.d.ts +13 -0
- package/dist/email/adapters/resend.email.d.ts +28 -0
- package/dist/email/adapters/smtp.email.d.ts +22 -0
- package/dist/email/address.d.ts +15 -0
- package/dist/email/email.module.d.ts +37 -0
- package/dist/email/email.options.d.ts +39 -0
- package/dist/email/email.port.d.ts +62 -0
- package/dist/email/index.cjs +314 -0
- package/dist/email/index.d.ts +12 -0
- package/dist/email/index.js +314 -0
- package/dist/errors/index.cjs +6 -6
- package/dist/errors/index.js +6 -6
- package/dist/index.cjs +15 -15
- package/dist/index.js +16 -16
- package/dist/invoicing/adapters/facturama.invoicing.d.ts +1 -0
- package/dist/invoicing/index.cjs +7 -2
- package/dist/invoicing/index.js +7 -2
- package/dist/invoicing/invoicing.port.d.ts +10 -0
- package/package.json +6 -1
- package/dist/{chunk-A2DGK4ZL.js → chunk-2DUEQKOI.js} +3 -3
- package/dist/{chunk-4HHZFOVC.cjs → chunk-FH5UNWWW.cjs} +2 -2
- package/dist/{chunk-MSTXS3MU.cjs → chunk-LSDY6ETG.cjs} +3 -3
- package/dist/{chunk-IKXSVEJ7.js → chunk-TUNDBBQF.js} +3 -3
package/README.md
CHANGED
|
@@ -12,8 +12,8 @@ está listo, la implementación no.
|
|
|
12
12
|
**Las integraciones**, cada una en su subpath y sin arrastrar dependencias a quien no la use: acceso
|
|
13
13
|
con Google, Facebook o enlace mágico por correo (`auth/oauth`) o con email y contraseña (`auth`), Stripe, cobro presencial en
|
|
14
14
|
terminal Mercado Pago Point o Clip (`payments`), facturación CFDI 4.0 (`invoicing`), Telegram,
|
|
15
|
-
WhatsApp, Instagram y Facebook Pages (`meta`), subida de archivos (`storage`),
|
|
16
|
-
|
|
15
|
+
WhatsApp, Instagram y Facebook Pages (`meta`), subida de archivos (`storage`), correo transaccional con Resend,
|
|
16
|
+
Brevo o SMTP tras un puerto (`email`) y lectura de analítica (`umami`).
|
|
17
17
|
|
|
18
18
|
## ¿Para qué proyectos es esto?
|
|
19
19
|
|
|
@@ -1186,6 +1186,27 @@ misma URL o valida un borrador o emite un documento con efectos fiscales. `isTes
|
|
|
1186
1186
|
para que puedas negarte a arrancar en el ambiente equivocado. Del lado de Facturama, el default es el
|
|
1187
1187
|
sandbox a propósito: una configuración olvidada no puede timbrar de verdad.
|
|
1188
1188
|
|
|
1189
|
+
#### Reintentar un timbrado sin duplicarlo
|
|
1190
|
+
|
|
1191
|
+
`issue()` es la única operación de este módulo con un efecto irreversible caro de repetir por
|
|
1192
|
+
accidente: un timeout o una conexión caída *después* de que el PAC ya timbró no te dice si el
|
|
1193
|
+
documento existe. `idempotencyKey` en `InvoiceDraft` resuelve eso — **solo en Facturapi**, que lo
|
|
1194
|
+
soporta con `idempotency_key` en el body (y, además, como header, para que un wrapper de resiliencia
|
|
1195
|
+
genérico que solo sabe reconocer un header `*idempotency*` —sin parsear el body— sepa que este POST
|
|
1196
|
+
es seguro de reintentar). Facturama no tiene equivalente y el adaptador simplemente lo ignora.
|
|
1197
|
+
|
|
1198
|
+
La clave es de la **llamada**, no de la venta: generá una nueva en cada intento real de facturar
|
|
1199
|
+
(`crypto.randomUUID()` alcanza), y reusala solo entre los reintentos automáticos de esa misma
|
|
1200
|
+
llamada. Repetirla en un reintento **deliberado** — por ejemplo, volver a facturar tras cancelar — le
|
|
1201
|
+
devuelve el documento viejo (cancelado) en vez de timbrar uno nuevo.
|
|
1202
|
+
|
|
1203
|
+
```ts
|
|
1204
|
+
await facturacion.issue({
|
|
1205
|
+
/* … */
|
|
1206
|
+
idempotencyKey: crypto.randomUUID(),
|
|
1207
|
+
});
|
|
1208
|
+
```
|
|
1209
|
+
|
|
1189
1210
|
#### Lo que este módulo no hace
|
|
1190
1211
|
|
|
1191
1212
|
- **No genera ni sella XML.** Los PAC que solo timbran un CFDI que vos sellaste con tu propio CSD
|
|
@@ -1413,19 +1434,20 @@ por email, así que quien entró ayer con Google y hoy pide un enlace sigue sien
|
|
|
1413
1434
|
igual que Google↔Facebook. No se crea ninguna fila de cuenta (`OAuthAccount`): el email ya es la
|
|
1414
1435
|
identidad.
|
|
1415
1436
|
|
|
1416
|
-
Se enciende atando dos puertos más. nestkit no
|
|
1417
|
-
proyecto pone
|
|
1437
|
+
Se enciende atando dos puertos más. nestkit no decide el correo: `MagicLinkSenderPort` es donde el
|
|
1438
|
+
proyecto pone la plantilla y el idioma, normalmente sobre el `EmailPort` de [`email`](#email--correo-transaccional-con-el-proveedor-como-configuración).
|
|
1418
1439
|
|
|
1419
1440
|
```ts
|
|
1420
1441
|
import {
|
|
1421
1442
|
MAGIC_LINK_STORE, MAGIC_LINK_SENDER, type MagicLinkSenderPort, type MagicLinkDelivery,
|
|
1422
1443
|
} from '@miguelmorales13/nestkit/auth/oauth';
|
|
1444
|
+
import { EMAIL, type EmailPort } from '@miguelmorales13/nestkit/email';
|
|
1423
1445
|
|
|
1424
1446
|
@Injectable()
|
|
1425
1447
|
class MagicLinkMailer implements MagicLinkSenderPort {
|
|
1426
|
-
constructor(@Inject(
|
|
1427
|
-
async send({ email, url
|
|
1428
|
-
await this.
|
|
1448
|
+
constructor(@Inject(EMAIL) private readonly email: EmailPort) {} // Resend, Brevo o SMTP: da igual
|
|
1449
|
+
async send({ email, url }: MagicLinkDelivery) {
|
|
1450
|
+
await this.email.send({ to: email, subject: 'Tu enlace de acceso', html: `<a href="${url}">Entrar</a>` });
|
|
1429
1451
|
}
|
|
1430
1452
|
}
|
|
1431
1453
|
|
|
@@ -1472,62 +1494,87 @@ correo y obtiene el mismo `ok`. Lo que sí es del proyecto: **limitar la frecuen
|
|
|
1472
1494
|
manda tantos correos como se le pidan— y decidir si el store invalida los enlaces anteriores de la
|
|
1473
1495
|
misma dirección al crear uno nuevo.
|
|
1474
1496
|
|
|
1475
|
-
### `email
|
|
1497
|
+
### `email` — correo transaccional con el proveedor como configuración
|
|
1476
1498
|
|
|
1477
|
-
|
|
1478
|
-
|
|
1499
|
+
Un puerto, `EmailPort`, y el proveedor detrás se elige en una línea: **Resend**, **Brevo** (antes
|
|
1500
|
+
Sendinblue) o **cualquier servidor SMTP** vía Nodemailer. Mismo patrón que `storage`: nada en la
|
|
1501
|
+
app depende de un cliente concreto, así que cambiar de proveedor no toca ninguna llamada.
|
|
1479
1502
|
|
|
1480
1503
|
```ts
|
|
1481
|
-
import {
|
|
1482
|
-
import { ResendModule } from '@miguelmorales13/nestkit/email/resend';
|
|
1504
|
+
import { EmailModule } from '@miguelmorales13/nestkit/email';
|
|
1483
1505
|
|
|
1484
|
-
@Module({
|
|
1506
|
+
@Module({
|
|
1507
|
+
imports: [
|
|
1508
|
+
EmailModule.forRoot({ provider: 'brevo' }), // lee BREVO_API_KEY y EMAIL_FROM
|
|
1509
|
+
// EmailModule.forRoot({ provider: 'resend', from: 'Mi App <hola@miapp.mx>' }),
|
|
1510
|
+
// EmailModule.forRoot({ provider: 'smtp', smtp: { host, port: 587, user, password } }),
|
|
1511
|
+
// EmailModule.forRoot({ provider: 'memory' }), // pruebas y desarrollo: nadie recibe nada
|
|
1512
|
+
],
|
|
1513
|
+
})
|
|
1485
1514
|
export class AppModule {}
|
|
1486
1515
|
```
|
|
1487
1516
|
|
|
1488
1517
|
```ts
|
|
1489
|
-
import {
|
|
1490
|
-
import { RESEND_CLIENT } from '@miguelmorales13/nestkit/email/resend';
|
|
1491
|
-
import type { Resend } from 'resend';
|
|
1518
|
+
import { EMAIL, type EmailPort } from '@miguelmorales13/nestkit/email';
|
|
1492
1519
|
|
|
1493
1520
|
@Injectable()
|
|
1494
1521
|
export class NotificationsService {
|
|
1495
|
-
constructor(@Inject(
|
|
1496
|
-
|
|
1497
|
-
async
|
|
1498
|
-
await this.
|
|
1522
|
+
constructor(@Inject(EMAIL) private readonly email: EmailPort) {}
|
|
1523
|
+
|
|
1524
|
+
async welcome(to: string, name: string) {
|
|
1525
|
+
const { id } = await this.email.send({
|
|
1526
|
+
to: { email: to, name }, // o 'Ana <ana@example.com>'
|
|
1527
|
+
subject: 'Bienvenida',
|
|
1528
|
+
text: `Hola ${name}`,
|
|
1529
|
+
html: `<p>Hola ${name}</p>`,
|
|
1530
|
+
tags: { category: 'welcome' },
|
|
1531
|
+
attachments: [{ filename: 'guia.pdf', content: pdfBuffer, contentType: 'application/pdf' }],
|
|
1532
|
+
});
|
|
1499
1533
|
}
|
|
1500
1534
|
}
|
|
1501
1535
|
```
|
|
1502
1536
|
|
|
1503
|
-
|
|
1537
|
+
Lo que no pases en código sale del entorno: `EMAIL_PROVIDER`, `EMAIL_FROM`, `EMAIL_REPLY_TO`;
|
|
1538
|
+
`RESEND_API_KEY`; `SMTP_HOST`, `SMTP_PORT`, `SMTP_SECURE`, `SMTP_USER`, `SMTP_PASSWORD`;
|
|
1539
|
+
`BREVO_API_KEY`. **No hay proveedor por defecto**: sin `provider` ni `EMAIL_PROVIDER` el módulo
|
|
1540
|
+
falla al cablear, no en el primer envío. Lo mismo si el proveedor elegido no tiene credenciales.
|
|
1504
1541
|
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1542
|
+
El mensaje es el mismo para los tres —`from`, `to`/`cc`/`bcc`, `replyTo`, `subject`, `text`/`html`,
|
|
1543
|
+
`headers`, `tags`, `attachments`— y cada adaptador lo traduce a lo suyo: las direcciones con nombre
|
|
1544
|
+
van como `"Ana <ana@…>"` a Resend y SMTP y como `{ name, email }` a Brevo; los `tags` son pares
|
|
1545
|
+
nombre/valor en Resend, `nombre:valor` en Brevo y cabeceras `X-Tag-<nombre>` por SMTP. Un fallo del
|
|
1546
|
+
proveedor es una `EmailProviderException` (502, código `EMAIL_PROVIDER_ERROR`) con el estado y el
|
|
1547
|
+
cuerpo originales en `details` — también en Resend, cuyo SDK no lanza sino que devuelve `{ error }`.
|
|
1508
1548
|
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1549
|
+
**Brevo** va por su API REST v3 con `fetch`, sin SDK. Cosas a saber: los adjuntos viajan en base64
|
|
1550
|
+
dentro del JSON y la petición completa no puede pasar de 10 MB; y Brevo **rechaza extensiones fuera
|
|
1551
|
+
de su lista** (pdf, docx, xlsx, csv, png, jpg, zip… — un `.exe` o un `.json` no entra). Su relay
|
|
1552
|
+
SMTP (`smtp-relay.brevo.com:587`, login + clave SMTP) también funciona con `provider: 'smtp'`, por
|
|
1553
|
+
si se prefiere.
|
|
1512
1554
|
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
import type { Transporter } from 'nodemailer';
|
|
1555
|
+
Los SDKs de Resend y Nodemailer se cargan **perezosamente en el primer envío**: una app en Brevo no
|
|
1556
|
+
instala ninguno de los dos. `memory` guarda cada mensaje en `MemoryEmail.sent` — el buzón de salida
|
|
1557
|
+
de las pruebas.
|
|
1517
1558
|
|
|
1518
|
-
|
|
1519
|
-
export class NotificationsService {
|
|
1520
|
-
constructor(@Inject(NODEMAILER_TRANSPORT) private readonly mailer: Transporter) {}
|
|
1559
|
+
Es el sitio natural para el `MagicLinkSenderPort` de `auth/oauth`:
|
|
1521
1560
|
|
|
1522
|
-
|
|
1523
|
-
|
|
1561
|
+
```ts
|
|
1562
|
+
@Injectable()
|
|
1563
|
+
class MagicLinkMailer implements MagicLinkSenderPort {
|
|
1564
|
+
constructor(@Inject(EMAIL) private readonly email: EmailPort) {}
|
|
1565
|
+
send({ email, url }: MagicLinkDelivery) {
|
|
1566
|
+
return this.email.send({ to: email, subject: 'Tu enlace de acceso', html: `<a href="${url}">Entrar</a>` });
|
|
1524
1567
|
}
|
|
1525
1568
|
}
|
|
1526
1569
|
```
|
|
1527
1570
|
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1571
|
+
#### `email/resend` y `email/nodemailer` — los clientes crudos
|
|
1572
|
+
|
|
1573
|
+
Siguen existiendo para quien necesite algo que el puerto no expresa (plantillas de Resend, opciones
|
|
1574
|
+
de transporte de Nodemailer): `ResendModule` exporta `RESEND_CLIENT` (un `Resend`, requiere
|
|
1575
|
+
`RESEND_API_KEY`) y `NodemailerModule` exporta `NODEMAILER_TRANSPORT` (un `Transporter`, requiere
|
|
1576
|
+
`SMTP_HOST`, `SMTP_PORT`, `SMTP_USER`, `SMTP_PASSWORD`; `SMTP_SECURE` opcional). Usar el puerto
|
|
1577
|
+
por defecto y bajar al cliente solo cuando haga falta.
|
|
1531
1578
|
|
|
1532
1579
|
### `storage` — subida de archivos agnóstica del proveedor
|
|
1533
1580
|
|
|
@@ -1697,6 +1744,7 @@ trae los datos.
|
|
|
1697
1744
|
| `@miguelmorales13/nestkit/invoicing` | `InvoicingModule`, `INVOICING`, `InvoicingPort`, adaptadores `FacturapiInvoicing`/`FacturamaInvoicing` — CFDI 4.0 |
|
|
1698
1745
|
| `@miguelmorales13/nestkit/payments` | `PaymentsModule`, `TERMINAL_PAYMENTS`, `TerminalPaymentsPort`, adaptadores `MercadoPagoTerminalPayments`/`ClipTerminalPayments`, `createTerminalPaymentsWebhookController` |
|
|
1699
1746
|
| `@miguelmorales13/nestkit/storage` | `StorageModule`, `STORAGE`, `StoragePort`, adaptadores `LocalStorage`/`S3Storage`/`BunnyStorage` |
|
|
1747
|
+
| `@miguelmorales13/nestkit/email` | `EmailModule`, `EMAIL`, `EmailPort`, adaptadores `ResendEmail`/`SmtpEmail`/`BrevoEmail`/`MemoryEmail` |
|
|
1700
1748
|
| `@miguelmorales13/nestkit/email/resend` | `ResendModule`, `RESEND_CLIENT` |
|
|
1701
1749
|
| `@miguelmorales13/nestkit/email/nodemailer` | `NodemailerModule`, `NODEMAILER_TRANSPORT` |
|
|
1702
1750
|
| `@miguelmorales13/nestkit/i18n` | `I18nModule`, `t`, `translate`, `currentLanguage`, `I18nInterceptor`, `TranslatorPort`, `NestI18nTranslator`, `translateOr` |
|
|
@@ -1708,7 +1756,7 @@ Qué se añadió en cada versión y por qué está hecho así: [CAMBIOS.md](./CA
|
|
|
1708
1756
|
|
|
1709
1757
|
## Estado del paquete
|
|
1710
1758
|
|
|
1711
|
-
`0.
|
|
1759
|
+
`0.19.0`. Sin adaptador Mongo real. Con 251 pruebas propias (`bun test`): las de
|
|
1712
1760
|
`verifyState`, que existen porque las pruebas end-to-end de la app consumidora
|
|
1713
1761
|
**no podían ver ese fallo** — desactivada la verificación seguían pasando,
|
|
1714
1762
|
porque el callback pasaba a canjear el código y fallaba redirigiendo al mismo
|
package/dist/auth/index.cjs
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
require('../chunk-SDWHKPXI.cjs');
|
|
5
|
+
var _chunkFH5UNWWWcjs = require('../chunk-FH5UNWWW.cjs');
|
|
7
6
|
|
|
8
7
|
|
|
9
8
|
|
|
10
9
|
|
|
11
10
|
var _chunkHDFPSA2Vcjs = require('../chunk-HDFPSA2V.cjs');
|
|
12
11
|
require('../chunk-Q5Y33L7B.cjs');
|
|
12
|
+
require('../chunk-SDWHKPXI.cjs');
|
|
13
13
|
require('../chunk-PNK5WMPP.cjs');
|
|
14
14
|
|
|
15
15
|
|
|
@@ -108,7 +108,7 @@ _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
|
108
108
|
|
|
109
109
|
// src/auth/auth.service.ts
|
|
110
110
|
var BaseAuthService = class {
|
|
111
|
-
constructor(users, tokens = new (0,
|
|
111
|
+
constructor(users, tokens = new (0, _chunkFH5UNWWWcjs.TokenService)()) {
|
|
112
112
|
this.users = users;
|
|
113
113
|
this.tokens = tokens;
|
|
114
114
|
}
|
|
@@ -206,4 +206,4 @@ function createAuthController(serviceToken, options = {}) {
|
|
|
206
206
|
|
|
207
207
|
|
|
208
208
|
|
|
209
|
-
exports.BaseAuthService = BaseAuthService; exports.CurrentTenant = CurrentTenant; exports.CurrentUser =
|
|
209
|
+
exports.BaseAuthService = BaseAuthService; exports.CurrentTenant = CurrentTenant; exports.CurrentUser = _chunkFH5UNWWWcjs.CurrentUser; exports.JwtAuthGuard = _chunkFH5UNWWWcjs.JwtAuthGuard; exports.LoginDto = LoginDto; exports.ROLES_KEY = ROLES_KEY; exports.RefreshDto = RefreshDto; exports.RegisterDto = RegisterDto; exports.RequireTenantGuard = RequireTenantGuard; exports.Roles = Roles; exports.RolesGuard = RolesGuard; exports.TokenService = _chunkFH5UNWWWcjs.TokenService; exports.createAuthController = createAuthController; exports.hashPassword = hashPassword; exports.verifyPassword = verifyPassword;
|
package/dist/auth/index.js
CHANGED
|
@@ -2,14 +2,14 @@ import {
|
|
|
2
2
|
CurrentUser,
|
|
3
3
|
JwtAuthGuard,
|
|
4
4
|
TokenService
|
|
5
|
-
} from "../chunk-
|
|
6
|
-
import "../chunk-ETRUVZTJ.js";
|
|
5
|
+
} from "../chunk-TUNDBBQF.js";
|
|
7
6
|
import {
|
|
8
7
|
ConflictAppException,
|
|
9
8
|
ForbiddenAppException,
|
|
10
9
|
UnauthorizedAppException
|
|
11
10
|
} from "../chunk-ZFIDAX7K.js";
|
|
12
11
|
import "../chunk-M3GQDRWR.js";
|
|
12
|
+
import "../chunk-ETRUVZTJ.js";
|
|
13
13
|
import "../chunk-VVMRZEIW.js";
|
|
14
14
|
import {
|
|
15
15
|
__decorateClass,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
5
|
-
require('../../chunk-SDWHKPXI.cjs');
|
|
4
|
+
var _chunkFH5UNWWWcjs = require('../../chunk-FH5UNWWW.cjs');
|
|
6
5
|
|
|
7
6
|
|
|
8
7
|
|
|
9
8
|
var _chunkHDFPSA2Vcjs = require('../../chunk-HDFPSA2V.cjs');
|
|
10
9
|
require('../../chunk-Q5Y33L7B.cjs');
|
|
10
|
+
require('../../chunk-SDWHKPXI.cjs');
|
|
11
11
|
require('../../chunk-PNK5WMPP.cjs');
|
|
12
12
|
|
|
13
13
|
|
|
@@ -630,7 +630,7 @@ OAuthCallbackFilter = exports.OAuthCallbackFilter = _chunk2REOCMUDcjs.__decorate
|
|
|
630
630
|
|
|
631
631
|
|
|
632
632
|
function createOAuthController(options = {}) {
|
|
633
|
-
const Guard = _nullishCoalesce(options.guard, () => (
|
|
633
|
+
const Guard = _nullishCoalesce(options.guard, () => ( _chunkFH5UNWWWcjs.JwtAuthGuard));
|
|
634
634
|
const userId = _nullishCoalesce(options.userId, () => ( ((user) => user.sub)));
|
|
635
635
|
let OAuthControllerHost = class {
|
|
636
636
|
// Explicit token: the build emits no `design:paramtypes`, so a subclass
|
|
@@ -743,17 +743,17 @@ function createOAuthController(options = {}) {
|
|
|
743
743
|
_chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
744
744
|
_common.UseGuards.call(void 0, Guard),
|
|
745
745
|
_common.Get.call(void 0, "me"),
|
|
746
|
-
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 0,
|
|
746
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _chunkFH5UNWWWcjs.CurrentUser.call(void 0, ))
|
|
747
747
|
], OAuthControllerHost.prototype, "me", 1);
|
|
748
748
|
_chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
749
749
|
_common.UseGuards.call(void 0, Guard),
|
|
750
750
|
_common.Get.call(void 0, "linked-accounts"),
|
|
751
|
-
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 0,
|
|
751
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _chunkFH5UNWWWcjs.CurrentUser.call(void 0, ))
|
|
752
752
|
], OAuthControllerHost.prototype, "linkedAccounts", 1);
|
|
753
753
|
_chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
754
754
|
_common.UseGuards.call(void 0, Guard),
|
|
755
755
|
_common.Post.call(void 0, "link-intent"),
|
|
756
|
-
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 0,
|
|
756
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _chunkFH5UNWWWcjs.CurrentUser.call(void 0, )),
|
|
757
757
|
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 1, _common.Res.call(void 0, { passthrough: true }))
|
|
758
758
|
], OAuthControllerHost.prototype, "linkIntent", 1);
|
|
759
759
|
_chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
package/dist/auth/oauth/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CurrentUser,
|
|
3
3
|
JwtAuthGuard
|
|
4
|
-
} from "../../chunk-
|
|
5
|
-
import "../../chunk-ETRUVZTJ.js";
|
|
4
|
+
} from "../../chunk-TUNDBBQF.js";
|
|
6
5
|
import {
|
|
7
6
|
UnauthorizedAppException,
|
|
8
7
|
ValidationAppException
|
|
9
8
|
} from "../../chunk-ZFIDAX7K.js";
|
|
10
9
|
import "../../chunk-M3GQDRWR.js";
|
|
10
|
+
import "../../chunk-ETRUVZTJ.js";
|
|
11
11
|
import "../../chunk-VVMRZEIW.js";
|
|
12
12
|
import {
|
|
13
13
|
__decorateClass,
|
package/dist/bootstrap/index.cjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkFQRF37NGcjs = require('../chunk-FQRF37NG.cjs');
|
|
4
|
+
require('../chunk-LSDY6ETG.cjs');
|
|
4
5
|
require('../chunk-3AUOOEQO.cjs');
|
|
5
|
-
require('../chunk-
|
|
6
|
+
require('../chunk-Q5Y33L7B.cjs');
|
|
6
7
|
require('../chunk-AXMW5JF7.cjs');
|
|
7
8
|
require('../chunk-Y72D5L6I.cjs');
|
|
8
9
|
require('../chunk-SDWHKPXI.cjs');
|
|
9
|
-
require('../chunk-Q5Y33L7B.cjs');
|
|
10
10
|
require('../chunk-PNK5WMPP.cjs');
|
|
11
11
|
require('../chunk-2REOCMUD.cjs');
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
exports.applyNestKitDefaults =
|
|
14
|
+
exports.applyNestKitDefaults = _chunkFQRF37NGcjs.applyNestKitDefaults;
|
package/dist/bootstrap/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
applyNestKitDefaults
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-PLEY5EZT.js";
|
|
4
|
+
import "../chunk-2DUEQKOI.js";
|
|
4
5
|
import "../chunk-DYHSOULW.js";
|
|
5
|
-
import "../chunk-
|
|
6
|
+
import "../chunk-M3GQDRWR.js";
|
|
6
7
|
import "../chunk-X4PQJZ4G.js";
|
|
7
8
|
import "../chunk-TCAMLNUZ.js";
|
|
8
9
|
import "../chunk-ETRUVZTJ.js";
|
|
9
|
-
import "../chunk-M3GQDRWR.js";
|
|
10
10
|
import "../chunk-VVMRZEIW.js";
|
|
11
11
|
import "../chunk-4MGIQFAJ.js";
|
|
12
12
|
export {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkLSDY6ETGcjs = require('./chunk-LSDY6ETG.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunk3AUOOEQOcjs = require('./chunk-3AUOOEQO.cjs');
|
|
7
7
|
|
|
8
8
|
// src/bootstrap/apply-defaults.ts
|
|
9
9
|
|
|
@@ -17,7 +17,7 @@ function applyNestKitDefaults(app, options = {}) {
|
|
|
17
17
|
app.useGlobalPipes(
|
|
18
18
|
new (0, _common.ValidationPipe)({ whitelist: true, transform: true, ...options.validation })
|
|
19
19
|
);
|
|
20
|
-
app.useGlobalFilters(new (0,
|
|
20
|
+
app.useGlobalFilters(new (0, _chunkLSDY6ETGcjs.GlobalExceptionFilter)());
|
|
21
21
|
app.useGlobalInterceptors(new (0, _chunk3AUOOEQOcjs.ResponseInterceptor)());
|
|
22
22
|
if (options.swagger !== false) {
|
|
23
23
|
const swaggerOptions = _nullishCoalesce(options.swagger, () => ( { title: "API" }));
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { BrevoEmailOptions } from '../email.options.js';
|
|
2
|
+
import { type EmailMessage, type EmailPort, type SentEmail } from '../email.port.js';
|
|
3
|
+
/**
|
|
4
|
+
* Brevo (formerly Sendinblue) over its v3 REST API — one `POST /smtp/email`
|
|
5
|
+
* with the key in an `api-key` header. No SDK: the call is a dozen lines of
|
|
6
|
+
* `fetch`, and every field it sends is visible here, which is the same
|
|
7
|
+
* reasoning as `payments` and `auth/oauth`.
|
|
8
|
+
*
|
|
9
|
+
* Attachments travel base64-encoded inside the JSON; Brevo caps the whole
|
|
10
|
+
* request at 10 MB, so anything bigger belongs in `storage` with a link.
|
|
11
|
+
*/
|
|
12
|
+
export declare class BrevoEmail implements EmailPort {
|
|
13
|
+
private readonly options;
|
|
14
|
+
private readonly defaults;
|
|
15
|
+
private readonly baseUrl;
|
|
16
|
+
private readonly fetchImpl;
|
|
17
|
+
constructor(options: BrevoEmailOptions, defaults?: {
|
|
18
|
+
from?: string;
|
|
19
|
+
replyTo?: string;
|
|
20
|
+
});
|
|
21
|
+
send(input: EmailMessage): Promise<SentEmail>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { EmailMessage, EmailPort, SentEmail } from '../email.port.js';
|
|
2
|
+
/**
|
|
3
|
+
* Keeps every message in memory instead of sending it. For tests, and for a
|
|
4
|
+
* development environment that must not email anyone. `sent` is the outbox.
|
|
5
|
+
*/
|
|
6
|
+
export declare class MemoryEmail implements EmailPort {
|
|
7
|
+
private readonly defaults;
|
|
8
|
+
readonly sent: EmailMessage[];
|
|
9
|
+
constructor(defaults?: {
|
|
10
|
+
from?: string;
|
|
11
|
+
replyTo?: string;
|
|
12
|
+
});
|
|
13
|
+
send(message: EmailMessage): Promise<SentEmail>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { EmailAddress, EmailMessage } from '../email.port.js';
|
|
2
|
+
/**
|
|
3
|
+
* Fills the defaults in and refuses what no provider would accept, so each
|
|
4
|
+
* adapter can assume a complete message and the error reads the same
|
|
5
|
+
* whichever one is configured.
|
|
6
|
+
*/
|
|
7
|
+
export declare function completeMessage(message: EmailMessage, defaults: {
|
|
8
|
+
from?: string;
|
|
9
|
+
replyTo?: string;
|
|
10
|
+
}): EmailMessage & {
|
|
11
|
+
from: EmailAddress;
|
|
12
|
+
};
|
|
13
|
+
export declare function attachmentBuffer(content: Buffer | string): Buffer;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Resend } from 'resend';
|
|
2
|
+
import type { ResendEmailOptions } from '../email.options.js';
|
|
3
|
+
import { type EmailMessage, type EmailPort, type SentEmail } from '../email.port.js';
|
|
4
|
+
/** The one method of the SDK this adapter uses — what a test hands in instead of the real thing. */
|
|
5
|
+
export type ResendLike = {
|
|
6
|
+
emails: {
|
|
7
|
+
send: Resend['emails']['send'];
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Resend through its SDK, loaded lazily on the first send so an app on Brevo
|
|
12
|
+
* or SMTP never loads it — the same rule as `storage`'s S3 adapter.
|
|
13
|
+
*
|
|
14
|
+
* The SDK does not throw: it answers `{ data, error }`. The adapter turns the
|
|
15
|
+
* error half into {@link EmailProviderException} so a failed send is an
|
|
16
|
+
* exception here like everywhere else, and never a silently ignored result.
|
|
17
|
+
*/
|
|
18
|
+
export declare class ResendEmail implements EmailPort {
|
|
19
|
+
private readonly options;
|
|
20
|
+
private readonly defaults;
|
|
21
|
+
private clientPromise?;
|
|
22
|
+
constructor(options: ResendEmailOptions, defaults?: {
|
|
23
|
+
from?: string;
|
|
24
|
+
replyTo?: string;
|
|
25
|
+
}, client?: ResendLike);
|
|
26
|
+
private client;
|
|
27
|
+
send(input: EmailMessage): Promise<SentEmail>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Transporter } from 'nodemailer';
|
|
2
|
+
import type { SmtpEmailOptions } from '../email.options.js';
|
|
3
|
+
import { type EmailMessage, type EmailPort, type SentEmail } from '../email.port.js';
|
|
4
|
+
/** The one method this adapter needs from a transport. */
|
|
5
|
+
export type TransporterLike = Pick<Transporter, 'sendMail'>;
|
|
6
|
+
/**
|
|
7
|
+
* Any SMTP server through Nodemailer, loaded lazily on the first send.
|
|
8
|
+
*
|
|
9
|
+
* Tags have no place in SMTP; they go out as `X-Tag-<name>` headers, which
|
|
10
|
+
* most providers' relays surface in their dashboards and nobody else minds.
|
|
11
|
+
*/
|
|
12
|
+
export declare class SmtpEmail implements EmailPort {
|
|
13
|
+
private readonly options;
|
|
14
|
+
private readonly defaults;
|
|
15
|
+
private transportPromise?;
|
|
16
|
+
constructor(options: SmtpEmailOptions, defaults?: {
|
|
17
|
+
from?: string;
|
|
18
|
+
replyTo?: string;
|
|
19
|
+
}, transport?: TransporterLike);
|
|
20
|
+
private transport;
|
|
21
|
+
send(input: EmailMessage): Promise<SentEmail>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { EmailAddress } from './email.port.js';
|
|
2
|
+
export interface ParsedAddress {
|
|
3
|
+
email: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Normalises the two spellings the port accepts into one shape. Providers
|
|
8
|
+
* disagree — Resend and Nodemailer take `"Name <email>"`, Brevo wants
|
|
9
|
+
* `{ name, email }` — so every adapter goes through here and the caller
|
|
10
|
+
* never has to know which one is behind the port.
|
|
11
|
+
*/
|
|
12
|
+
export declare function parseAddress(address: EmailAddress): ParsedAddress;
|
|
13
|
+
/** `Name <email>` when there is a name, the bare address otherwise. */
|
|
14
|
+
export declare function formatAddress(address: EmailAddress): string;
|
|
15
|
+
export declare function toList(value: EmailAddress | EmailAddress[] | undefined): EmailAddress[];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { type EmailOptions } from './email.options.js';
|
|
3
|
+
import { type EmailPort } from './email.port.js';
|
|
4
|
+
/**
|
|
5
|
+
* Merges explicit options with the environment; anything not passed in code
|
|
6
|
+
* falls back to the env, so `EmailModule.forRoot()` with no arguments works
|
|
7
|
+
* when the environment is configured.
|
|
8
|
+
*
|
|
9
|
+
* Recognised vars: `EMAIL_PROVIDER`, `EMAIL_FROM`, `EMAIL_REPLY_TO`; resend
|
|
10
|
+
* `RESEND_API_KEY`; smtp `SMTP_HOST`, `SMTP_PORT`, `SMTP_SECURE`, `SMTP_USER`,
|
|
11
|
+
* `SMTP_PASSWORD`; brevo `BREVO_API_KEY`, `BREVO_BASE_URL`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function resolveEmailOptions(options?: EmailOptions): EmailOptions;
|
|
14
|
+
/** Constructs the adapter the options select, failing loudly on missing config. */
|
|
15
|
+
export declare function createEmailAdapter(options?: EmailOptions): EmailPort;
|
|
16
|
+
/**
|
|
17
|
+
* Provider-agnostic transactional email. Register once in the root module
|
|
18
|
+
* and inject the port anywhere with `@Inject(EMAIL) email: EmailPort`.
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* EmailModule.forRoot({ provider: 'brevo' }) // reads BREVO_API_KEY, EMAIL_FROM
|
|
22
|
+
* EmailModule.forRoot({ provider: 'resend', from: 'Mi App <hola@miapp.mx>' })
|
|
23
|
+
* EmailModule.forRoot({ provider: 'smtp', smtp: { host, port: 587, user, password } })
|
|
24
|
+
* EmailModule.forRootAsync({ inject: [Config], useFactory: (c) => ({ provider: c.emailProvider }) })
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* Switching providers is this one line — no call site changes, because
|
|
28
|
+
* everything depends on `EmailPort`, never on a concrete client.
|
|
29
|
+
*/
|
|
30
|
+
export declare class EmailModule {
|
|
31
|
+
static forRoot(options?: EmailOptions): DynamicModule;
|
|
32
|
+
static forRootAsync(config: {
|
|
33
|
+
imports?: any[];
|
|
34
|
+
inject?: any[];
|
|
35
|
+
useFactory: (...args: any[]) => EmailOptions | Promise<EmailOptions>;
|
|
36
|
+
}): DynamicModule;
|
|
37
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** DI token carrying the resolved {@link EmailOptions}. */
|
|
2
|
+
export declare const EMAIL_OPTIONS: unique symbol;
|
|
3
|
+
/** Which adapter backs the {@link EmailPort}. */
|
|
4
|
+
export type EmailProvider = 'resend' | 'smtp' | 'brevo' | 'memory';
|
|
5
|
+
export interface ResendEmailOptions {
|
|
6
|
+
apiKey: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Any SMTP server, through Nodemailer. Brevo's own relay works here too
|
|
10
|
+
* (`smtp-relay.brevo.com:587`, login + SMTP key) for an app that would rather
|
|
11
|
+
* not depend on the HTTP API — but the `brevo` adapter is the lighter choice.
|
|
12
|
+
*/
|
|
13
|
+
export interface SmtpEmailOptions {
|
|
14
|
+
host: string;
|
|
15
|
+
port: number;
|
|
16
|
+
/** TLS from the first byte (port 465). Off for STARTTLS on 587. */
|
|
17
|
+
secure?: boolean;
|
|
18
|
+
/** Both omitted for a relay that needs no authentication (a local MailHog, say). */
|
|
19
|
+
user?: string;
|
|
20
|
+
password?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface BrevoEmailOptions {
|
|
23
|
+
apiKey: string;
|
|
24
|
+
/** Defaults to `https://api.brevo.com/v3`. */
|
|
25
|
+
baseUrl?: string;
|
|
26
|
+
/** For tests. Defaults to the global `fetch`. */
|
|
27
|
+
fetchImpl?: typeof fetch;
|
|
28
|
+
}
|
|
29
|
+
export interface EmailOptions {
|
|
30
|
+
/** Read from `EMAIL_PROVIDER` when omitted. There is no default: a misconfigured app must not send nowhere in silence. */
|
|
31
|
+
provider?: EmailProvider;
|
|
32
|
+
/** Default sender, `"Name <email>"` or bare. `EMAIL_FROM` when omitted. A message may override it. */
|
|
33
|
+
from?: string;
|
|
34
|
+
/** Default reply-to. `EMAIL_REPLY_TO` when omitted. */
|
|
35
|
+
replyTo?: string;
|
|
36
|
+
resend?: ResendEmailOptions;
|
|
37
|
+
smtp?: SmtpEmailOptions;
|
|
38
|
+
brevo?: BrevoEmailOptions;
|
|
39
|
+
}
|