@atlas-id/contracts 0.1.0 → 0.2.1

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.
@@ -0,0 +1,911 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * Representa una versión semántica en formato MAJOR.MINOR.PATCH
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * const version: SemanticVersion = '1.2.3';
9
+ * ```
10
+ */
11
+ type SemanticVersion = `${number}.${number}.${number}`;
12
+ /**
13
+ * Estructura que contiene un payload con su versión asociada.
14
+ * Útil para versionado de datos y compatibilidad entre versiones.
15
+ *
16
+ * @template TPayload - Tipo del payload versionado
17
+ */
18
+ type Versioned<TPayload> = {
19
+ version: SemanticVersion;
20
+ payload: TPayload;
21
+ };
22
+ /**
23
+ * Valida si una cadena de texto cumple con el formato de versión semántica.
24
+ *
25
+ * @param version - Cadena a validar
26
+ * @returns true si es una versión semántica válida, false en caso contrario
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * isValidSemanticVersion('1.2.3'); // true
31
+ * isValidSemanticVersion('1.2'); // false
32
+ * isValidSemanticVersion('invalid'); // false
33
+ * ```
34
+ */
35
+ declare function isValidSemanticVersion(version: string): version is SemanticVersion;
36
+ /**
37
+ * Parsea una versión semántica y retorna sus componentes numéricos.
38
+ *
39
+ * @param version - Versión semántica a parsear
40
+ * @returns Objeto con major, minor y patch, o null si la versión es inválida
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * parseSemanticVersion('1.2.3'); // { major: 1, minor: 2, patch: 3 }
45
+ * parseSemanticVersion('invalid'); // null
46
+ * ```
47
+ */
48
+ declare function parseSemanticVersion(version: string): {
49
+ major: number;
50
+ minor: number;
51
+ patch: number;
52
+ } | null;
53
+ /**
54
+ * Compara dos versiones semánticas.
55
+ *
56
+ * @param version1 - Primera versión a comparar
57
+ * @param version2 - Segunda versión a comparar
58
+ * @returns -1 si version1 < version2, 0 si son iguales, 1 si version1 > version2
59
+ * @throws Error si alguna de las versiones es inválida
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * compareSemanticVersions('1.2.3', '1.2.4'); // -1
64
+ * compareSemanticVersions('2.0.0', '1.9.9'); // 1
65
+ * compareSemanticVersions('1.0.0', '1.0.0'); // 0
66
+ * ```
67
+ */
68
+ declare function compareSemanticVersions(version1: string, version2: string): number;
69
+ /**
70
+ * Verifica si una versión es mayor que otra.
71
+ *
72
+ * @param version1 - Versión a comparar
73
+ * @param version2 - Versión de referencia
74
+ * @returns true si version1 > version2
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * isVersionGreaterThan('2.0.0', '1.9.9'); // true
79
+ * isVersionGreaterThan('1.0.0', '1.0.0'); // false
80
+ * ```
81
+ */
82
+ declare function isVersionGreaterThan(version1: string, version2: string): boolean;
83
+ /**
84
+ * Verifica si una versión es menor que otra.
85
+ *
86
+ * @param version1 - Versión a comparar
87
+ * @param version2 - Versión de referencia
88
+ * @returns true si version1 < version2
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * isVersionLessThan('1.0.0', '2.0.0'); // true
93
+ * ```
94
+ */
95
+ declare function isVersionLessThan(version1: string, version2: string): boolean;
96
+ /**
97
+ * Verifica si una versión es mayor o igual que otra.
98
+ *
99
+ * @param version1 - Versión a comparar
100
+ * @param version2 - Versión de referencia
101
+ * @returns true si version1 >= version2
102
+ */
103
+ declare function isVersionGreaterOrEqual(version1: string, version2: string): boolean;
104
+ /**
105
+ * Verifica si una versión es menor o igual que otra.
106
+ *
107
+ * @param version1 - Versión a comparar
108
+ * @param version2 - Versión de referencia
109
+ * @returns true si version1 <= version2
110
+ */
111
+ declare function isVersionLessOrEqual(version1: string, version2: string): boolean;
112
+
113
+ /**
114
+ * Constantes para tipos de eventos del sistema de notificaciones.
115
+ * Centraliza los nombres de eventos para evitar errores de tipeo.
116
+ */
117
+ declare const NOTIFICATION_EVENT_TYPES: {
118
+ readonly REQUESTED: "notifications.requested";
119
+ readonly DISPATCHED: "notifications.dispatched";
120
+ readonly DELIVERED: "notifications.delivered";
121
+ readonly FAILED: "notifications.failed";
122
+ };
123
+ /**
124
+ * Constantes para tipos de eventos de conexiones OAuth.
125
+ */
126
+ declare const OAUTH_CONNECTION_EVENT_TYPES: {
127
+ readonly LINKED: "oauth.connection.linked";
128
+ readonly TOKEN_REFRESHED: "oauth.connection.token_refreshed";
129
+ readonly REVOKED: "oauth.connection.revoked";
130
+ };
131
+ /**
132
+ * Metadata asociada a un evento para trazabilidad y correlación en sistemas distribuidos.
133
+ *
134
+ * @property traceId - ID de traza para distributed tracing (OpenTelemetry, etc.)
135
+ * @property spanId - ID de span dentro de la traza
136
+ * @property correlationId - ID para correlacionar eventos relacionados en un flujo de negocio
137
+ * @property causationId - ID del evento que causó este evento (event sourcing)
138
+ * @property tenantId - ID del tenant en arquitecturas multi-tenant
139
+ * @property projectId - ID del proyecto asociado
140
+ * @property source - Nombre del servicio o componente que originó el evento
141
+ */
142
+ type EventMeta = {
143
+ traceId?: string;
144
+ spanId?: string;
145
+ correlationId?: string;
146
+ causationId?: string;
147
+ tenantId?: string;
148
+ projectId?: string;
149
+ source: string;
150
+ };
151
+ /**
152
+ * Envelope que envuelve un evento con toda su metadata y información de versionado.
153
+ * Esta estructura permite la serialización, transmisión y procesamiento de eventos
154
+ * en sistemas distribuidos con garantías de trazabilidad.
155
+ *
156
+ * @template TPayload - Tipo del payload específico del evento
157
+ * @template TMeta - Tipo de metadata (por defecto EventMeta)
158
+ *
159
+ * @property id - Identificador único del evento (recomendado: UUID v4)
160
+ * @property type - Tipo del evento (ej: 'notifications.requested')
161
+ * @property version - Versión semántica del contrato del evento
162
+ * @property occurredAt - Timestamp ISO 8601 de cuándo ocurrió el evento
163
+ * @property payload - Datos específicos del evento
164
+ * @property meta - Metadata de trazabilidad y contexto
165
+ */
166
+ type EventEnvelope<TPayload, TMeta extends EventMeta = EventMeta> = {
167
+ id: string;
168
+ type: string;
169
+ version: SemanticVersion;
170
+ occurredAt: string;
171
+ payload: TPayload;
172
+ meta: TMeta;
173
+ };
174
+ /**
175
+ * Contrato que define la estructura y versión de un tipo de evento.
176
+ * Incluye un ejemplo para documentación y validación.
177
+ *
178
+ * @template TPayload - Tipo del payload del evento
179
+ * @template TMeta - Tipo de metadata del evento
180
+ *
181
+ * @property type - Tipo del evento
182
+ * @property version - Versión semántica del contrato
183
+ * @property schema - Identificador del esquema (formato: tipo@version)
184
+ * @property example - Ejemplo completo de un evento de este tipo
185
+ */
186
+ type EventContract<TPayload, TMeta extends EventMeta = EventMeta> = {
187
+ type: string;
188
+ version: SemanticVersion;
189
+ schema: string;
190
+ example: EventEnvelope<TPayload, TMeta>;
191
+ };
192
+
193
+ /**
194
+ * Canales disponibles para el envío de notificaciones.
195
+ */
196
+ type NotificationChannel = 'email' | 'sms' | 'webhook';
197
+ /**
198
+ * Base común para todas las solicitudes de notificación.
199
+ * Contiene campos compartidos entre todos los tipos de canales.
200
+ *
201
+ * @property channel - Canal de notificación a utilizar
202
+ * @property projectId - ID del proyecto que solicita la notificación
203
+ * @property tenantId - ID del tenant (opcional, para multi-tenancy)
204
+ * @property locale - Código de idioma para localización (ej: 'es-ES', 'en-US')
205
+ * @property deduplicationKey - Clave opcional para prevenir duplicados
206
+ * @property expiresAt - Timestamp ISO 8601 de expiración de la notificación
207
+ * @property metadata - Metadatos adicionales como pares clave-valor
208
+ */
209
+ type BaseNotificationRequest = {
210
+ channel: NotificationChannel;
211
+ projectId: string;
212
+ tenantId?: string;
213
+ locale?: string;
214
+ deduplicationKey?: string;
215
+ expiresAt?: string;
216
+ metadata?: Record<string, string>;
217
+ };
218
+ /**
219
+ * Solicitud de notificación por correo electrónico.
220
+ *
221
+ * @property channel - Debe ser 'email'
222
+ * @property to - Dirección de correo electrónico del destinatario
223
+ * @property templateId - ID del template de email a utilizar
224
+ * @property variables - Variables para reemplazar en el template
225
+ * @property cc - Lista opcional de direcciones en copia
226
+ * @property bcc - Lista opcional de direcciones en copia oculta
227
+ * @property replyTo - Dirección de respuesta opcional
228
+ */
229
+ type EmailNotificationRequest = BaseNotificationRequest & {
230
+ channel: 'email';
231
+ to: string;
232
+ templateId: string;
233
+ variables?: Record<string, string | number | boolean | null>;
234
+ cc?: string[];
235
+ bcc?: string[];
236
+ replyTo?: string;
237
+ };
238
+ /**
239
+ * Solicitud de notificación por SMS.
240
+ *
241
+ * @property channel - Debe ser 'sms'
242
+ * @property to - Número de teléfono del destinatario (formato E.164 recomendado)
243
+ * @property templateId - ID del template de SMS a utilizar
244
+ * @property variables - Variables para reemplazar en el template
245
+ */
246
+ type SmsNotificationRequest = BaseNotificationRequest & {
247
+ channel: 'sms';
248
+ to: string;
249
+ templateId: string;
250
+ variables?: Record<string, string | number | boolean | null>;
251
+ };
252
+ /**
253
+ * Solicitud de notificación por webhook.
254
+ *
255
+ * @property channel - Debe ser 'webhook'
256
+ * @property url - URL del endpoint que recibirá el webhook
257
+ * @property signatureVersion - Versión del algoritmo de firma para verificación
258
+ * @property body - Cuerpo del webhook (estructura libre)
259
+ */
260
+ type WebhookNotificationRequest = BaseNotificationRequest & {
261
+ channel: 'webhook';
262
+ url: string;
263
+ signatureVersion: SemanticVersion;
264
+ body: unknown;
265
+ };
266
+ /**
267
+ * Unión de todos los tipos de solicitudes de notificación.
268
+ * Utiliza discriminated union basado en el campo 'channel'.
269
+ */
270
+ type NotificationRequest = EmailNotificationRequest | SmsNotificationRequest | WebhookNotificationRequest;
271
+ /**
272
+ * Estados posibles de una notificación en su ciclo de vida.
273
+ *
274
+ * - requested: Solicitud creada, pendiente de procesamiento
275
+ * - scheduled: Programada para envío futuro
276
+ * - dispatched: Enviada al proveedor externo
277
+ * - delivered: Confirmada como entregada por el proveedor
278
+ * - failed: Falló el envío o entrega
279
+ * - cancelled: Cancelada antes de ser enviada
280
+ */
281
+ type NotificationStatus = 'requested' | 'scheduled' | 'dispatched' | 'delivered' | 'failed' | 'cancelled';
282
+ /**
283
+ * Envelope que contiene una notificación con su estado y metadata.
284
+ *
285
+ * @property id - Identificador único de la notificación
286
+ * @property request - Solicitud original de la notificación
287
+ * @property status - Estado actual de la notificación
288
+ * @property createdAt - Timestamp ISO 8601 de creación
289
+ * @property updatedAt - Timestamp ISO 8601 de última actualización
290
+ * @property lastError - Información del último error si el estado es 'failed'
291
+ * @property providerResponseId - ID de respuesta del proveedor externo
292
+ */
293
+ type NotificationEnvelope = {
294
+ id: string;
295
+ request: NotificationRequest;
296
+ status: NotificationStatus;
297
+ createdAt: string;
298
+ updatedAt: string;
299
+ lastError?: {
300
+ code: string;
301
+ message: string;
302
+ retriable: boolean;
303
+ };
304
+ providerResponseId?: string;
305
+ };
306
+ /**
307
+ * Type guard para verificar si una solicitud es de tipo email.
308
+ *
309
+ * @param request - Solicitud a verificar
310
+ * @returns true si es EmailNotificationRequest
311
+ */
312
+ declare function isEmailNotificationRequest(request: NotificationRequest): request is EmailNotificationRequest;
313
+ /**
314
+ * Type guard para verificar si una solicitud es de tipo SMS.
315
+ *
316
+ * @param request - Solicitud a verificar
317
+ * @returns true si es SmsNotificationRequest
318
+ */
319
+ declare function isSmsNotificationRequest(request: NotificationRequest): request is SmsNotificationRequest;
320
+ /**
321
+ * Type guard para verificar si una solicitud es de tipo webhook.
322
+ *
323
+ * @param request - Solicitud a verificar
324
+ * @returns true si es WebhookNotificationRequest
325
+ */
326
+ declare function isWebhookNotificationRequest(request: NotificationRequest): request is WebhookNotificationRequest;
327
+ type RequestedPayload = {
328
+ notification: NotificationEnvelope;
329
+ };
330
+ type DispatchedPayload = {
331
+ notificationId: string;
332
+ channel: NotificationChannel;
333
+ provider: string;
334
+ providerMessageId?: string;
335
+ };
336
+ type DeliveredPayload = {
337
+ notificationId: string;
338
+ deliveredAt: string;
339
+ };
340
+ type FailedPayload = {
341
+ notificationId: string;
342
+ failedAt: string;
343
+ errorCode: string;
344
+ message: string;
345
+ retriable: boolean;
346
+ };
347
+ /**
348
+ * Contratos de eventos para el sistema de notificaciones.
349
+ * Define los eventos que se emiten durante el ciclo de vida de una notificación.
350
+ */
351
+ declare const notificationEvents: Record<'requested' | 'dispatched' | 'delivered' | 'failed', EventContract<RequestedPayload | DispatchedPayload | DeliveredPayload | FailedPayload>>;
352
+ /**
353
+ * Unión de todos los tipos de eventos de notificaciones.
354
+ */
355
+ type NotificationEvent = EventEnvelope<RequestedPayload> | EventEnvelope<DispatchedPayload> | EventEnvelope<DeliveredPayload> | EventEnvelope<FailedPayload>;
356
+
357
+ /**
358
+ * Categorías de proveedores OAuth soportados.
359
+ *
360
+ * - oauth2: OAuth 2.0 estándar
361
+ * - oidc: OpenID Connect (extensión de OAuth 2.0)
362
+ * - saml: Security Assertion Markup Language
363
+ */
364
+ type OAuthProviderCategory = 'oauth2' | 'oidc' | 'saml';
365
+ /**
366
+ * Definición de un proveedor OAuth configurado en el sistema.
367
+ *
368
+ * @property id - Identificador único del proveedor (ej: 'google', 'github')
369
+ * @property name - Nombre legible del proveedor
370
+ * @property category - Categoría del protocolo OAuth
371
+ * @property authorizationUrl - URL del endpoint de autorización
372
+ * @property tokenUrl - URL del endpoint de intercambio de tokens
373
+ * @property scopes - Lista de scopes soportados por el proveedor
374
+ * @property supportsPkce - Indica si el proveedor soporta PKCE (Proof Key for Code Exchange)
375
+ * @property requiresWebhookForRefresh - Indica si requiere webhook para refrescar tokens
376
+ */
377
+ type OAuthProvider = {
378
+ id: string;
379
+ name: string;
380
+ category: OAuthProviderCategory;
381
+ authorizationUrl: string;
382
+ tokenUrl: string;
383
+ scopes: string[];
384
+ supportsPkce: boolean;
385
+ requiresWebhookForRefresh?: boolean;
386
+ };
387
+ /**
388
+ * Conexión OAuth establecida entre un usuario y un proveedor.
389
+ * Representa la autorización activa de un usuario para acceder a recursos del proveedor.
390
+ *
391
+ * @property id - Identificador único de la conexión
392
+ * @property providerId - ID del proveedor OAuth
393
+ * @property projectId - ID del proyecto asociado
394
+ * @property tenantId - ID del tenant (opcional, para multi-tenancy)
395
+ * @property userId - ID del usuario que autorizó la conexión
396
+ * @property scope - Lista de scopes autorizados en esta conexión
397
+ * @property expiresAt - Timestamp ISO 8601 de expiración de la conexión
398
+ * @property createdAt - Timestamp ISO 8601 de creación
399
+ * @property updatedAt - Timestamp ISO 8601 de última actualización
400
+ * @property status - Estado actual de la conexión
401
+ */
402
+ type OAuthConnection = {
403
+ id: string;
404
+ providerId: string;
405
+ projectId: string;
406
+ tenantId?: string;
407
+ userId: string;
408
+ scope: string[];
409
+ expiresAt?: string;
410
+ createdAt: string;
411
+ updatedAt: string;
412
+ status: 'active' | 'refreshing' | 'revoked' | 'expired';
413
+ };
414
+ /**
415
+ * Conjunto de tokens OAuth obtenidos de un proveedor.
416
+ *
417
+ * @property accessToken - Token de acceso para autenticación
418
+ * @property refreshToken - Token para refrescar el access token (opcional)
419
+ * @property expiresIn - Tiempo de expiración en segundos (opcional)
420
+ * @property tokenType - Tipo de token (generalmente 'Bearer')
421
+ * @property issuedAt - Timestamp ISO 8601 de emisión
422
+ * @property expiresAt - Timestamp ISO 8601 de expiración calculado
423
+ * @property idToken - ID Token para OIDC (opcional)
424
+ */
425
+ type TokenSet = {
426
+ accessToken: string;
427
+ refreshToken?: string;
428
+ expiresIn?: number;
429
+ tokenType?: string;
430
+ issuedAt: string;
431
+ expiresAt?: string;
432
+ idToken?: string;
433
+ };
434
+ /**
435
+ * Type guard para verificar si una conexión está activa.
436
+ *
437
+ * @param connection - Conexión a verificar
438
+ * @returns true si el estado es 'active'
439
+ */
440
+ declare function isActiveConnection(connection: OAuthConnection): boolean;
441
+ /**
442
+ * Type guard para verificar si una conexión está revocada.
443
+ *
444
+ * @param connection - Conexión a verificar
445
+ * @returns true si el estado es 'revoked'
446
+ */
447
+ declare function isRevokedConnection(connection: OAuthConnection): boolean;
448
+ /**
449
+ * Type guard para verificar si una conexión está expirada.
450
+ *
451
+ * @param connection - Conexión a verificar
452
+ * @returns true si el estado es 'expired' o si expiresAt está en el pasado
453
+ */
454
+ declare function isExpiredConnection(connection: OAuthConnection): boolean;
455
+ type ConnectionLinkedPayload = {
456
+ connection: OAuthConnection;
457
+ tokenSet: TokenSet;
458
+ };
459
+ type TokenRefreshedPayload = {
460
+ connectionId: string;
461
+ tokenSet: TokenSet;
462
+ };
463
+ type ConnectionRevokedPayload = {
464
+ connectionId: string;
465
+ reason: 'user' | 'provider' | 'security';
466
+ };
467
+ /**
468
+ * Contratos de eventos para el sistema de conexiones OAuth.
469
+ * Define los eventos que se emiten durante el ciclo de vida de una conexión OAuth.
470
+ */
471
+ declare const oauthConnectionEvents: Record<'linked' | 'tokenRefreshed' | 'revoked', EventContract<ConnectionLinkedPayload | TokenRefreshedPayload | ConnectionRevokedPayload>>;
472
+ /**
473
+ * Unión de todos los tipos de eventos de conexiones OAuth.
474
+ */
475
+ type OAuthConnectionEvent = EventEnvelope<ConnectionLinkedPayload> | EventEnvelope<TokenRefreshedPayload> | EventEnvelope<ConnectionRevokedPayload>;
476
+
477
+ /**
478
+ * Utilidades de validación para formatos comunes utilizados en los contratos.
479
+ */
480
+ /**
481
+ * Valida si una cadena tiene formato UUID v4.
482
+ *
483
+ * @param value - Cadena a validar
484
+ * @returns true si es un UUID v4 válido
485
+ *
486
+ * @example
487
+ * ```typescript
488
+ * isValidUuid('550e8400-e29b-41d4-a716-446655440000'); // true
489
+ * isValidUuid('invalid'); // false
490
+ * ```
491
+ */
492
+ declare function isValidUuid(value: string): boolean;
493
+ /**
494
+ * Valida si una cadena tiene formato de email básico.
495
+ *
496
+ * @param value - Cadena a validar
497
+ * @returns true si tiene formato de email válido
498
+ *
499
+ * @example
500
+ * ```typescript
501
+ * isValidEmail('user@example.com'); // true
502
+ * isValidEmail('invalid'); // false
503
+ * ```
504
+ */
505
+ declare function isValidEmail(value: string): boolean;
506
+ /**
507
+ * Valida si una cadena tiene formato de URL válido.
508
+ *
509
+ * @param value - Cadena a validar
510
+ * @returns true si es una URL válida
511
+ *
512
+ * @example
513
+ * ```typescript
514
+ * isValidUrl('https://example.com'); // true
515
+ * isValidUrl('not-a-url'); // false
516
+ * ```
517
+ */
518
+ declare function isValidUrl(value: string): boolean;
519
+ /**
520
+ * Valida si una cadena tiene formato de teléfono E.164.
521
+ *
522
+ * @param value - Cadena a validar
523
+ * @returns true si tiene formato E.164 válido
524
+ *
525
+ * @example
526
+ * ```typescript
527
+ * isValidE164Phone('+1234567890'); // true
528
+ * isValidE164Phone('1234567890'); // false
529
+ * ```
530
+ */
531
+ declare function isValidE164Phone(value: string): boolean;
532
+ /**
533
+ * Valida si una cadena es un timestamp ISO 8601 válido.
534
+ *
535
+ * @param value - Cadena a validar
536
+ * @returns true si es un timestamp ISO 8601 válido
537
+ *
538
+ * @example
539
+ * ```typescript
540
+ * isValidIso8601('2024-01-01T00:00:00.000Z'); // true
541
+ * isValidIso8601('invalid'); // false
542
+ * ```
543
+ */
544
+ declare function isValidIso8601(value: string): boolean;
545
+ /**
546
+ * Valida si un objeto tiene todas las propiedades requeridas.
547
+ *
548
+ * @param obj - Objeto a validar
549
+ * @param requiredKeys - Array de claves requeridas
550
+ * @returns true si todas las claves están presentes
551
+ *
552
+ * @example
553
+ * ```typescript
554
+ * hasRequiredKeys({ a: 1, b: 2 }, ['a', 'b']); // true
555
+ * hasRequiredKeys({ a: 1 }, ['a', 'b']); // false
556
+ * ```
557
+ */
558
+ declare function hasRequiredKeys<T extends Record<string, unknown>>(obj: T, requiredKeys: (keyof T)[]): boolean;
559
+
560
+ /**
561
+ * Esquemas de validación en runtime usando Zod.
562
+ * Estos esquemas permiten validar datos en tiempo de ejecución,
563
+ * no solo en tiempo de compilación con TypeScript.
564
+ *
565
+ * Nota: Requiere instalar zod como dependencia.
566
+ */
567
+
568
+ /**
569
+ * Esquema para validar versiones semánticas.
570
+ */
571
+ declare const semanticVersionSchema: z.ZodEffects<z.ZodString, `${number}.${number}.${number}`, string>;
572
+ /**
573
+ * Esquema para validar metadata de eventos.
574
+ */
575
+ declare const eventMetaSchema: z.ZodObject<{
576
+ traceId: z.ZodOptional<z.ZodString>;
577
+ spanId: z.ZodOptional<z.ZodString>;
578
+ correlationId: z.ZodOptional<z.ZodString>;
579
+ causationId: z.ZodOptional<z.ZodString>;
580
+ tenantId: z.ZodOptional<z.ZodString>;
581
+ projectId: z.ZodOptional<z.ZodString>;
582
+ source: z.ZodString;
583
+ }, "strip", z.ZodTypeAny, {
584
+ source: string;
585
+ traceId?: string | undefined;
586
+ spanId?: string | undefined;
587
+ correlationId?: string | undefined;
588
+ causationId?: string | undefined;
589
+ tenantId?: string | undefined;
590
+ projectId?: string | undefined;
591
+ }, {
592
+ source: string;
593
+ traceId?: string | undefined;
594
+ spanId?: string | undefined;
595
+ correlationId?: string | undefined;
596
+ causationId?: string | undefined;
597
+ tenantId?: string | undefined;
598
+ projectId?: string | undefined;
599
+ }>;
600
+ /**
601
+ * Esquema genérico para validar envelopes de eventos.
602
+ *
603
+ * @template TPayload - Tipo del payload (debe ser un esquema Zod)
604
+ */
605
+ declare function createEventEnvelopeSchema<TPayload extends z.ZodTypeAny>(payloadSchema: TPayload): z.ZodObject<{
606
+ id: z.ZodString;
607
+ type: z.ZodString;
608
+ version: typeof semanticVersionSchema;
609
+ occurredAt: z.ZodString;
610
+ payload: TPayload;
611
+ meta: typeof eventMetaSchema;
612
+ }>;
613
+ /**
614
+ * Esquema para validar solicitudes de notificación por email.
615
+ */
616
+ declare const emailNotificationRequestSchema: z.ZodObject<{
617
+ channel: z.ZodLiteral<"email">;
618
+ projectId: z.ZodString;
619
+ tenantId: z.ZodOptional<z.ZodString>;
620
+ locale: z.ZodOptional<z.ZodString>;
621
+ deduplicationKey: z.ZodOptional<z.ZodString>;
622
+ expiresAt: z.ZodOptional<z.ZodString>;
623
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
624
+ to: z.ZodString;
625
+ templateId: z.ZodString;
626
+ variables: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>>;
627
+ cc: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
628
+ bcc: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
629
+ replyTo: z.ZodOptional<z.ZodString>;
630
+ }, "strip", z.ZodTypeAny, {
631
+ to: string;
632
+ templateId: string;
633
+ channel: "email";
634
+ projectId: string;
635
+ variables?: Record<string, string | number | boolean | null> | undefined;
636
+ cc?: string[] | undefined;
637
+ bcc?: string[] | undefined;
638
+ replyTo?: string | undefined;
639
+ tenantId?: string | undefined;
640
+ locale?: string | undefined;
641
+ deduplicationKey?: string | undefined;
642
+ expiresAt?: string | undefined;
643
+ metadata?: Record<string, string> | undefined;
644
+ }, {
645
+ to: string;
646
+ templateId: string;
647
+ channel: "email";
648
+ projectId: string;
649
+ variables?: Record<string, string | number | boolean | null> | undefined;
650
+ cc?: string[] | undefined;
651
+ bcc?: string[] | undefined;
652
+ replyTo?: string | undefined;
653
+ tenantId?: string | undefined;
654
+ locale?: string | undefined;
655
+ deduplicationKey?: string | undefined;
656
+ expiresAt?: string | undefined;
657
+ metadata?: Record<string, string> | undefined;
658
+ }>;
659
+ /**
660
+ * Esquema para validar solicitudes de notificación por SMS.
661
+ */
662
+ declare const smsNotificationRequestSchema: z.ZodObject<{
663
+ channel: z.ZodLiteral<"sms">;
664
+ projectId: z.ZodString;
665
+ tenantId: z.ZodOptional<z.ZodString>;
666
+ locale: z.ZodOptional<z.ZodString>;
667
+ deduplicationKey: z.ZodOptional<z.ZodString>;
668
+ expiresAt: z.ZodOptional<z.ZodString>;
669
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
670
+ to: z.ZodString;
671
+ templateId: z.ZodString;
672
+ variables: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>>;
673
+ }, "strip", z.ZodTypeAny, {
674
+ to: string;
675
+ templateId: string;
676
+ channel: "sms";
677
+ projectId: string;
678
+ variables?: Record<string, string | number | boolean | null> | undefined;
679
+ tenantId?: string | undefined;
680
+ locale?: string | undefined;
681
+ deduplicationKey?: string | undefined;
682
+ expiresAt?: string | undefined;
683
+ metadata?: Record<string, string> | undefined;
684
+ }, {
685
+ to: string;
686
+ templateId: string;
687
+ channel: "sms";
688
+ projectId: string;
689
+ variables?: Record<string, string | number | boolean | null> | undefined;
690
+ tenantId?: string | undefined;
691
+ locale?: string | undefined;
692
+ deduplicationKey?: string | undefined;
693
+ expiresAt?: string | undefined;
694
+ metadata?: Record<string, string> | undefined;
695
+ }>;
696
+ /**
697
+ * Esquema para validar solicitudes de notificación por webhook.
698
+ */
699
+ declare const webhookNotificationRequestSchema: z.ZodObject<{
700
+ channel: z.ZodLiteral<"webhook">;
701
+ projectId: z.ZodString;
702
+ tenantId: z.ZodOptional<z.ZodString>;
703
+ locale: z.ZodOptional<z.ZodString>;
704
+ deduplicationKey: z.ZodOptional<z.ZodString>;
705
+ expiresAt: z.ZodOptional<z.ZodString>;
706
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
707
+ url: z.ZodString;
708
+ signatureVersion: z.ZodEffects<z.ZodString, `${number}.${number}.${number}`, string>;
709
+ body: z.ZodUnknown;
710
+ }, "strip", z.ZodTypeAny, {
711
+ channel: "webhook";
712
+ projectId: string;
713
+ url: string;
714
+ signatureVersion: `${number}.${number}.${number}`;
715
+ tenantId?: string | undefined;
716
+ locale?: string | undefined;
717
+ deduplicationKey?: string | undefined;
718
+ expiresAt?: string | undefined;
719
+ metadata?: Record<string, string> | undefined;
720
+ body?: unknown;
721
+ }, {
722
+ channel: "webhook";
723
+ projectId: string;
724
+ url: string;
725
+ signatureVersion: string;
726
+ tenantId?: string | undefined;
727
+ locale?: string | undefined;
728
+ deduplicationKey?: string | undefined;
729
+ expiresAt?: string | undefined;
730
+ metadata?: Record<string, string> | undefined;
731
+ body?: unknown;
732
+ }>;
733
+ /**
734
+ * Esquema para validar cualquier solicitud de notificación.
735
+ */
736
+ declare const notificationRequestSchema: z.ZodDiscriminatedUnion<"channel", [z.ZodObject<{
737
+ channel: z.ZodLiteral<"email">;
738
+ projectId: z.ZodString;
739
+ tenantId: z.ZodOptional<z.ZodString>;
740
+ locale: z.ZodOptional<z.ZodString>;
741
+ deduplicationKey: z.ZodOptional<z.ZodString>;
742
+ expiresAt: z.ZodOptional<z.ZodString>;
743
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
744
+ to: z.ZodString;
745
+ templateId: z.ZodString;
746
+ variables: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>>;
747
+ cc: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
748
+ bcc: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
749
+ replyTo: z.ZodOptional<z.ZodString>;
750
+ }, "strip", z.ZodTypeAny, {
751
+ to: string;
752
+ templateId: string;
753
+ channel: "email";
754
+ projectId: string;
755
+ variables?: Record<string, string | number | boolean | null> | undefined;
756
+ cc?: string[] | undefined;
757
+ bcc?: string[] | undefined;
758
+ replyTo?: string | undefined;
759
+ tenantId?: string | undefined;
760
+ locale?: string | undefined;
761
+ deduplicationKey?: string | undefined;
762
+ expiresAt?: string | undefined;
763
+ metadata?: Record<string, string> | undefined;
764
+ }, {
765
+ to: string;
766
+ templateId: string;
767
+ channel: "email";
768
+ projectId: string;
769
+ variables?: Record<string, string | number | boolean | null> | undefined;
770
+ cc?: string[] | undefined;
771
+ bcc?: string[] | undefined;
772
+ replyTo?: string | undefined;
773
+ tenantId?: string | undefined;
774
+ locale?: string | undefined;
775
+ deduplicationKey?: string | undefined;
776
+ expiresAt?: string | undefined;
777
+ metadata?: Record<string, string> | undefined;
778
+ }>, z.ZodObject<{
779
+ channel: z.ZodLiteral<"sms">;
780
+ projectId: z.ZodString;
781
+ tenantId: z.ZodOptional<z.ZodString>;
782
+ locale: z.ZodOptional<z.ZodString>;
783
+ deduplicationKey: z.ZodOptional<z.ZodString>;
784
+ expiresAt: z.ZodOptional<z.ZodString>;
785
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
786
+ to: z.ZodString;
787
+ templateId: z.ZodString;
788
+ variables: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>>;
789
+ }, "strip", z.ZodTypeAny, {
790
+ to: string;
791
+ templateId: string;
792
+ channel: "sms";
793
+ projectId: string;
794
+ variables?: Record<string, string | number | boolean | null> | undefined;
795
+ tenantId?: string | undefined;
796
+ locale?: string | undefined;
797
+ deduplicationKey?: string | undefined;
798
+ expiresAt?: string | undefined;
799
+ metadata?: Record<string, string> | undefined;
800
+ }, {
801
+ to: string;
802
+ templateId: string;
803
+ channel: "sms";
804
+ projectId: string;
805
+ variables?: Record<string, string | number | boolean | null> | undefined;
806
+ tenantId?: string | undefined;
807
+ locale?: string | undefined;
808
+ deduplicationKey?: string | undefined;
809
+ expiresAt?: string | undefined;
810
+ metadata?: Record<string, string> | undefined;
811
+ }>, z.ZodObject<{
812
+ channel: z.ZodLiteral<"webhook">;
813
+ projectId: z.ZodString;
814
+ tenantId: z.ZodOptional<z.ZodString>;
815
+ locale: z.ZodOptional<z.ZodString>;
816
+ deduplicationKey: z.ZodOptional<z.ZodString>;
817
+ expiresAt: z.ZodOptional<z.ZodString>;
818
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
819
+ url: z.ZodString;
820
+ signatureVersion: z.ZodEffects<z.ZodString, `${number}.${number}.${number}`, string>;
821
+ body: z.ZodUnknown;
822
+ }, "strip", z.ZodTypeAny, {
823
+ channel: "webhook";
824
+ projectId: string;
825
+ url: string;
826
+ signatureVersion: `${number}.${number}.${number}`;
827
+ tenantId?: string | undefined;
828
+ locale?: string | undefined;
829
+ deduplicationKey?: string | undefined;
830
+ expiresAt?: string | undefined;
831
+ metadata?: Record<string, string> | undefined;
832
+ body?: unknown;
833
+ }, {
834
+ channel: "webhook";
835
+ projectId: string;
836
+ url: string;
837
+ signatureVersion: string;
838
+ tenantId?: string | undefined;
839
+ locale?: string | undefined;
840
+ deduplicationKey?: string | undefined;
841
+ expiresAt?: string | undefined;
842
+ metadata?: Record<string, string> | undefined;
843
+ body?: unknown;
844
+ }>]>;
845
+ /**
846
+ * Esquema para validar conexiones OAuth.
847
+ */
848
+ declare const oauthConnectionSchema: z.ZodObject<{
849
+ id: z.ZodString;
850
+ providerId: z.ZodString;
851
+ projectId: z.ZodString;
852
+ tenantId: z.ZodOptional<z.ZodString>;
853
+ userId: z.ZodString;
854
+ scope: z.ZodArray<z.ZodString, "many">;
855
+ expiresAt: z.ZodOptional<z.ZodString>;
856
+ createdAt: z.ZodString;
857
+ updatedAt: z.ZodString;
858
+ status: z.ZodEnum<["active", "refreshing", "revoked", "expired"]>;
859
+ }, "strip", z.ZodTypeAny, {
860
+ projectId: string;
861
+ status: "active" | "refreshing" | "revoked" | "expired";
862
+ id: string;
863
+ providerId: string;
864
+ userId: string;
865
+ scope: string[];
866
+ createdAt: string;
867
+ updatedAt: string;
868
+ tenantId?: string | undefined;
869
+ expiresAt?: string | undefined;
870
+ }, {
871
+ projectId: string;
872
+ status: "active" | "refreshing" | "revoked" | "expired";
873
+ id: string;
874
+ providerId: string;
875
+ userId: string;
876
+ scope: string[];
877
+ createdAt: string;
878
+ updatedAt: string;
879
+ tenantId?: string | undefined;
880
+ expiresAt?: string | undefined;
881
+ }>;
882
+ /**
883
+ * Esquema para validar conjuntos de tokens OAuth.
884
+ */
885
+ declare const tokenSetSchema: z.ZodObject<{
886
+ accessToken: z.ZodString;
887
+ refreshToken: z.ZodOptional<z.ZodString>;
888
+ expiresIn: z.ZodOptional<z.ZodNumber>;
889
+ tokenType: z.ZodOptional<z.ZodString>;
890
+ issuedAt: z.ZodString;
891
+ expiresAt: z.ZodOptional<z.ZodString>;
892
+ idToken: z.ZodOptional<z.ZodString>;
893
+ }, "strip", z.ZodTypeAny, {
894
+ accessToken: string;
895
+ issuedAt: string;
896
+ expiresAt?: string | undefined;
897
+ refreshToken?: string | undefined;
898
+ expiresIn?: number | undefined;
899
+ tokenType?: string | undefined;
900
+ idToken?: string | undefined;
901
+ }, {
902
+ accessToken: string;
903
+ issuedAt: string;
904
+ expiresAt?: string | undefined;
905
+ refreshToken?: string | undefined;
906
+ expiresIn?: number | undefined;
907
+ tokenType?: string | undefined;
908
+ idToken?: string | undefined;
909
+ }>;
910
+
911
+ export { type BaseNotificationRequest, type EmailNotificationRequest, type EventContract, type EventEnvelope, type EventMeta, NOTIFICATION_EVENT_TYPES, type NotificationChannel, type NotificationEnvelope, type NotificationEvent, type NotificationRequest, type NotificationStatus, OAUTH_CONNECTION_EVENT_TYPES, type OAuthConnection, type OAuthConnectionEvent, type OAuthProvider, type OAuthProviderCategory, type SemanticVersion, type SmsNotificationRequest, type TokenSet, type Versioned, type WebhookNotificationRequest, compareSemanticVersions, createEventEnvelopeSchema, emailNotificationRequestSchema, eventMetaSchema, hasRequiredKeys, isActiveConnection, isEmailNotificationRequest, isExpiredConnection, isRevokedConnection, isSmsNotificationRequest, isValidE164Phone, isValidEmail, isValidIso8601, isValidSemanticVersion, isValidUrl, isValidUuid, isVersionGreaterOrEqual, isVersionGreaterThan, isVersionLessOrEqual, isVersionLessThan, isWebhookNotificationRequest, notificationEvents, notificationRequestSchema, oauthConnectionEvents, oauthConnectionSchema, parseSemanticVersion, semanticVersionSchema, smsNotificationRequestSchema, tokenSetSchema, webhookNotificationRequestSchema };