@lynkoria/contracts 0.0.0-stage → 0.1.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.
@@ -0,0 +1,732 @@
1
+ import { z } from "zod";
2
+ // src/schemas.ts
3
+ /**
4
+ * Opaque product identifiers (user, device, tenant, product call/conversation ids).
5
+ * Colons are excluded because Lynkoria builds namespaced identities with `:` separators.
6
+ */
7
+ const ProductId = z.string().regex(/^[A-Za-z0-9._@-]{1,128}$/, "must be 1-128 chars of [A-Za-z0-9._@-]");
8
+ const Uuid = z.uuid();
9
+ const TenantId = ProductId.default("default");
10
+ const ProjectFeatures = z.object({
11
+ calls: z.boolean().default(true),
12
+ livestream: z.boolean().default(false),
13
+ messaging: z.boolean().default(false),
14
+ presence: z.boolean().default(false),
15
+ attachments: z.boolean().default(false),
16
+ /** ADR 006: when true, a new device's join token removes the user's other devices from the room. */
17
+ singleDeviceCalls: z.boolean().default(false),
18
+ /** Device registration and push delivery (FCM/APNs). Needs a push credential reference. */
19
+ push: z.boolean().default(false),
20
+ /** Server-side recording/streaming through LiveKit Egress. Never available for E2EE calls. */
21
+ recording: z.boolean().default(false)
22
+ });
23
+ const ProjectLimits = z.object({
24
+ maxRoomSize: z.number().int().min(2).max(1e3).default(50),
25
+ maxConcurrentRooms: z.number().int().min(1).max(1e5).default(100),
26
+ tokensPerMinute: z.number().int().min(1).max(1e5).default(600)
27
+ });
28
+ /** Per project environment messaging policy (plan §9.7). */
29
+ const ProductMessagingPolicy = z.object({
30
+ allowDms: z.boolean().default(true),
31
+ allowGroups: z.boolean().default(true),
32
+ allowAttachments: z.boolean().default(false),
33
+ allowThreads: z.boolean().default(false),
34
+ allowReactions: z.boolean().default(true),
35
+ maxAttachmentBytes: z.number().int().min(1).max(5 * 1024 ** 3).default(25 * 1024 ** 2),
36
+ allowedAttachmentTypes: z.array(z.string().regex(/^[a-z]+\/[a-z0-9.+*-]+$/i)).max(50).default([
37
+ "image/*",
38
+ "video/mp4",
39
+ "application/pdf"
40
+ ]),
41
+ retentionDays: z.number().int().min(1).max(36500).nullable().default(null)
42
+ });
43
+ const CallType = z.enum([
44
+ "one_to_one",
45
+ "group",
46
+ "livestream"
47
+ ]);
48
+ const CallStatus = z.enum(["active", "ended"]);
49
+ const ParticipantRole = z.enum([
50
+ "host",
51
+ "speaker",
52
+ "viewer",
53
+ "participant"
54
+ ]);
55
+ const CreateCallRequest = z.object({
56
+ productCallId: ProductId,
57
+ tenantId: TenantId,
58
+ type: CallType.default("group"),
59
+ maxParticipants: z.number().int().min(2).max(1e3).optional(),
60
+ emptyTimeoutSec: z.number().int().min(10).max(3600).default(300),
61
+ departureTimeoutSec: z.number().int().min(0).max(3600).default(20),
62
+ /**
63
+ * Clients will encrypt media end to end with a key the server never sees. Lynkoria records the
64
+ * flag and refuses server-side recording/streaming for the call; it does not distribute keys.
65
+ */
66
+ e2ee: z.boolean().default(false)
67
+ });
68
+ const Call = z.object({
69
+ id: Uuid,
70
+ productCallId: z.string(),
71
+ tenantId: z.string(),
72
+ type: CallType,
73
+ roomName: z.string(),
74
+ status: CallStatus,
75
+ maxParticipants: z.number().int(),
76
+ e2ee: z.boolean(),
77
+ createdAt: z.string(),
78
+ endedAt: z.string().nullable()
79
+ });
80
+ const JoinTokenRequest = z.object({
81
+ userId: ProductId,
82
+ deviceId: ProductId,
83
+ displayName: z.string().trim().min(1).max(128),
84
+ role: ParticipantRole.default("participant")
85
+ });
86
+ const JoinTokenResponse = z.object({
87
+ url: z.string(),
88
+ token: z.string(),
89
+ identity: z.string(),
90
+ expiresAt: z.string()
91
+ });
92
+ const UpdatePermissionsRequest = z.object({ role: z.enum([
93
+ "host",
94
+ "speaker",
95
+ "viewer",
96
+ "participant"
97
+ ]) });
98
+ const CallSignalType = z.enum([
99
+ "invited",
100
+ "ringing",
101
+ "accepted",
102
+ "declined",
103
+ "ended"
104
+ ]);
105
+ /** Incoming-call signaling to foreground devices (plan §14.4). Push for background devices stays product-owned. */
106
+ const CallSignalRequest = z.object({
107
+ type: CallSignalType,
108
+ toUserIds: z.array(ProductId).min(1).max(1e3),
109
+ fromUserId: ProductId.optional(),
110
+ data: z.record(z.string(), z.unknown()).optional()
111
+ });
112
+ const MessagingTokenRequest = z.object({
113
+ userId: ProductId,
114
+ deviceId: ProductId,
115
+ tenantId: TenantId
116
+ });
117
+ const MessagingTokenResponse = z.object({
118
+ token: z.string(),
119
+ expiresAt: z.string()
120
+ });
121
+ const ConversationType = z.enum([
122
+ "dm",
123
+ "group",
124
+ "channel",
125
+ "session"
126
+ ]);
127
+ const CreateConversationRequest = z.object({
128
+ tenantId: TenantId,
129
+ type: ConversationType,
130
+ productConversationId: ProductId.optional(),
131
+ title: z.string().trim().max(200).optional(),
132
+ memberIds: z.array(ProductId).min(1).max(1e3)
133
+ });
134
+ const MembersRequest = z.object({ userIds: z.array(ProductId).min(1).max(1e3) });
135
+ const Conversation = z.object({
136
+ id: Uuid,
137
+ tenantId: z.string(),
138
+ type: ConversationType,
139
+ productConversationId: z.string().nullable(),
140
+ title: z.string().nullable(),
141
+ lastSeq: z.number().int(),
142
+ lastMessageAt: z.string().nullable(),
143
+ createdAt: z.string(),
144
+ readSeq: z.number().int().optional()
145
+ });
146
+ const ConversationList = z.object({
147
+ items: z.array(Conversation),
148
+ nextCursor: z.string().nullable()
149
+ });
150
+ const AttachmentStatus = z.enum([
151
+ "pending",
152
+ "ready",
153
+ "rejected"
154
+ ]);
155
+ /** Malware-scan state. When scanning is enabled a file is `ready` only after a `clean` verdict. */
156
+ const AttachmentScanStatus = z.enum([
157
+ "not_scanned",
158
+ "pending",
159
+ "clean",
160
+ "infected",
161
+ "rejected",
162
+ "failed"
163
+ ]);
164
+ const Attachment = z.object({
165
+ id: Uuid,
166
+ fileName: z.string(),
167
+ mediaType: z.string(),
168
+ size: z.number().int(),
169
+ status: AttachmentStatus,
170
+ scanStatus: AttachmentScanStatus.optional()
171
+ });
172
+ const SendMessageRequest = z.object({
173
+ clientMessageId: z.string().regex(/^[A-Za-z0-9_-]{8,64}$/),
174
+ text: z.string().max(65536).default(""),
175
+ attachmentIds: z.array(Uuid).max(10).default([]),
176
+ parentMessageId: Uuid.optional()
177
+ });
178
+ const EditMessageRequest = z.object({ text: z.string().min(1).max(65536) });
179
+ const ReadRequest = z.object({ seq: z.number().int().min(0) });
180
+ const ReactionRequest = z.object({ emoji: z.string().min(1).max(32) });
181
+ const Reaction = z.object({
182
+ userId: z.string(),
183
+ emoji: z.string()
184
+ });
185
+ const Message = z.object({
186
+ id: Uuid,
187
+ conversationId: Uuid,
188
+ seq: z.number().int(),
189
+ senderId: z.string(),
190
+ clientMessageId: z.string(),
191
+ kind: z.enum(["text", "system"]),
192
+ body: z.string().nullable(),
193
+ attachments: z.array(Attachment),
194
+ reactions: z.array(Reaction),
195
+ parentMessageId: z.string().nullable(),
196
+ createdAt: z.string(),
197
+ editedAt: z.string().nullable(),
198
+ deletedAt: z.string().nullable()
199
+ });
200
+ const ConversationEventType = z.enum([
201
+ "message.created",
202
+ "message.updated",
203
+ "message.deleted",
204
+ "reaction.added",
205
+ "reaction.removed"
206
+ ]);
207
+ /**
208
+ * Every change to a conversation allocates the next conversation sequence number.
209
+ * Clients track the last seq they applied and resync with `after_seq` on gaps or reconnect.
210
+ */
211
+ const ConversationEvent = z.object({
212
+ conversationId: Uuid,
213
+ seq: z.number().int(),
214
+ type: ConversationEventType,
215
+ message: Message,
216
+ reaction: Reaction.nullable(),
217
+ createdAt: z.string()
218
+ });
219
+ const ConversationEventPage = z.object({
220
+ items: z.array(ConversationEvent),
221
+ lastSeq: z.number().int(),
222
+ hasMore: z.boolean()
223
+ });
224
+ const SendMessageResponse = z.object({
225
+ message: Message,
226
+ created: z.boolean(),
227
+ status: z.literal("sent")
228
+ });
229
+ const UploadIntentRequest = z.object({
230
+ conversationId: Uuid,
231
+ fileName: z.string().trim().min(1).max(255),
232
+ size: z.number().int().min(1),
233
+ mediaType: z.string().regex(/^[a-z]+\/[a-z0-9.+-]+$/i)
234
+ });
235
+ const UploadIntentResponse = z.object({
236
+ attachment: Attachment,
237
+ uploadUrl: z.string(),
238
+ headers: z.record(z.string(), z.string()),
239
+ expiresAt: z.string()
240
+ });
241
+ const DownloadUrlResponse = z.object({
242
+ url: z.string(),
243
+ expiresAt: z.string()
244
+ });
245
+ const ConnectivityStatus = z.enum(["online", "offline"]);
246
+ const ManualStatus = z.enum([
247
+ "available",
248
+ "away",
249
+ "dnd",
250
+ "busy",
251
+ "invisible"
252
+ ]);
253
+ const PresenceStatus = z.enum([
254
+ "online",
255
+ "offline",
256
+ "away",
257
+ "dnd",
258
+ "busy"
259
+ ]);
260
+ const Presence = z.object({
261
+ userId: z.string(),
262
+ status: PresenceStatus,
263
+ lastSeenAt: z.string().nullable()
264
+ });
265
+ const ConsoleRole = z.enum([
266
+ "owner",
267
+ "admin",
268
+ "developer",
269
+ "auditor"
270
+ ]);
271
+ const EnvironmentName = z.enum(["staging", "production"]);
272
+ const ServiceScope = z.enum([
273
+ "calls:write",
274
+ "messaging:write",
275
+ "users:write"
276
+ ]);
277
+ const Origin = z.url({ protocol: /^https?$/ }).refine((v) => new URL(v).origin === v, "must be a bare origin");
278
+ const CreateProjectRequest = z.object({
279
+ slug: z.string().regex(/^[a-z][a-z0-9-]{1,30}$/),
280
+ name: z.string().trim().min(1).max(100)
281
+ });
282
+ const PatchProjectRequest = z.object({
283
+ name: z.string().trim().min(1).max(100).optional(),
284
+ status: z.enum(["active", "disabled"]).optional()
285
+ }).refine((v) => Object.keys(v).length > 0, "At least one field is required");
286
+ const CreateEnvironmentRequest = z.object({
287
+ environment: EnvironmentName,
288
+ allowedOrigins: z.array(Origin).max(50).default([]),
289
+ webhookUrl: z.url({ protocol: /^https?$/ }).nullable().default(null),
290
+ livekitKeyRef: z.string().min(1).max(100),
291
+ /** Key into the server's PUSH_CREDENTIALS_JSON; provider secrets never pass through the API. */
292
+ pushCredentialRef: z.string().min(1).max(100).nullable().default(null),
293
+ features: ProjectFeatures.prefault({}),
294
+ limits: ProjectLimits.prefault({}),
295
+ messagingPolicy: ProductMessagingPolicy.prefault({})
296
+ });
297
+ const PatchEnvironmentRequest = z.object({
298
+ status: z.enum(["active", "disabled"]).optional(),
299
+ allowedOrigins: z.array(Origin).max(50).optional(),
300
+ webhookUrl: z.url({ protocol: /^https?$/ }).nullable().optional(),
301
+ livekitKeyRef: z.string().min(1).max(100).optional(),
302
+ pushCredentialRef: z.string().min(1).max(100).nullable().optional(),
303
+ features: z.object({
304
+ calls: ProjectFeatures.shape.calls.removeDefault().optional(),
305
+ livestream: ProjectFeatures.shape.livestream.removeDefault().optional(),
306
+ messaging: ProjectFeatures.shape.messaging.removeDefault().optional(),
307
+ presence: ProjectFeatures.shape.presence.removeDefault().optional(),
308
+ attachments: ProjectFeatures.shape.attachments.removeDefault().optional(),
309
+ singleDeviceCalls: ProjectFeatures.shape.singleDeviceCalls.removeDefault().optional(),
310
+ push: ProjectFeatures.shape.push.removeDefault().optional(),
311
+ recording: ProjectFeatures.shape.recording.removeDefault().optional()
312
+ }).optional(),
313
+ limits: z.object({
314
+ maxRoomSize: ProjectLimits.shape.maxRoomSize.removeDefault().optional(),
315
+ maxConcurrentRooms: ProjectLimits.shape.maxConcurrentRooms.removeDefault().optional(),
316
+ tokensPerMinute: ProjectLimits.shape.tokensPerMinute.removeDefault().optional()
317
+ }).optional(),
318
+ messagingPolicy: z.object({
319
+ allowDms: ProductMessagingPolicy.shape.allowDms.removeDefault().optional(),
320
+ allowGroups: ProductMessagingPolicy.shape.allowGroups.removeDefault().optional(),
321
+ allowAttachments: ProductMessagingPolicy.shape.allowAttachments.removeDefault().optional(),
322
+ allowThreads: ProductMessagingPolicy.shape.allowThreads.removeDefault().optional(),
323
+ allowReactions: ProductMessagingPolicy.shape.allowReactions.removeDefault().optional(),
324
+ maxAttachmentBytes: ProductMessagingPolicy.shape.maxAttachmentBytes.removeDefault().optional(),
325
+ allowedAttachmentTypes: ProductMessagingPolicy.shape.allowedAttachmentTypes.removeDefault().optional(),
326
+ retentionDays: ProductMessagingPolicy.shape.retentionDays.removeDefault().optional()
327
+ }).optional()
328
+ });
329
+ const CreateKeyRequest = z.object({
330
+ environmentId: Uuid,
331
+ displayName: z.string().trim().min(1).max(100),
332
+ scopes: z.array(ServiceScope).min(1).default([
333
+ "calls:write",
334
+ "messaging:write",
335
+ "users:write"
336
+ ]),
337
+ expiresAt: z.iso.datetime().nullable().default(null)
338
+ });
339
+ const GrantRoleRequest = z.object({
340
+ email: z.email().transform((v) => v.toLowerCase()),
341
+ role: ConsoleRole,
342
+ projectId: Uuid.nullable().default(null)
343
+ });
344
+ const UsageQuery = z.object({
345
+ env: Uuid.optional(),
346
+ from: z.iso.date().optional(),
347
+ to: z.iso.date().optional()
348
+ });
349
+ const Environment = z.object({
350
+ id: Uuid,
351
+ projectId: Uuid,
352
+ environment: EnvironmentName,
353
+ status: z.enum(["active", "disabled"]),
354
+ allowedOrigins: z.array(z.string()),
355
+ webhookUrl: z.string().nullable(),
356
+ webhookSecretConfigured: z.boolean(),
357
+ livekitKeyRef: z.string(),
358
+ pushCredentialRef: z.string().nullable(),
359
+ features: ProjectFeatures,
360
+ limits: ProjectLimits,
361
+ messagingPolicy: ProductMessagingPolicy,
362
+ createdAt: z.string(),
363
+ updatedAt: z.string()
364
+ });
365
+ const Project = z.object({
366
+ id: Uuid,
367
+ slug: z.string(),
368
+ name: z.string(),
369
+ status: z.enum(["active", "disabled"]),
370
+ createdAt: z.string(),
371
+ environments: z.array(Environment)
372
+ });
373
+ /** Service key metadata. The secret itself is never returned after creation. */
374
+ const ServiceKey = z.object({
375
+ id: z.string(),
376
+ environmentId: Uuid,
377
+ mode: z.enum(["live", "test"]),
378
+ displayName: z.string(),
379
+ prefix: z.string(),
380
+ suffix: z.string(),
381
+ scopes: z.array(z.string()),
382
+ expiresAt: z.string().nullable(),
383
+ revokedAt: z.string().nullable(),
384
+ lastUsedAt: z.string().nullable(),
385
+ createdBy: z.string(),
386
+ createdAt: z.string()
387
+ });
388
+ const CreatedServiceKey = z.object({
389
+ key: ServiceKey,
390
+ secret: z.string()
391
+ });
392
+ const WebhookSecret = z.object({
393
+ secret: z.string(),
394
+ version: z.number().int()
395
+ });
396
+ const UsageRow = z.object({
397
+ environmentId: Uuid,
398
+ date: z.string(),
399
+ callCount: z.number(),
400
+ participantMinutes: z.number(),
401
+ peakParticipants: z.number(),
402
+ apiRequests: z.number(),
403
+ apiErrors: z.number(),
404
+ tokensIssued: z.number(),
405
+ messagesSent: z.number()
406
+ });
407
+ const AuditEvent = z.object({
408
+ id: Uuid,
409
+ actor: z.string(),
410
+ projectId: z.string().nullable(),
411
+ action: z.string(),
412
+ targetType: z.string(),
413
+ targetId: z.string().nullable(),
414
+ ip: z.string().nullable(),
415
+ userAgent: z.string().nullable(),
416
+ requestId: z.string().nullable(),
417
+ metadata: z.record(z.string(), z.unknown()),
418
+ createdAt: z.string()
419
+ });
420
+ const AuditPage = z.object({
421
+ items: z.array(AuditEvent),
422
+ nextBefore: z.string().nullable()
423
+ });
424
+ const RoleGrant = z.object({
425
+ id: Uuid,
426
+ email: z.string(),
427
+ role: ConsoleRole,
428
+ projectId: z.string().nullable(),
429
+ createdAt: z.string(),
430
+ /** Latest audited console action by this member on the organization's projects. Lists only. */
431
+ lastActivityAt: z.string().nullable().optional()
432
+ });
433
+ const AdminMe = z.object({
434
+ email: z.string(),
435
+ roles: z.array(z.object({
436
+ role: ConsoleRole,
437
+ projectId: z.string().nullable()
438
+ }))
439
+ });
440
+ /** One of the signed-in console user's own sessions. `id` identifies it for revocation only. */
441
+ const ConsoleSession = z.object({
442
+ id: z.string(),
443
+ current: z.boolean(),
444
+ createdAt: z.string(),
445
+ lastSeenAt: z.string(),
446
+ expiresAt: z.string(),
447
+ ip: z.string().nullable(),
448
+ userAgent: z.string().nullable()
449
+ });
450
+ const AuditQuery = z.object({
451
+ projectId: Uuid.optional(),
452
+ /** Exact action, e.g. `service_key.created`, or a prefix followed by `*`, e.g. `service_key.*`. */
453
+ action: z.string().max(100).optional(),
454
+ actor: z.string().max(320).optional(),
455
+ from: z.iso.datetime().optional(),
456
+ to: z.iso.datetime().optional(),
457
+ before: z.string().max(200).optional(),
458
+ limit: z.coerce.number().int().min(1).max(200).default(50)
459
+ });
460
+ const AdminCall = z.object({
461
+ id: Uuid,
462
+ environmentId: Uuid,
463
+ tenantId: z.string(),
464
+ productCallId: z.string(),
465
+ type: z.enum([
466
+ "one_to_one",
467
+ "group",
468
+ "livestream"
469
+ ]),
470
+ status: z.enum(["active", "ended"]),
471
+ maxParticipants: z.number().int(),
472
+ e2ee: z.boolean(),
473
+ startedAt: z.string(),
474
+ endedAt: z.string().nullable(),
475
+ /** Seconds from start to end (or to now while active). */
476
+ durationSeconds: z.number().int(),
477
+ /** Participant sessions connected now. */
478
+ connected: z.number().int(),
479
+ /** Participant sessions over the call's lifetime. */
480
+ participantSessions: z.number().int(),
481
+ /** Active, nobody connected, started more than 10 minutes ago. */
482
+ stale: z.boolean()
483
+ });
484
+ const AdminCallQuery = z.object({
485
+ status: z.enum([
486
+ "active",
487
+ "ended",
488
+ "all"
489
+ ]).default("active"),
490
+ type: z.enum([
491
+ "one_to_one",
492
+ "group",
493
+ "livestream"
494
+ ]).optional(),
495
+ env: Uuid.optional(),
496
+ /** Prefix of productCallId. */
497
+ q: z.string().max(128).optional(),
498
+ cursor: z.string().max(200).optional(),
499
+ limit: z.coerce.number().int().min(1).max(100).default(50)
500
+ });
501
+ const AdminCallPage = z.object({
502
+ items: z.array(AdminCall),
503
+ nextCursor: z.string().nullable()
504
+ });
505
+ const AdminParticipant = z.object({
506
+ identity: z.string(),
507
+ /** The product user ID part of the identity. */
508
+ userId: z.string(),
509
+ deviceId: z.string(),
510
+ joinedAt: z.string(),
511
+ leftAt: z.string().nullable(),
512
+ durationSeconds: z.number().int()
513
+ });
514
+ const AdminCallDetail = z.object({
515
+ call: AdminCall,
516
+ participants: z.array(AdminParticipant),
517
+ /** Total participant sessions; `participants` holds at most the 500 most recent. */
518
+ participantTotal: z.number().int()
519
+ });
520
+ const EnvironmentLive = z.object({
521
+ environmentId: Uuid,
522
+ environment: EnvironmentName,
523
+ activeCalls: z.object({
524
+ total: z.number().int(),
525
+ one_to_one: z.number().int(),
526
+ group: z.number().int(),
527
+ livestream: z.number().int()
528
+ }),
529
+ connectedParticipants: z.number().int(),
530
+ livestreamAudience: z.number().int(),
531
+ staleCalls: z.number().int(),
532
+ limits: ProjectLimits,
533
+ webhooks: z.object({
534
+ pending: z.number().int(),
535
+ dead: z.number().int(),
536
+ oldestPendingAt: z.string().nullable()
537
+ })
538
+ });
539
+ const ProjectLive = z.object({
540
+ generatedAt: z.string(),
541
+ environments: z.array(EnvironmentLive)
542
+ });
543
+ const UsageCounts = z.object({
544
+ callCount: z.number(),
545
+ participantMinutes: z.number(),
546
+ /** Highest single-environment peak in the bucket (never a sum). */
547
+ peakParticipants: z.number(),
548
+ messagesSent: z.number(),
549
+ tokensIssued: z.number(),
550
+ apiRequests: z.number(),
551
+ apiErrors: z.number()
552
+ });
553
+ const UsageSeriesQuery = z.object({
554
+ bucket: z.enum(["hour", "day"]).default("day"),
555
+ /** Hourly: ISO timestamp (inclusive). Daily: UTC date (inclusive). */
556
+ from: z.string().max(40),
557
+ /** Hourly: ISO timestamp (exclusive). Daily: UTC date (inclusive). */
558
+ to: z.string().max(40),
559
+ project: Uuid.optional(),
560
+ env: Uuid.optional()
561
+ });
562
+ const UsageSeries = z.object({
563
+ bucket: z.enum(["hour", "day"]),
564
+ from: z.string(),
565
+ to: z.string(),
566
+ /**
567
+ * First bucket ever recorded for the selected scope (any time), or null when nothing has been
568
+ * recorded. Buckets before it have no data; they are not zeros.
569
+ */
570
+ since: z.string().nullable(),
571
+ /** Buckets that have data; missing buckets after `since` had no activity. */
572
+ points: z.array(UsageCounts.extend({ bucket: z.string() })),
573
+ totals: UsageCounts,
574
+ byProject: z.array(UsageCounts.extend({ projectId: Uuid }))
575
+ });
576
+ const OrganizationLive = z.object({
577
+ generatedAt: z.string(),
578
+ projects: z.array(z.object({
579
+ projectId: Uuid,
580
+ activeCalls: z.number().int(),
581
+ livestreams: z.number().int(),
582
+ connectedParticipants: z.number().int(),
583
+ livestreamAudience: z.number().int(),
584
+ staleCalls: z.number().int(),
585
+ webhooksPending: z.number().int(),
586
+ webhooksDead: z.number().int()
587
+ }))
588
+ });
589
+ const WebhookDelivery = z.object({
590
+ id: Uuid,
591
+ environmentId: Uuid,
592
+ type: z.string(),
593
+ attempts: z.number().int(),
594
+ lastError: z.string().nullable(),
595
+ createdAt: z.string(),
596
+ availableAt: z.string(),
597
+ deliveredAt: z.string().nullable(),
598
+ deadAt: z.string().nullable()
599
+ });
600
+ const WebhookEventPage = z.object({
601
+ items: z.array(WebhookDelivery),
602
+ nextCursor: z.string().nullable()
603
+ });
604
+ const PushPlatform = z.enum(["android", "ios"]);
605
+ /** `fcm` (Android), `apns` (iOS alerts) and `apns_voip` (iOS PushKit, incoming calls only). */
606
+ const PushProvider = z.enum([
607
+ "fcm",
608
+ "apns",
609
+ "apns_voip"
610
+ ]);
611
+ const RegisterDeviceRequest = z.object({
612
+ platform: PushPlatform,
613
+ provider: PushProvider,
614
+ token: z.string().regex(/^[A-Za-z0-9:_.-]{16,4096}$/, "invalid push token"),
615
+ /** Android application id or iOS bundle id, used to pick the topic. */
616
+ appId: z.string().regex(/^[A-Za-z0-9._-]{1,200}$/),
617
+ apnsEnvironment: z.enum(["sandbox", "production"]).optional()
618
+ }).refine((v) => v.platform === "android" === (v.provider === "fcm"), "android devices use fcm; ios devices use apns or apns_voip").refine((v) => v.provider === "fcm" || v.apnsEnvironment !== void 0, "apnsEnvironment is required for apns providers");
619
+ const PushDevice = z.object({
620
+ id: Uuid,
621
+ deviceId: z.string(),
622
+ platform: PushPlatform,
623
+ provider: PushProvider,
624
+ appId: z.string(),
625
+ updatedAt: z.string()
626
+ });
627
+ const NotificationPreferences = z.object({
628
+ calls: z.boolean(),
629
+ messages: z.boolean()
630
+ });
631
+ /** Product-initiated notification (service key). Call pushes are sent automatically by call signals. */
632
+ const SendNotificationRequest = z.object({
633
+ tenantId: TenantId,
634
+ userIds: z.array(ProductId).min(1).max(1e3),
635
+ kind: z.enum(["message", "custom"]).default("custom"),
636
+ title: z.string().max(200).optional(),
637
+ body: z.string().max(1e3).optional(),
638
+ /** Flat string map delivered to the app; keep it small and free of secrets. */
639
+ data: z.record(z.string().max(64), z.string().max(1024)).default({}),
640
+ collapseKey: z.string().max(64).optional(),
641
+ ttlSeconds: z.number().int().min(0).max(2419200).default(86400)
642
+ });
643
+ const SendNotificationResponse = z.object({ queued: z.number().int() });
644
+ const RecordingKind = z.enum([
645
+ "room_composite",
646
+ "participant",
647
+ "audio_only"
648
+ ]);
649
+ const RecordingOutput = z.enum([
650
+ "mp4",
651
+ "ogg",
652
+ "hls"
653
+ ]);
654
+ const StartRecordingRequest = z.object({
655
+ kind: RecordingKind.default("room_composite"),
656
+ /** Required for `participant` recordings: the Lynkoria participant identity. */
657
+ participantIdentity: z.string().min(1).max(400).optional(),
658
+ outputs: z.array(RecordingOutput).min(1).max(2).default(["mp4"]),
659
+ /** Optional RTMP(S) destinations for live streaming (room composite only). */
660
+ rtmpUrls: z.array(z.url({ protocol: /^rtmps?$/ })).max(3).default([]),
661
+ layout: z.enum([
662
+ "grid",
663
+ "speaker",
664
+ "single-speaker"
665
+ ]).default("grid")
666
+ }).refine((v) => v.kind !== "participant" || v.participantIdentity, { message: "participantIdentity is required for participant recordings" }).refine((v) => v.kind !== "audio_only" || v.outputs.every((o) => o !== "mp4"), { message: "audio_only recordings use ogg or hls" }).refine((v) => v.rtmpUrls.length === 0 || v.kind === "room_composite", { message: "RTMP streaming is available for room_composite only" });
667
+ const RecordingStatus = z.enum([
668
+ "starting",
669
+ "active",
670
+ "ending",
671
+ "complete",
672
+ "failed",
673
+ "aborted",
674
+ "deleted"
675
+ ]);
676
+ const RecordingFile = z.object({
677
+ name: z.string(),
678
+ size: z.number().int().nullable(),
679
+ durationMs: z.number().int().nullable()
680
+ });
681
+ const Recording = z.object({
682
+ id: Uuid,
683
+ callId: Uuid,
684
+ kind: RecordingKind,
685
+ outputs: z.array(z.string()),
686
+ status: RecordingStatus,
687
+ files: z.array(RecordingFile),
688
+ error: z.string().nullable(),
689
+ startedAt: z.string().nullable(),
690
+ endedAt: z.string().nullable(),
691
+ expiresAt: z.string().nullable(),
692
+ createdAt: z.string()
693
+ });
694
+ const RecordingList = z.object({ recordings: z.array(Recording) });
695
+ const RecordingDownload = z.object({
696
+ url: z.string(),
697
+ expiresAt: z.string()
698
+ });
699
+ const PushDeliveryView = z.object({
700
+ id: Uuid,
701
+ environmentId: Uuid,
702
+ provider: PushProvider,
703
+ kind: z.string(),
704
+ status: z.enum([
705
+ "pending",
706
+ "sent",
707
+ "failed",
708
+ "dead"
709
+ ]),
710
+ attempts: z.number().int(),
711
+ lastError: z.string().nullable(),
712
+ createdAt: z.string(),
713
+ sentAt: z.string().nullable()
714
+ });
715
+ const ScanSummary = z.object({
716
+ counts: z.record(z.string(), z.number().int()),
717
+ recent: z.array(z.object({
718
+ id: Uuid,
719
+ environmentId: Uuid,
720
+ scanStatus: z.string(),
721
+ detectedType: z.string().nullable(),
722
+ scanDetail: z.string().nullable(),
723
+ size: z.number().int(),
724
+ scannedAt: z.string().nullable()
725
+ }))
726
+ });
727
+ const OpsOverview = z.object({
728
+ pushDeliveries: z.array(PushDeliveryView),
729
+ recordings: z.array(Recording),
730
+ scans: ScanSummary
731
+ });
732
+ export { AdminCall, AdminCallDetail, AdminCallPage, AdminCallQuery, AdminMe, AdminParticipant, Attachment, AttachmentScanStatus, AttachmentStatus, AuditEvent, AuditPage, AuditQuery, Call, CallSignalRequest, CallSignalType, CallStatus, CallType, ConnectivityStatus, ConsoleRole, ConsoleSession, Conversation, ConversationEvent, ConversationEventPage, ConversationEventType, ConversationList, ConversationType, CreateCallRequest, CreateConversationRequest, CreateEnvironmentRequest, CreateKeyRequest, CreateProjectRequest, CreatedServiceKey, DownloadUrlResponse, EditMessageRequest, Environment, EnvironmentLive, EnvironmentName, GrantRoleRequest, JoinTokenRequest, JoinTokenResponse, ManualStatus, MembersRequest, Message, MessagingTokenRequest, MessagingTokenResponse, NotificationPreferences, OpsOverview, OrganizationLive, ParticipantRole, PatchEnvironmentRequest, PatchProjectRequest, Presence, PresenceStatus, ProductId, ProductMessagingPolicy, Project, ProjectFeatures, ProjectLimits, ProjectLive, PushDeliveryView, PushDevice, PushPlatform, PushProvider, Reaction, ReactionRequest, ReadRequest, Recording, RecordingDownload, RecordingFile, RecordingKind, RecordingList, RecordingOutput, RecordingStatus, RegisterDeviceRequest, RoleGrant, ScanSummary, SendMessageRequest, SendMessageResponse, SendNotificationRequest, SendNotificationResponse, ServiceKey, ServiceScope, StartRecordingRequest, TenantId, UpdatePermissionsRequest, UploadIntentRequest, UploadIntentResponse, UsageCounts, UsageQuery, UsageRow, UsageSeries, UsageSeriesQuery, Uuid, WebhookDelivery, WebhookEventPage, WebhookSecret };