@jysperu/schema-correo 1.0.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/LICENSE +21 -0
- package/README.md +341 -0
- package/dist/correo.cjs.js +1 -0
- package/dist/correo.d.ts +95 -0
- package/dist/correo.d.ts.map +1 -0
- package/dist/correo.esm.js +1 -0
- package/dist/correo.schema.json +73 -0
- package/dist/correo.umd.js +1 -0
- package/package.json +72 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 JYS Perú
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
# @jysperu/schema-correo
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/js/@jysperu%2Fschema-correo)
|
|
4
|
+
[](https://www.npmjs.com/package/@jysperu/schema-correo)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
[](https://nodejs.org/)
|
|
8
|
+
[](https://www.mongodb.com/)
|
|
9
|
+
[](https://joi.dev/)
|
|
10
|
+
[](https://bundlephobia.com/package/@jysperu/schema-correo)
|
|
11
|
+
|
|
12
|
+
Esquemas para correos electrónicos con soporte para **Mongoose**, **JSON Schema** y **Joi**.
|
|
13
|
+
|
|
14
|
+
## 🚀 Características
|
|
15
|
+
|
|
16
|
+
- 📧 **Validación** de correos electrónicos
|
|
17
|
+
- 🌍 **Formato estándar** RFC 5322 completo
|
|
18
|
+
- 🔧 **Extracción** automática de usuario y dominio
|
|
19
|
+
- 🏷️ **Clasificaciones** del uso de correo (Trabajo, Personal, etc.)
|
|
20
|
+
- ✅ **Estados** de validación y verificación
|
|
21
|
+
|
|
22
|
+
## 📦 Instalación
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install @jysperu/schema-correo
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## ⚡ Inicio Rápido
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { MongoSchemaCorreo, JsonSchemaCorreo, JoiSchemaCorreo } from "@jysperu/schema-correo";
|
|
32
|
+
import { ICorreo, ClasificacionCorreo } from "@jysperu/schema-correo";
|
|
33
|
+
|
|
34
|
+
// Mongoose
|
|
35
|
+
const PersonaSchema = new Schema({
|
|
36
|
+
correos: [MongoSchemaCorreo],
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Joi Validation
|
|
40
|
+
const { error, value } = JoiSchemaCorreo.validate({
|
|
41
|
+
correo: "usuario@ejemplo.com",
|
|
42
|
+
tipo: "Personal",
|
|
43
|
+
valido: true,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// JSON Schema
|
|
47
|
+
const validate = ajv.compile(JsonSchemaCorreo);
|
|
48
|
+
const isValid = validate(correoData);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## 📚 Esquemas Disponibles
|
|
52
|
+
|
|
53
|
+
### 1. 🍃 Mongoose Schema
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import { MongoSchemaCorreo, ICorreo } from "@jysperu/schema-correo";
|
|
57
|
+
import { Schema, model, Document } from "mongoose";
|
|
58
|
+
|
|
59
|
+
interface IPersona extends Document {
|
|
60
|
+
nombres: string;
|
|
61
|
+
correos: ICorreo[];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const PersonaSchema = new Schema<IPersona>({
|
|
65
|
+
nombres: { type: String, required: true },
|
|
66
|
+
correos: [MongoSchemaCorreo], // Array de correos
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const PersonaModel = model<IPersona>("Persona", PersonaSchema);
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 2. 📋 JSON Schema
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import { JsonSchemaCorreo } from "@jysperu/schema-correo";
|
|
76
|
+
import Ajv from "ajv";
|
|
77
|
+
|
|
78
|
+
const ajv = new Ajv();
|
|
79
|
+
const validate = ajv.compile(JsonSchemaCorreo);
|
|
80
|
+
|
|
81
|
+
const correo = {
|
|
82
|
+
correo: "usuario@ejemplo.com",
|
|
83
|
+
tipo: "Personal",
|
|
84
|
+
nombre: "Juan Pérez",
|
|
85
|
+
valido: true,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const valid = validate(correo);
|
|
89
|
+
if (!valid) console.log(validate.errors);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### 3. ✅ Joi Schema
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
import { JoiSchemaCorreo } from "@jysperu/schema-correo";
|
|
96
|
+
|
|
97
|
+
// Validación individual
|
|
98
|
+
const { error, value } = JoiSchemaCorreo.validate({
|
|
99
|
+
correo: "usuario@dominio.com",
|
|
100
|
+
tipo: "Personal",
|
|
101
|
+
nombre: "Ana García",
|
|
102
|
+
valido: true,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
if (error) {
|
|
106
|
+
error.details.forEach((err) => console.log(`❌ ${err.path}: ${err.message}`));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Para arrays de correos
|
|
110
|
+
import Joi from "@jysperu/joi-spanish";
|
|
111
|
+
|
|
112
|
+
const personaSchema = Joi.object({
|
|
113
|
+
nombres: Joi.string().required(),
|
|
114
|
+
correos: Joi.array().items(JoiSchemaCorreo).default([]),
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## 🛠️ Casos de Uso Avanzados
|
|
119
|
+
|
|
120
|
+
### Crear persona con múltiples correos
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
import { MongoSchemaCorreo, ICorreo, ClasificacionCorreo } from "@jysperu/schema-correo";
|
|
124
|
+
|
|
125
|
+
const persona = new PersonaModel({
|
|
126
|
+
nombres: "Ana García",
|
|
127
|
+
correos: [
|
|
128
|
+
{
|
|
129
|
+
correo: "ana.garcia@empresa.com",
|
|
130
|
+
tipo: ClasificacionCorreo.TRABAJO,
|
|
131
|
+
nombre: "Ana García",
|
|
132
|
+
usuario: "ana.garcia",
|
|
133
|
+
dominio: "empresa.com",
|
|
134
|
+
valido: true,
|
|
135
|
+
verificado: true,
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
correo: "ana.personal@gmail.com",
|
|
139
|
+
tipo: ClasificacionCorreo.PERSONAL,
|
|
140
|
+
nombre: "Ana García",
|
|
141
|
+
usuario: "ana.personal",
|
|
142
|
+
dominio: "gmail.com",
|
|
143
|
+
valido: true,
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
await persona.save();
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Operaciones con correos
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
// Buscar correos verificados
|
|
155
|
+
const correosVerificados = persona.correos.filter((correo) => correo.verificado);
|
|
156
|
+
|
|
157
|
+
// Encontrar correos de trabajo
|
|
158
|
+
const correosDetrabajo = persona.correos.filter((correo) => correo.tipo === ClasificacionCorreo.TRABAJO);
|
|
159
|
+
|
|
160
|
+
// Agregar nuevo correo
|
|
161
|
+
persona.correos.push({
|
|
162
|
+
correo: "ana.backup@hotmail.com",
|
|
163
|
+
tipo: "Backup",
|
|
164
|
+
usuario: "ana.backup",
|
|
165
|
+
dominio: "hotmail.com",
|
|
166
|
+
valido: true,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
await persona.save();
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## 📊 Esquema de Datos
|
|
173
|
+
|
|
174
|
+
### ✅ Campo Obligatorio
|
|
175
|
+
|
|
176
|
+
| Campo | Tipo | Validación | Descripción |
|
|
177
|
+
| ------- | -------- | ------------------------------- | ---------------------------------- |
|
|
178
|
+
| `correo` | `String` | Required, trim, formato email | Dirección de correo electrónico |
|
|
179
|
+
|
|
180
|
+
### ⚙️ Campos Opcionales
|
|
181
|
+
|
|
182
|
+
| Campo | Tipo | Validación/Enum | Defecto | Descripción |
|
|
183
|
+
| ------------ | --------- | ------------------------ | ---------- | ------------------------------------- |
|
|
184
|
+
| `tipo` | `String` | Min 1 char, personalizable | "Personal" | Clasificación (Trabajo/Personal) |
|
|
185
|
+
| `nombre` | `String` | Max 100 chars | - | Nombre de la persona |
|
|
186
|
+
| `usuario` | `String` | Max 64 chars, lowercase | - | Parte antes del @ (usuario) |
|
|
187
|
+
| `dominio` | `String` | Max 255 chars, lowercase | - | Parte después del @ (dominio) |
|
|
188
|
+
| `valido` | `Boolean` | true/false | false | Formato de correo válido |
|
|
189
|
+
| `verificado` | `Boolean` | true/false | false | Correo verificado por el usuario |
|
|
190
|
+
|
|
191
|
+
### 🏷️ Clasificaciones Personales
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
enum ClasificacionCorreo {
|
|
195
|
+
TRABAJO = "Trabajo", // 🏢 Correo laboral
|
|
196
|
+
PERSONAL = "Personal", // 👤 Correo personal
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## 💡 Ejemplos de Datos
|
|
201
|
+
|
|
202
|
+
### 📧 Correo Personal (Completo)
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
const correoCompleto: ICorreo = {
|
|
206
|
+
correo: "ana.garcia@gmail.com",
|
|
207
|
+
tipo: "Personal",
|
|
208
|
+
nombre: "Ana García",
|
|
209
|
+
usuario: "ana.garcia",
|
|
210
|
+
dominio: "gmail.com",
|
|
211
|
+
valido: true,
|
|
212
|
+
verificado: true,
|
|
213
|
+
};
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### 🏢 Correo de Trabajo
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
const correoTrabajo: ICorreo = {
|
|
220
|
+
correo: "jperez@empresa.com.pe",
|
|
221
|
+
tipo: "Trabajo",
|
|
222
|
+
nombre: "Juan Pérez",
|
|
223
|
+
usuario: "jperez",
|
|
224
|
+
dominio: "empresa.com.pe",
|
|
225
|
+
valido: true,
|
|
226
|
+
verificado: false,
|
|
227
|
+
};
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### 🔄 Correo Temporal
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
const correoTemporal: ICorreo = {
|
|
234
|
+
correo: "temp.user@10minutemail.com",
|
|
235
|
+
tipo: "Temporal",
|
|
236
|
+
nombre: "Usuario Temporal",
|
|
237
|
+
usuario: "temp.user",
|
|
238
|
+
dominio: "10minutemail.com",
|
|
239
|
+
valido: true,
|
|
240
|
+
verificado: false,
|
|
241
|
+
};
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### 🏫 Correo Educativo
|
|
245
|
+
|
|
246
|
+
```typescript
|
|
247
|
+
const correoEducativo: ICorreo = {
|
|
248
|
+
correo: "estudiante@universidad.edu",
|
|
249
|
+
tipo: "Educativo",
|
|
250
|
+
nombre: "Estudiante Universitario",
|
|
251
|
+
usuario: "estudiante",
|
|
252
|
+
dominio: "universidad.edu",
|
|
253
|
+
valido: true,
|
|
254
|
+
verificado: true,
|
|
255
|
+
};
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## 🔧 Configuración del Esquema
|
|
259
|
+
|
|
260
|
+
```typescript
|
|
261
|
+
// Configuración Mongoose
|
|
262
|
+
{
|
|
263
|
+
strict: false, // Permite campos adicionales
|
|
264
|
+
timestamps: true, // createdAt, updatedAt automáticos
|
|
265
|
+
_id: true // Cada correo tiene su propio ID
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// Configuración Joi
|
|
269
|
+
{
|
|
270
|
+
stripUnknown: false, // Mantiene campos extra
|
|
271
|
+
allowUnknown: true, // Permite propiedades no definidas
|
|
272
|
+
convert: true, // Conversión automática de tipos
|
|
273
|
+
abortEarly: false // Muestra todos los errores
|
|
274
|
+
}
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## 📋 JSON Schema Standalone
|
|
278
|
+
|
|
279
|
+
El archivo `correo.schema.json` se genera automáticamente en cada build:
|
|
280
|
+
|
|
281
|
+
```bash
|
|
282
|
+
# Usar correo.schema.json directamente
|
|
283
|
+
curl -O https://gitlab.com/tiny.node/schema/correo/-/raw/main/dist/correo.schema.json
|
|
284
|
+
|
|
285
|
+
# Validar con cualquier validador JSON Schema
|
|
286
|
+
cat data.json | ajv validate -s correo.schema.json
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
## 🧪 Testing y Validación
|
|
290
|
+
|
|
291
|
+
```typescript
|
|
292
|
+
// Test básico con Joi
|
|
293
|
+
import { JoiSchemaCorreo } from "@jysperu/schema-correo";
|
|
294
|
+
|
|
295
|
+
const testCases = [
|
|
296
|
+
{ correo: "usuario@dominio.com", valid: true },
|
|
297
|
+
{ correo: "", valid: false }, // Vacío
|
|
298
|
+
{ correo: "correo-invalido", valid: false }, // Sin @
|
|
299
|
+
{ correo: "test@", valid: false }, // Sin dominio
|
|
300
|
+
];
|
|
301
|
+
|
|
302
|
+
testCases.forEach((test) => {
|
|
303
|
+
const result = JoiSchemaCorreo.validate(test);
|
|
304
|
+
console.log(`${test.correo}: ${result.error ? "❌" : "✅"}`);
|
|
305
|
+
});
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
## 📦 Build y Distribución
|
|
309
|
+
|
|
310
|
+
```bash
|
|
311
|
+
# Construir el proyecto
|
|
312
|
+
npm run build
|
|
313
|
+
|
|
314
|
+
# Genera automáticamente:
|
|
315
|
+
# └── dist/
|
|
316
|
+
# ├── correo.es.js # ESM
|
|
317
|
+
# ├── correo.cjs.js # CommonJS
|
|
318
|
+
# ├── correo.umd.js # UMD
|
|
319
|
+
# ├── *.d.ts # TypeScript definitions
|
|
320
|
+
# └── correo.schema.json # JSON Schema
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
## 🔗 Enlaces y Recursos
|
|
324
|
+
|
|
325
|
+
- 📘 **Repositorio**: [GitLab - schema-correo](https://gitlab.com/tiny.node/schema/correo)
|
|
326
|
+
- 🐛 **Issues**: [Reportar problemas](https://gitlab.com/tiny.node/schema/correo/issues)
|
|
327
|
+
- 📦 **npm**: [@jysperu/schema-correo](https://www.npmjs.com/package/@jysperu/schema-correo)
|
|
328
|
+
- 📚 **Documentación Joi**: [@jysperu/joi-spanish](https://www.npmjs.com/package/@jysperu/joi-spanish)
|
|
329
|
+
- 🏢 **JYS Perú**: [www.jys.pe](https://www.jys.pe)
|
|
330
|
+
|
|
331
|
+
## 📄 Licencia
|
|
332
|
+
|
|
333
|
+
**MIT License** - Consulta el archivo [LICENSE](./LICENSE) para detalles completos.
|
|
334
|
+
|
|
335
|
+
```text
|
|
336
|
+
MIT License - Copyright (c) 2025 JYS Perú
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
---
|
|
340
|
+
|
|
341
|
+
Desarrollado con ❤️ por [**JYS Perú**](https://www.jys.pe)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0});var t=require("mongoose"),o=require("@jysperu/joi-spanish"),r=(e=>(e.TRABAJO="Trabajo",e.PERSONAL="Personal",e))(r||{});let a=new t.Schema({correo:{type:String,required:[!0,"El correo electrónico es obligatorio"],trim:!0,lowercase:!0,validate:{validator:function(e){return/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(e)},message:"El formato del correo electrónico es inválido"}},tipo:{type:String,default:"Personal",validate:{validator:function(e){return"string"==typeof e&&0<e.trim().length},message:"El tipo debe ser un texto no vacío. Valores sugeridos: "+Object.values(r).join(", ")}},nombre:{type:String,trim:!0,maxlength:[100,"El nombre es demasiado largo"],comment:"Nombre de la persona asociada al correo"},usuario:{type:String,trim:!0,lowercase:!0,maxlength:[64,"El usuario es demasiado largo"]},dominio:{type:String,trim:!0,lowercase:!0,maxlength:[255,"El dominio es demasiado largo"]},valido:{type:Boolean,default:!1},verificado:{type:Boolean,default:!1}},{strict:!1,timestamps:!0}),i=o.object({correo:o.string().email({minDomainSegments:2}).trim().lowercase().required().messages({"string.email":"El formato del correo electrónico es inválido","any.required":"El correo electrónico es obligatorio","string.empty":"El correo no puede estar vacío"}),tipo:o.string().trim().min(1).default("Personal").messages({"string.empty":"El tipo no puede estar vacío","string.min":"El tipo debe tener al menos 1 caracter"}),nombre:o.string().trim().max(100).optional().messages({"string.max":"El nombre no puede exceder 100 caracteres"}),usuario:o.string().trim().lowercase().max(64).optional().messages({"string.max":"El usuario no puede exceder 64 caracteres"}),dominio:o.string().trim().lowercase().max(255).optional().messages({"string.max":"El dominio no puede exceder 255 caracteres"}),valido:o.boolean().default(!1),verificado:o.boolean().default(!1)}).options({stripUnknown:!1,allowUnknown:!0}),n={$schema:"http://json-schema.org/draft-07/schema#",type:"object",properties:{correo:{type:"string",format:"email",pattern:"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$",minLength:5,maxLength:320,description:"Dirección de correo electrónico válida"},tipo:{type:"string",minLength:1,maxLength:50,default:"Personal",enum:Object.values(r),description:"Tipo de correo electrónico"},nombre:{type:"string",minLength:1,maxLength:100,description:"Nombre de la persona asociada al correo",examples:["Juan Pérez","María García"]},usuario:{type:"string",minLength:1,maxLength:64,pattern:"^[a-zA-Z0-9._%+-]+$",description:"Parte del usuario del correo electrónico (antes del @)",examples:["usuario","juan.perez"]},dominio:{type:"string",minLength:4,maxLength:255,pattern:"^[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$",description:"Dominio del correo electrónico (después del @)",examples:["ejemplo.com","domain.org"]},valido:{type:"boolean",default:!1,description:"Indica si el formato del correo es válido"},verificado:{type:"boolean",default:!1,description:"Indica si el correo ha sido verificado"}},required:["correo"],additionalProperties:!0,title:"Correo Electrónico",description:"Esquema para correos electrónicos"};exports.ClasificacionCorreo=r,exports.JoiSchemaCorreo=i,exports.JsonSchemaCorreo=n,exports.MongoSchemaCorreo=a,exports.default=a;
|
package/dist/correo.d.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Schema } from 'mongoose';
|
|
2
|
+
import { default as Joi } from '@jysperu/joi-spanish';
|
|
3
|
+
export declare enum ClasificacionCorreo {
|
|
4
|
+
TRABAJO = "Trabajo",
|
|
5
|
+
PERSONAL = "Personal"
|
|
6
|
+
}
|
|
7
|
+
export interface ICorreo {
|
|
8
|
+
correo: string;
|
|
9
|
+
tipo?: string;
|
|
10
|
+
nombre?: string;
|
|
11
|
+
usuario?: string;
|
|
12
|
+
dominio?: string;
|
|
13
|
+
valido?: boolean;
|
|
14
|
+
verificado?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Esquema de Mongoose para correos electrónicos
|
|
18
|
+
*/
|
|
19
|
+
export declare const MongoSchemaCorreo: Schema<ICorreo, import('mongoose').Model<ICorreo, any, any, any, import('mongoose').Document<unknown, any, ICorreo, any, {}> & ICorreo & {
|
|
20
|
+
_id: import("mongoose").Types.ObjectId;
|
|
21
|
+
} & {
|
|
22
|
+
__v: number;
|
|
23
|
+
}, any>, {}, {}, {}, {}, import('mongoose').DefaultSchemaOptions, ICorreo, import('mongoose').Document<unknown, {}, import('mongoose').FlatRecord<ICorreo>, {}, import('mongoose').ResolveSchemaOptions<import('mongoose').DefaultSchemaOptions>> & import('mongoose').FlatRecord<ICorreo> & {
|
|
24
|
+
_id: import("mongoose").Types.ObjectId;
|
|
25
|
+
} & {
|
|
26
|
+
__v: number;
|
|
27
|
+
}>;
|
|
28
|
+
export default MongoSchemaCorreo;
|
|
29
|
+
/**
|
|
30
|
+
* Joi Schema para validación de correos electrónicos
|
|
31
|
+
*/
|
|
32
|
+
export declare const JoiSchemaCorreo: Joi.ObjectSchema<any>;
|
|
33
|
+
/**
|
|
34
|
+
* JSON Schema para validación de correos electrónicos
|
|
35
|
+
*/
|
|
36
|
+
export declare const JsonSchemaCorreo: {
|
|
37
|
+
readonly $schema: "http://json-schema.org/draft-07/schema#";
|
|
38
|
+
readonly type: "object";
|
|
39
|
+
readonly properties: {
|
|
40
|
+
readonly correo: {
|
|
41
|
+
readonly type: "string";
|
|
42
|
+
readonly format: "email";
|
|
43
|
+
readonly pattern: "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$";
|
|
44
|
+
readonly minLength: 5;
|
|
45
|
+
readonly maxLength: 320;
|
|
46
|
+
readonly description: "Dirección de correo electrónico válida";
|
|
47
|
+
};
|
|
48
|
+
readonly tipo: {
|
|
49
|
+
readonly type: "string";
|
|
50
|
+
readonly minLength: 1;
|
|
51
|
+
readonly maxLength: 50;
|
|
52
|
+
readonly default: "Personal";
|
|
53
|
+
readonly enum: ClasificacionCorreo[];
|
|
54
|
+
readonly description: "Tipo de correo electrónico";
|
|
55
|
+
};
|
|
56
|
+
readonly nombre: {
|
|
57
|
+
readonly type: "string";
|
|
58
|
+
readonly minLength: 1;
|
|
59
|
+
readonly maxLength: 100;
|
|
60
|
+
readonly description: "Nombre de la persona asociada al correo";
|
|
61
|
+
readonly examples: readonly ["Juan Pérez", "María García"];
|
|
62
|
+
};
|
|
63
|
+
readonly usuario: {
|
|
64
|
+
readonly type: "string";
|
|
65
|
+
readonly minLength: 1;
|
|
66
|
+
readonly maxLength: 64;
|
|
67
|
+
readonly pattern: "^[a-zA-Z0-9._%+-]+$";
|
|
68
|
+
readonly description: "Parte del usuario del correo electrónico (antes del @)";
|
|
69
|
+
readonly examples: readonly ["usuario", "juan.perez"];
|
|
70
|
+
};
|
|
71
|
+
readonly dominio: {
|
|
72
|
+
readonly type: "string";
|
|
73
|
+
readonly minLength: 4;
|
|
74
|
+
readonly maxLength: 255;
|
|
75
|
+
readonly pattern: "^[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$";
|
|
76
|
+
readonly description: "Dominio del correo electrónico (después del @)";
|
|
77
|
+
readonly examples: readonly ["ejemplo.com", "domain.org"];
|
|
78
|
+
};
|
|
79
|
+
readonly valido: {
|
|
80
|
+
readonly type: "boolean";
|
|
81
|
+
readonly default: false;
|
|
82
|
+
readonly description: "Indica si el formato del correo es válido";
|
|
83
|
+
};
|
|
84
|
+
readonly verificado: {
|
|
85
|
+
readonly type: "boolean";
|
|
86
|
+
readonly default: false;
|
|
87
|
+
readonly description: "Indica si el correo ha sido verificado";
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
readonly required: readonly ["correo"];
|
|
91
|
+
readonly additionalProperties: true;
|
|
92
|
+
readonly title: "Correo Electrónico";
|
|
93
|
+
readonly description: "Esquema para correos electrónicos";
|
|
94
|
+
};
|
|
95
|
+
//# sourceMappingURL=correo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"correo.d.ts","sourceRoot":"","sources":["../src/correo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,GAAG,MAAM,sBAAsB,CAAC;AAGvC,oBAAY,mBAAmB;IAC7B,OAAO,YAAY;IACnB,QAAQ,aAAa;CACtB;AAGD,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;EA+D7B,CAAC;AAEF,eAAe,iBAAiB,CAAC;AAEjC;;GAEG;AACH,eAAO,MAAM,eAAe,uBAqC1B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0DnB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Schema as a}from"mongoose";import o from"@jysperu/joi-spanish";var r=(e=>(e.TRABAJO="Trabajo",e.PERSONAL="Personal",e))(r||{});let n=new a({correo:{type:String,required:[!0,"El correo electrónico es obligatorio"],trim:!0,lowercase:!0,validate:{validator:function(e){return/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(e)},message:"El formato del correo electrónico es inválido"}},tipo:{type:String,default:"Personal",validate:{validator:function(e){return"string"==typeof e&&0<e.trim().length},message:"El tipo debe ser un texto no vacío. Valores sugeridos: "+Object.values(r).join(", ")}},nombre:{type:String,trim:!0,maxlength:[100,"El nombre es demasiado largo"],comment:"Nombre de la persona asociada al correo"},usuario:{type:String,trim:!0,lowercase:!0,maxlength:[64,"El usuario es demasiado largo"]},dominio:{type:String,trim:!0,lowercase:!0,maxlength:[255,"El dominio es demasiado largo"]},valido:{type:Boolean,default:!1},verificado:{type:Boolean,default:!1}},{strict:!1,timestamps:!0}),s=o.object({correo:o.string().email({minDomainSegments:2}).trim().lowercase().required().messages({"string.email":"El formato del correo electrónico es inválido","any.required":"El correo electrónico es obligatorio","string.empty":"El correo no puede estar vacío"}),tipo:o.string().trim().min(1).default("Personal").messages({"string.empty":"El tipo no puede estar vacío","string.min":"El tipo debe tener al menos 1 caracter"}),nombre:o.string().trim().max(100).optional().messages({"string.max":"El nombre no puede exceder 100 caracteres"}),usuario:o.string().trim().lowercase().max(64).optional().messages({"string.max":"El usuario no puede exceder 64 caracteres"}),dominio:o.string().trim().lowercase().max(255).optional().messages({"string.max":"El dominio no puede exceder 255 caracteres"}),valido:o.boolean().default(!1),verificado:o.boolean().default(!1)}).options({stripUnknown:!1,allowUnknown:!0}),l={$schema:"http://json-schema.org/draft-07/schema#",type:"object",properties:{correo:{type:"string",format:"email",pattern:"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$",minLength:5,maxLength:320,description:"Dirección de correo electrónico válida"},tipo:{type:"string",minLength:1,maxLength:50,default:"Personal",enum:Object.values(r),description:"Tipo de correo electrónico"},nombre:{type:"string",minLength:1,maxLength:100,description:"Nombre de la persona asociada al correo",examples:["Juan Pérez","María García"]},usuario:{type:"string",minLength:1,maxLength:64,pattern:"^[a-zA-Z0-9._%+-]+$",description:"Parte del usuario del correo electrónico (antes del @)",examples:["usuario","juan.perez"]},dominio:{type:"string",minLength:4,maxLength:255,pattern:"^[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$",description:"Dominio del correo electrónico (después del @)",examples:["ejemplo.com","domain.org"]},valido:{type:"boolean",default:!1,description:"Indica si el formato del correo es válido"},verificado:{type:"boolean",default:!1,description:"Indica si el correo ha sido verificado"}},required:["correo"],additionalProperties:!0,title:"Correo Electrónico",description:"Esquema para correos electrónicos"};export{r as ClasificacionCorreo,s as JoiSchemaCorreo,l as JsonSchemaCorreo,n as MongoSchemaCorreo,n as default};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"type": "object",
|
|
4
|
+
"properties": {
|
|
5
|
+
"correo": {
|
|
6
|
+
"type": "string",
|
|
7
|
+
"format": "email",
|
|
8
|
+
"pattern": "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$",
|
|
9
|
+
"minLength": 5,
|
|
10
|
+
"maxLength": 320,
|
|
11
|
+
"description": "Dirección de correo electrónico válida"
|
|
12
|
+
},
|
|
13
|
+
"tipo": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"minLength": 1,
|
|
16
|
+
"maxLength": 50,
|
|
17
|
+
"default": "Personal",
|
|
18
|
+
"enum": [
|
|
19
|
+
"Trabajo",
|
|
20
|
+
"Personal"
|
|
21
|
+
],
|
|
22
|
+
"description": "Tipo de correo electrónico"
|
|
23
|
+
},
|
|
24
|
+
"nombre": {
|
|
25
|
+
"type": "string",
|
|
26
|
+
"minLength": 1,
|
|
27
|
+
"maxLength": 100,
|
|
28
|
+
"description": "Nombre de la persona asociada al correo",
|
|
29
|
+
"examples": [
|
|
30
|
+
"Juan Pérez",
|
|
31
|
+
"María García"
|
|
32
|
+
]
|
|
33
|
+
},
|
|
34
|
+
"usuario": {
|
|
35
|
+
"type": "string",
|
|
36
|
+
"minLength": 1,
|
|
37
|
+
"maxLength": 64,
|
|
38
|
+
"pattern": "^[a-zA-Z0-9._%+-]+$",
|
|
39
|
+
"description": "Parte del usuario del correo electrónico (antes del @)",
|
|
40
|
+
"examples": [
|
|
41
|
+
"usuario",
|
|
42
|
+
"juan.perez"
|
|
43
|
+
]
|
|
44
|
+
},
|
|
45
|
+
"dominio": {
|
|
46
|
+
"type": "string",
|
|
47
|
+
"minLength": 4,
|
|
48
|
+
"maxLength": 255,
|
|
49
|
+
"pattern": "^[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$",
|
|
50
|
+
"description": "Dominio del correo electrónico (después del @)",
|
|
51
|
+
"examples": [
|
|
52
|
+
"ejemplo.com",
|
|
53
|
+
"domain.org"
|
|
54
|
+
]
|
|
55
|
+
},
|
|
56
|
+
"valido": {
|
|
57
|
+
"type": "boolean",
|
|
58
|
+
"default": false,
|
|
59
|
+
"description": "Indica si el formato del correo es válido"
|
|
60
|
+
},
|
|
61
|
+
"verificado": {
|
|
62
|
+
"type": "boolean",
|
|
63
|
+
"default": false,
|
|
64
|
+
"description": "Indica si el correo ha sido verificado"
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"required": [
|
|
68
|
+
"correo"
|
|
69
|
+
],
|
|
70
|
+
"additionalProperties": true,
|
|
71
|
+
"title": "Correo Electrónico",
|
|
72
|
+
"description": "Esquema para correos electrónicos"
|
|
73
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
((e,o)=>{"object"==typeof exports&&typeof module<"u"?o(exports,require("mongoose"),require("@jysperu/joi-spanish")):"function"==typeof define&&define.amd?define("@jysperu/schema-correo",["exports","mongoose","@jysperu/joi-spanish"],o):o(((e=typeof globalThis<"u"?globalThis:e||self).JCore=e.JCore||{},e.JCore.schema=e.JCore.schema||{},e.JCore.schema.correo={}),e.mongoose,e.Joi)})(this,function(e,o,r){(a={}).TRABAJO="Trabajo",a.PERSONAL="Personal";var a,o=new o.Schema({correo:{type:String,required:[!0,"El correo electrónico es obligatorio"],trim:!0,lowercase:!0,validate:{validator:function(e){return/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(e)},message:"El formato del correo electrónico es inválido"}},tipo:{type:String,default:"Personal",validate:{validator:function(e){return"string"==typeof e&&0<e.trim().length},message:"El tipo debe ser un texto no vacío. Valores sugeridos: "+Object.values(a).join(", ")}},nombre:{type:String,trim:!0,maxlength:[100,"El nombre es demasiado largo"],comment:"Nombre de la persona asociada al correo"},usuario:{type:String,trim:!0,lowercase:!0,maxlength:[64,"El usuario es demasiado largo"]},dominio:{type:String,trim:!0,lowercase:!0,maxlength:[255,"El dominio es demasiado largo"]},valido:{type:Boolean,default:!1},verificado:{type:Boolean,default:!1}},{strict:!1,timestamps:!0}),r=r.object({correo:r.string().email({minDomainSegments:2}).trim().lowercase().required().messages({"string.email":"El formato del correo electrónico es inválido","any.required":"El correo electrónico es obligatorio","string.empty":"El correo no puede estar vacío"}),tipo:r.string().trim().min(1).default("Personal").messages({"string.empty":"El tipo no puede estar vacío","string.min":"El tipo debe tener al menos 1 caracter"}),nombre:r.string().trim().max(100).optional().messages({"string.max":"El nombre no puede exceder 100 caracteres"}),usuario:r.string().trim().lowercase().max(64).optional().messages({"string.max":"El usuario no puede exceder 64 caracteres"}),dominio:r.string().trim().lowercase().max(255).optional().messages({"string.max":"El dominio no puede exceder 255 caracteres"}),valido:r.boolean().default(!1),verificado:r.boolean().default(!1)}).options({stripUnknown:!1,allowUnknown:!0}),i={$schema:"http://json-schema.org/draft-07/schema#",type:"object",properties:{correo:{type:"string",format:"email",pattern:"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$",minLength:5,maxLength:320,description:"Dirección de correo electrónico válida"},tipo:{type:"string",minLength:1,maxLength:50,default:"Personal",enum:Object.values(a),description:"Tipo de correo electrónico"},nombre:{type:"string",minLength:1,maxLength:100,description:"Nombre de la persona asociada al correo",examples:["Juan Pérez","María García"]},usuario:{type:"string",minLength:1,maxLength:64,pattern:"^[a-zA-Z0-9._%+-]+$",description:"Parte del usuario del correo electrónico (antes del @)",examples:["usuario","juan.perez"]},dominio:{type:"string",minLength:4,maxLength:255,pattern:"^[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$",description:"Dominio del correo electrónico (después del @)",examples:["ejemplo.com","domain.org"]},valido:{type:"boolean",default:!1,description:"Indica si el formato del correo es válido"},verificado:{type:"boolean",default:!1,description:"Indica si el correo ha sido verificado"}},required:["correo"],additionalProperties:!0,title:"Correo Electrónico",description:"Esquema para correos electrónicos"};e.ClasificacionCorreo=a,e.JoiSchemaCorreo=r,e.JsonSchemaCorreo=i,e.MongoSchemaCorreo=o,e.default=o,Object.defineProperty(e,"__esModule",{value:!0})});
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jysperu/schema-correo",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Esquemas para correos electrónicos: Mongoose, JSON Schema y Joi",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"mongoose",
|
|
7
|
+
"schema",
|
|
8
|
+
"correo",
|
|
9
|
+
"validation",
|
|
10
|
+
"joi",
|
|
11
|
+
"json-schema",
|
|
12
|
+
"typescript",
|
|
13
|
+
"spanish"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://gitlab.com/tiny.node/schema/correo#readme",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://gitlab.com/tiny.node/schema/correo/issues"
|
|
18
|
+
},
|
|
19
|
+
"type": "module",
|
|
20
|
+
"main": "./dist/correo.umd.js",
|
|
21
|
+
"module": "./dist/correo.esm.js",
|
|
22
|
+
"types": "./dist/correo.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/correo.d.ts",
|
|
26
|
+
"import": "./dist/correo.esm.js",
|
|
27
|
+
"require": "./dist/correo.cjs.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"README.md",
|
|
33
|
+
"LICENSE"
|
|
34
|
+
],
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=16.0.0"
|
|
37
|
+
},
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"author": {
|
|
40
|
+
"name": "JYS Perú",
|
|
41
|
+
"url": "https://www.jys.pe",
|
|
42
|
+
"email": "developers@jys.pe"
|
|
43
|
+
},
|
|
44
|
+
"contributors": [
|
|
45
|
+
"JYS Perú <developers@jys.pe>"
|
|
46
|
+
],
|
|
47
|
+
"repository": {
|
|
48
|
+
"type": "git",
|
|
49
|
+
"url": "git+https://gitlab.com/tiny.node/schema/correo.git"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "vite build",
|
|
53
|
+
"dev": "vite build --watch",
|
|
54
|
+
"typecheck": "tsc --noEmit",
|
|
55
|
+
"lint": "tsc --noEmit && echo \"✅ TypeScript check passed\"",
|
|
56
|
+
"prepublishOnly": "npm run build",
|
|
57
|
+
"test": "echo \"⚠️ No tests specified\" && exit 0"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@node-minify/core": "^9.0.2",
|
|
61
|
+
"@node-minify/uglify-es": "^9.0.1",
|
|
62
|
+
"@node-minify/uglify-js": "^9.0.1",
|
|
63
|
+
"@types/node": "^24.10.1",
|
|
64
|
+
"typescript": "^5.8.3",
|
|
65
|
+
"vite": "^6.2.5",
|
|
66
|
+
"vite-plugin-dts": "^4.5.3"
|
|
67
|
+
},
|
|
68
|
+
"dependencies": {
|
|
69
|
+
"@jysperu/joi-spanish": "^17.13.4",
|
|
70
|
+
"mongoose": "^8.13.2"
|
|
71
|
+
}
|
|
72
|
+
}
|