@openpeepshq/common 0.1.46 → 0.3.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.
Files changed (83) hide show
  1. package/dist/lib/adminSections.js +1 -1
  2. package/dist/lib/capabilitiesHelpers.js +30 -40
  3. package/dist/lib/csvHelpers.js +1 -1
  4. package/dist/lib/eventIcs.js +26 -32
  5. package/dist/lib/eventRecurrence.d.ts +17 -0
  6. package/dist/lib/eventRecurrence.js +75 -18
  7. package/dist/lib/eventTime.js +9 -11
  8. package/dist/lib/groupHelpers.js +13 -34
  9. package/dist/lib/groupTemplateHelpers.js +6 -10
  10. package/dist/lib/jamHelpers.js +6 -9
  11. package/dist/lib/markdownHelpers.d.ts +37 -0
  12. package/dist/lib/markdownHelpers.js +151 -3
  13. package/dist/lib/postHelpers.js +70 -97
  14. package/dist/lib/profileHelpers.js +17 -24
  15. package/dist/lib/pushHelpers.js +3 -4
  16. package/dist/lib/scopeHelpers.js +6 -9
  17. package/dist/lib/ssoLoginUrl.js +4 -6
  18. package/dist/lib/ssoProviders.js +35 -39
  19. package/dist/lib/tokenHelpers.js +5 -5
  20. package/dist/lib/utils.js +6 -7
  21. package/dist/types/admin-db.js +1 -1
  22. package/dist/types/api.d.ts +1 -0
  23. package/dist/types/api.js +1 -1
  24. package/dist/types/config.d.ts +3 -0
  25. package/dist/types/config.js +3 -0
  26. package/dist/types/models.js +1 -1
  27. package/dist/types/plugins.js +2 -2
  28. package/dist/zod.d.ts +1 -0
  29. package/dist/zod.js +1 -0
  30. package/package.json +36 -6
  31. package/src/index.ts +4 -0
  32. package/src/lib/adminSections.ts +84 -0
  33. package/src/lib/attachmentHelpers.ts +14 -0
  34. package/src/lib/capabilitiesHelpers.ts +532 -0
  35. package/src/lib/colors.ts +20 -0
  36. package/src/lib/csvHelpers.ts +31 -0
  37. package/src/lib/eventIcs.ts +265 -0
  38. package/src/lib/eventRecurrence.ts +495 -0
  39. package/src/lib/eventTime.ts +206 -0
  40. package/src/lib/federationHosts.ts +22 -0
  41. package/src/lib/feedCursor.ts +27 -0
  42. package/src/lib/feedFormat.ts +24 -0
  43. package/src/lib/groupHelpers.ts +421 -0
  44. package/src/lib/groupTemplateHelpers.ts +83 -0
  45. package/src/lib/index.ts +29 -0
  46. package/src/lib/jamHelpers.ts +164 -0
  47. package/src/lib/legacyThemeRoot.ts +14 -0
  48. package/src/lib/markdownHelpers.ts +290 -0
  49. package/src/lib/mediaDimensions.ts +21 -0
  50. package/src/lib/postHelpers.ts +783 -0
  51. package/src/lib/profileHelpers.ts +220 -0
  52. package/src/lib/pushHelpers.ts +34 -0
  53. package/src/lib/reactions.ts +52 -0
  54. package/src/lib/reportHelpers.ts +7 -0
  55. package/src/lib/scopeHelpers.ts +176 -0
  56. package/src/lib/ssoLoginUrl.ts +93 -0
  57. package/src/lib/ssoProviders.ts +472 -0
  58. package/src/lib/text.ts +26 -0
  59. package/src/lib/timeZone.ts +52 -0
  60. package/src/lib/tokenHelpers.ts +119 -0
  61. package/src/lib/utils.ts +322 -0
  62. package/src/types/admin-db.ts +74 -0
  63. package/src/types/admin-email.ts +55 -0
  64. package/src/types/admin-jobs.ts +17 -0
  65. package/src/types/admin-performance.ts +20 -0
  66. package/src/types/analytics.ts +318 -0
  67. package/src/types/api.ts +871 -0
  68. package/src/types/apple-app-site-association.ts +54 -0
  69. package/src/types/auth.ts +22 -0
  70. package/src/types/capabilities.ts +280 -0
  71. package/src/types/config.ts +546 -0
  72. package/src/types/db.ts +138 -0
  73. package/src/types/export.ts +10 -0
  74. package/src/types/index.ts +20 -0
  75. package/src/types/internal.ts +338 -0
  76. package/src/types/models.ts +939 -0
  77. package/src/types/notifications.ts +92 -0
  78. package/src/types/plugins.ts +150 -0
  79. package/src/types/roleDefaults.ts +132 -0
  80. package/src/types/stats.ts +195 -0
  81. package/src/types/stripe.ts +45 -0
  82. package/src/types/utils.ts +100 -0
  83. package/src/zod.ts +1 -0
@@ -0,0 +1,871 @@
1
+ import { z } from 'zod';
2
+ import {
3
+ notificationStatsSchema,
4
+ pushNotificationSchema,
5
+ type PushNotification,
6
+ } from './notifications';
7
+ import {
8
+ AccessToken,
9
+ accessTokenSchema,
10
+ accountInteractionsSchema,
11
+ accountNameSchema,
12
+ accountSchema,
13
+ answerSchema,
14
+ applicationDataSchema,
15
+ groupDataSchema,
16
+ GroupRoleData,
17
+ groupRoleSchema,
18
+ groupSchema,
19
+ guestDataSchema,
20
+ hashtagSchema,
21
+ InviteLink,
22
+ inviteLinkSchema,
23
+ jamRecordingStatusSchema,
24
+ latLngSchema,
25
+ locationSchema,
26
+ type MediaAttachment,
27
+ mediaAttachmentSchema,
28
+ mentionDataSchema,
29
+ postDataUnionSchema,
30
+ postTypeSchema,
31
+ profileDataSchema,
32
+ profileStatsSchema,
33
+ reactionDataSchema,
34
+ roleDataSchema,
35
+ Report,
36
+ reportDataSchema,
37
+ reportSchema,
38
+ resourceSchema,
39
+ rsvpSchema,
40
+ Scope,
41
+ scopeSchema,
42
+ VisibilityType,
43
+ visibilityTypeSchema,
44
+ } from './models';
45
+ import { groupWithMetaSchema } from './internal';
46
+ import { communityConfigSchema } from './config';
47
+ import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi';
48
+
49
+ extendZodWithOpenApi(z);
50
+
51
+ export const errorResponseBodySchema = z.object({
52
+ success: z.literal(false),
53
+ message: z.string(),
54
+ });
55
+ export type ErrorResponseBody = z.infer<typeof errorResponseBodySchema>;
56
+
57
+ export const publicAccountSchema = z
58
+ .object({
59
+ id: z.uuid(),
60
+ email: z.email(),
61
+ emailValidated: z.boolean().default(false),
62
+ })
63
+ .openapi('Account', { type: 'object' });
64
+ export type PublicAccount = z.infer<typeof publicAccountSchema>;
65
+
66
+ /** Role identity on public profiles — capabilities stay internal. */
67
+ export const publicRoleSchema = roleDataSchema.pick({
68
+ key: true,
69
+ displayName: true,
70
+ });
71
+ export type PublicRole = z.infer<typeof publicRoleSchema>;
72
+
73
+ export const publicProfileSchema = z.object({
74
+ id: z.string().uuid(),
75
+ type: z.enum(['local', 'guest', 'federated']),
76
+ createdAt: z.string().datetime(),
77
+ updatedAt: z.string().datetime(),
78
+ deletedAt: z.string().datetime().nullable().optional(),
79
+ handle: accountNameSchema,
80
+ avatar: z.string().url().nullable().optional(),
81
+ header: z.string().url().nullable().optional(),
82
+ displayName: z.string().max(30).optional(),
83
+ bio: z.string().optional(),
84
+ location: locationSchema.optional(),
85
+ locked: z.boolean().optional(),
86
+ bot: z.boolean().optional(),
87
+ discoverable: z.boolean().optional(),
88
+ roles: publicRoleSchema.array().optional(),
89
+ memberships: z
90
+ .array(
91
+ groupRoleSchema.extend({
92
+ group: groupSchema,
93
+ }),
94
+ )
95
+ .optional()
96
+ .transform((memberships) =>
97
+ memberships?.filter((m) =>
98
+ m.group.capabilities?.none?.add?.includes('core-groups-read'),
99
+ ),
100
+ ),
101
+ fields: z
102
+ .array(
103
+ z.object({
104
+ name: z.string().max(255).min(1),
105
+ value: z.string().max(255),
106
+ }),
107
+ )
108
+ .max(4)
109
+ .optional(),
110
+ profileStats: profileStatsSchema.optional(),
111
+ pinnedPostId: z.string().optional(),
112
+ blockedByMe: z.boolean().optional(),
113
+ });
114
+
115
+ export type PublicProfile = z.infer<typeof publicProfileSchema>;
116
+
117
+ export const publicAccessTokenSchema = accessTokenSchema
118
+ .omit({ signedToken: true })
119
+ .extend({
120
+ ownedBy: publicProfileSchema.optional(),
121
+ scopes: z.array(scopeSchema).optional(),
122
+ })
123
+ .openapi('PublicAccessToken');
124
+
125
+ export type PublicAccessToken = Omit<AccessToken, 'signedToken'> & {
126
+ ownedBy?: PublicProfile;
127
+ scopes?: Scope[];
128
+ };
129
+
130
+ export const jamParticipantProfileSchema = publicProfileSchema.extend(
131
+ guestDataSchema.partial().shape,
132
+ );
133
+
134
+ export const mentionWithPublicProfileSchema = mentionDataSchema.extend({
135
+ profile: publicProfileSchema,
136
+ });
137
+ export type MentionWithPublicProfile = z.infer<
138
+ typeof mentionWithPublicProfileSchema
139
+ >;
140
+
141
+ export const entryWithPublicProfileSchema = z.discriminatedUnion('type', [
142
+ z.object({
143
+ type: z.literal('create'),
144
+ data: postDataUnionSchema,
145
+ profile: publicProfileSchema,
146
+ createdAt: z.string().datetime(),
147
+ }),
148
+ z.object({
149
+ type: z.literal('edit'),
150
+ data: postDataUnionSchema,
151
+ profile: publicProfileSchema,
152
+ createdAt: z.string().datetime(),
153
+ }),
154
+ z.object({
155
+ type: z.literal('delete'),
156
+ data: z.any(),
157
+ profile: publicProfileSchema,
158
+ createdAt: z.string().datetime(),
159
+ }),
160
+ z.object({
161
+ type: z.literal('answer'),
162
+ data: answerSchema,
163
+ profile: publicProfileSchema,
164
+ createdAt: z.string().datetime(),
165
+ }),
166
+ z.object({
167
+ type: z.literal('rsvp'),
168
+ data: rsvpSchema,
169
+ profile: publicProfileSchema,
170
+ createdAt: z.string().datetime(),
171
+ }),
172
+ ]);
173
+
174
+ export type EntryWithPublicProfile = z.infer<
175
+ typeof entryWithPublicProfileSchema
176
+ >;
177
+
178
+ const reactionWithPublicProfileSchema = reactionDataSchema.extend({
179
+ profile: publicProfileSchema,
180
+ });
181
+ export type ReactionWithPublicProfile = z.infer<
182
+ typeof reactionWithPublicProfileSchema
183
+ >;
184
+
185
+ const repostWithPublicProfileSchema = z.object({
186
+ profile: publicProfileSchema,
187
+ createdAt: z.string().datetime(),
188
+ });
189
+ export type RepostWithPublicProfile = z.infer<
190
+ typeof repostWithPublicProfileSchema
191
+ >;
192
+
193
+ const publicReplyPostObject = z.object({
194
+ id: z.string(),
195
+ type: postTypeSchema,
196
+ profile: publicProfileSchema,
197
+ data: postDataUnionSchema,
198
+ entries: entryWithPublicProfileSchema.array(),
199
+ createdAt: z.string().datetime(),
200
+ deletedAt: z.string().datetime().optional().nullable(),
201
+ visibility: visibilityTypeSchema,
202
+ group: groupWithMetaSchema.optional().nullable(),
203
+ audience: z.array(publicProfileSchema).optional().nullable(),
204
+ seen: z.boolean().optional(),
205
+ inReplyToId: z.string().optional().nullable(),
206
+ hidden: z.boolean().optional(),
207
+ });
208
+ export const publicReplyPostSchema = publicReplyPostObject.extend({
209
+ replyTo: publicReplyPostObject.optional().nullable(),
210
+ });
211
+ export type PublicReplyPost = z.infer<typeof publicReplyPostSchema>;
212
+
213
+ export const publicApplicationSchema = applicationDataSchema.pick({
214
+ name: true,
215
+ website: true,
216
+ });
217
+ export type PublicApplication = z.infer<typeof publicApplicationSchema>;
218
+
219
+ const publicRsvpSchema = rsvpSchema.extend({
220
+ profile: publicProfileSchema,
221
+ createdAt: z.string().datetime(),
222
+ });
223
+ export type PublicRsvp = z.infer<typeof publicRsvpSchema>;
224
+
225
+ const basePublicPostSchema = publicReplyPostSchema.extend({
226
+ repostCount: z.number(),
227
+ replyCount: z.number(),
228
+ reactions: reactionWithPublicProfileSchema.array(),
229
+ /** Capped lean list of who reposted (most recent). Count stays in repostCount. */
230
+ reposts: repostWithPublicProfileSchema.array(),
231
+ /** Newest conversation descendants for a nested timeline preview. */
232
+ latestReplies: publicReplyPostSchema.array().optional(),
233
+ latestRepliesHasMore: z.boolean().optional(),
234
+ /** Last reply or reaction on the conversation root; feeds sort by this. */
235
+ lastActivityAt: z.string().datetime().optional(),
236
+ application: publicApplicationSchema.optional(),
237
+ mentions: z.array(mentionWithPublicProfileSchema),
238
+ tags: z.array(hashtagSchema),
239
+ groupId: z.string().optional().nullable(),
240
+ groupDiscoverable: z.boolean().optional().nullable(),
241
+ updatedAt: z.string().datetime(),
242
+ accountInteractions: accountInteractionsSchema.optional(),
243
+ rsvps: publicRsvpSchema.array(),
244
+ seen: z.boolean().optional(),
245
+ occurrenceRecurrenceId: z.string().datetime().optional(),
246
+ occurrenceStart: z.string().datetime().optional(),
247
+ occurrenceEnd: z.string().datetime().optional(),
248
+ });
249
+
250
+ const withReplyPostSchema = basePublicPostSchema.extend({
251
+ inReplyToId: z.string().optional().nullable(),
252
+ replyTo: publicReplyPostSchema.optional().nullable(),
253
+ });
254
+
255
+ export const publicPostSchema = withReplyPostSchema
256
+ .extend({
257
+ repost: basePublicPostSchema.optional().nullable(),
258
+ })
259
+ .openapi('Post');
260
+ export type PublicPost = z.infer<typeof publicPostSchema>;
261
+ export type PublicPostInput = z.input<typeof publicPostSchema>;
262
+
263
+ export const publicJamEventSchema = z.object({
264
+ jamId: z.string(),
265
+ type: z.enum(['message', 'reaction', 'attendance', 'active']),
266
+ content: z.string(),
267
+ sender: z.object({
268
+ profile: publicProfileSchema.extend({
269
+ email: z.string().email().optional(),
270
+ }),
271
+ participantId: z.string(),
272
+ }),
273
+
274
+ joinTime: z.string().datetime().optional(),
275
+ leaveTime: z.string().datetime().optional(),
276
+ });
277
+
278
+ export type PublicJamEvent = z.infer<typeof publicJamEventSchema>;
279
+
280
+ export const publicNotificationSchema = z.object({
281
+ id: z.string().uuid(),
282
+ type: z.string(),
283
+ seen: z.boolean().optional(),
284
+ read: z.boolean().optional(),
285
+ createdAt: z.string().datetime(),
286
+ senderProfile: publicProfileSchema.nullable().optional(),
287
+ group: groupSchema.nullable().optional(),
288
+ post: publicPostSchema.nullable().optional(),
289
+ data: z.any().optional(),
290
+ });
291
+ export type PublicNotification = z.infer<typeof publicNotificationSchema>;
292
+
293
+ export const publicGroupMemberSchema = groupRoleSchema.extend({
294
+ profile: publicProfileSchema,
295
+ });
296
+
297
+ export interface PublicGroupMember extends GroupRoleData {
298
+ profile: PublicProfile;
299
+ }
300
+
301
+ export const accountCreationDataSchema = z.object({
302
+ email: z.string().email(),
303
+ password: z.string().min(8),
304
+ emailValidated: z.boolean().optional(),
305
+ inviteCode: z.string().optional(),
306
+ profile: z.object({
307
+ handle: z.string().min(4).max(255),
308
+ avatar: z.string().url().optional(),
309
+ displayName: profileDataSchema.shape.displayName,
310
+ bot: profileDataSchema.shape.bot,
311
+ }),
312
+ });
313
+
314
+ export type AccountCreationData = z.infer<typeof accountCreationDataSchema>;
315
+
316
+ export const accountUpdateDataSchema = z.object({
317
+ account: accountSchema,
318
+ email: z.string().email().optional(),
319
+ password: z.string().min(8).optional(),
320
+ emailValidated: z.boolean().optional(),
321
+ });
322
+
323
+ export type AccountUpdateData = z.infer<typeof accountUpdateDataSchema>;
324
+
325
+ export type OpenpeepsErrorCode = 404 | 500 | 409 | 422 | 403 | 401;
326
+ export interface OpenpeepsErrorData {
327
+ code?: OpenpeepsErrorCode;
328
+ errorKey: string;
329
+ parameters?: Record<string, unknown>;
330
+ }
331
+ export interface OpenpeepsError extends OpenpeepsErrorData {
332
+ __allPeepError__: true;
333
+ }
334
+
335
+ export const serverInfoSchema = z.object({
336
+ version: z.string(),
337
+ /** Optional CI/image build identifier (`BUILD`). */
338
+ build: z.string().optional(),
339
+ environment: z.string(),
340
+ publicContent: z.boolean(),
341
+ /** Process start time (ISO). */
342
+ startedAt: z.iso.datetime(),
343
+ uptimeSeconds: z.number().nonnegative(),
344
+ /** Local media-folder size and volume free space; null when unreadable. */
345
+ disk: z
346
+ .object({
347
+ folderBytes: z.number().nonnegative(),
348
+ freeBytes: z.number().nonnegative(),
349
+ totalBytes: z.number().nonnegative(),
350
+ })
351
+ .nullable(),
352
+ /** Latest post view (`post_seen.created_at`); null if none yet. */
353
+ lastAccessed: z.iso.datetime().nullable(),
354
+ maxProfiles: z.number().int().nonnegative().optional(),
355
+ communityConfig: communityConfigSchema,
356
+ jams: z.object({
357
+ livekit: z.object({
358
+ url: z.string(),
359
+ enabled: z.boolean(),
360
+ recordingEnabled: z.boolean(),
361
+ }),
362
+ }),
363
+ vapid: z.object({
364
+ publicKey: z.string().optional(),
365
+ }),
366
+ sentryConfig: z.object({
367
+ enabled: z.boolean(),
368
+ dsn: z.string().optional(),
369
+ replayEnabled: z.boolean().optional(),
370
+ }),
371
+ payments: z.object({
372
+ stripe: z.object({
373
+ paidMembership: z.object({
374
+ enabled: z.boolean(),
375
+ }),
376
+ }),
377
+ }),
378
+ sso: z
379
+ .object({
380
+ onlySSO: z.boolean().optional(),
381
+ generic: z.array(
382
+ z.object({
383
+ id: z.string(),
384
+ name: z.string(),
385
+ loginLink: z.string(),
386
+ }),
387
+ ),
388
+ oidc: z.array(
389
+ z.object({
390
+ id: z.string(),
391
+ name: z.string(),
392
+ }),
393
+ ),
394
+ })
395
+ .optional(),
396
+ });
397
+
398
+ export type ServerInfo = z.infer<typeof serverInfoSchema>;
399
+
400
+ export const unseenPostCountsSchema = z.object({
401
+ groups: z.record(z.string(), z.number()),
402
+ direct: z.record(z.string(), z.number()),
403
+ });
404
+ export type UnseenPostCounts = z.infer<typeof unseenPostCountsSchema>;
405
+
406
+ export const pushPayloadSchema = z.object({
407
+ notification: pushNotificationSchema,
408
+ notificationStats: notificationStatsSchema,
409
+ });
410
+ export type PushPayload = z.infer<typeof pushPayloadSchema>;
411
+
412
+ export const webhookDataSchema = z.object({
413
+ type: z.literal('pushNotification'),
414
+ payload: pushPayloadSchema,
415
+ });
416
+ export type WebhookData = z.infer<typeof webhookDataSchema>;
417
+
418
+ export const webhookKeyResponseSchema = z.object({
419
+ publicKey: z.string(),
420
+ });
421
+ export type WebhookKeyResponse = z.infer<typeof webhookKeyResponseSchema>;
422
+ export const webhookVerifyRequestSchema = z.object({
423
+ token: z.string(),
424
+ });
425
+ export type WebhookVerifyRequest = z.infer<typeof webhookVerifyRequestSchema>;
426
+ export const webhookVerifyResponseSchema = z.object({
427
+ success: z.literal(true),
428
+ payload: z.record(z.string(), z.unknown()),
429
+ });
430
+ export type WebhookVerifyResponse = z.infer<typeof webhookVerifyResponseSchema>;
431
+
432
+ export const publicInviteLinkSchema = inviteLinkSchema.extend({
433
+ profile: publicProfileSchema,
434
+ redemptions: publicProfileSchema.array(),
435
+ });
436
+
437
+ export interface PublicInviteLink extends InviteLink {
438
+ profile: PublicProfile;
439
+ redemptions: PublicProfile[];
440
+ }
441
+
442
+ export const muteParticipantRequestSchema = z.object({
443
+ identity: z.string().uuid(),
444
+ trackSid: z.string(),
445
+ });
446
+
447
+ export type MuteParticipantRequest = z.infer<
448
+ typeof muteParticipantRequestSchema
449
+ >;
450
+ export interface Thread extends PublicPost {
451
+ children: Thread[];
452
+ }
453
+
454
+ export interface AudienceSetting {
455
+ visibility: VisibilityType;
456
+ groupId?: string | null;
457
+ audience?: PublicProfile[] | null;
458
+ }
459
+
460
+ export const guestPassRequestSchema = z.object({
461
+ displayName: z.string().max(30),
462
+ email: z.string().email(),
463
+ resource: resourceSchema,
464
+ });
465
+ export type GuestPassRequest = z.infer<typeof guestPassRequestSchema>;
466
+
467
+ export const logRowSchema = z.object({
468
+ level: z.string(),
469
+ message: z.string(),
470
+ timestamp: z.string().date(),
471
+ meta: z.any(),
472
+ namespace: z.string(),
473
+ });
474
+ export type LogRow = z.infer<typeof logRowSchema>;
475
+ export const successResponseSchema = z.object({
476
+ success: z.literal(true),
477
+ });
478
+ export type SuccessResponse = z.infer<typeof successResponseSchema>;
479
+
480
+ export const successFailureResponseSchema = z.object({
481
+ success: z.boolean(),
482
+ message: z.string().optional(),
483
+ key: z.string().optional(),
484
+ });
485
+ export type SuccessFailureResponse = z.infer<
486
+ typeof successFailureResponseSchema
487
+ >;
488
+
489
+ export const fetchUrlRequestSchema = z.object({
490
+ url: z.url(),
491
+ });
492
+
493
+ export const fetchUrlReponseSchema = z.object({
494
+ statusCode: z.number(),
495
+ success: z.boolean(),
496
+ data: z.object({
497
+ image: z.string(),
498
+ title: z.string(),
499
+ description: z.string(),
500
+ url: z.string(),
501
+ }),
502
+ });
503
+
504
+ export type FetchUrlResponse = z.infer<typeof fetchUrlReponseSchema>;
505
+
506
+ export const loginRequestSchema = z.object({
507
+ email: z.email(),
508
+ password: z.string().min(8),
509
+ });
510
+ export type LoginRequest = z.infer<typeof loginRequestSchema>;
511
+
512
+ export type FetchUrlRequest = z.infer<typeof fetchUrlRequestSchema>;
513
+
514
+ export const registerRequestSchema = z.object({
515
+ handle: accountNameSchema,
516
+ email: z.email(),
517
+ password: z
518
+ .string()
519
+ .min(8, { message: 'Your password should be at least 8 characters long' }),
520
+ displayName: profileDataSchema.shape.displayName,
521
+ confirmPassword: z.string().optional(),
522
+ privacyPolicyAccepted: z.boolean(),
523
+ inviteCode: z.string().optional(),
524
+ bot: profileDataSchema.shape.bot,
525
+ });
526
+ export type RegisterRequest = z.infer<typeof registerRequestSchema>;
527
+
528
+ export const registerFormSchema = registerRequestSchema
529
+ .refine((data) => data.password === data.confirmPassword, {
530
+ message: 'Passwords do not match',
531
+ path: ['confirmPassword'],
532
+ })
533
+ .refine((data) => data.privacyPolicyAccepted, {
534
+ message: 'You must agree to the privacy policy',
535
+ path: ['privacyPolicyAccepted'],
536
+ });
537
+ export const createGroupRequestSchema = groupDataSchema.extend({
538
+ members: publicProfileSchema.array().optional(),
539
+ });
540
+ export type CreateGroupRequest = z.infer<typeof createGroupRequestSchema>;
541
+
542
+ export const requestResetPasswordRequestSchema = z.object({
543
+ email: z.string().email(),
544
+ });
545
+ export type RequestResetPasswordRequest = z.infer<
546
+ typeof requestResetPasswordRequestSchema
547
+ >;
548
+
549
+ export const resetPasswordRequestSchema = z.object({
550
+ password: z.string().min(8),
551
+ confirmPassword: z.string().optional(),
552
+ });
553
+ export type ResetPasswordRequest = z.infer<typeof resetPasswordRequestSchema>;
554
+
555
+ export const resetPasswordFormSchema = resetPasswordRequestSchema.refine(
556
+ (data) => data.password === data.confirmPassword,
557
+ {
558
+ message: 'Passwords do not match',
559
+ path: ['confirmPassword'],
560
+ },
561
+ );
562
+
563
+ export const validateEmailQuerySchema = z.object({
564
+ token: z.string().min(1),
565
+ });
566
+ export type ValidateEmailQuery = z.infer<typeof validateEmailQuerySchema>;
567
+
568
+ export const tokenResponseSchema = z.object({
569
+ success: z.literal(true),
570
+ token: z.string(),
571
+ checkoutUrl: z.string().optional(),
572
+ });
573
+ export type TokenResponse = z.infer<typeof tokenResponseSchema>;
574
+
575
+ export const jamTokenResponseSchema = tokenResponseSchema.extend({
576
+ livekitUrl: z.string(),
577
+ });
578
+ export type JamTokenResponse = z.infer<typeof jamTokenResponseSchema>;
579
+
580
+ export interface Credentials {
581
+ token: string;
582
+ }
583
+
584
+ const focusCoordinatesPattern = /^-?\d+,-?\d+$/;
585
+
586
+ // NOTE: `file` / `thumbnail` accept a `File` (browser) or any
587
+ // multipart body — modelled as `z.any()` for the API contract so the OpenAPI
588
+ // generator can produce a binary content schema. Handlers should runtime-check
589
+ // they actually got a `File` / `Blob` instance.
590
+ export const mediaStorageRequestSchema = z.object({
591
+ description: z.string().optional(),
592
+ file: z.any().openapi({
593
+ type: 'string',
594
+ format: 'binary',
595
+ }) as unknown as z.ZodType<File>,
596
+ thumbnail: z
597
+ .any()
598
+ .optional()
599
+ .openapi({ type: 'string', format: 'binary' }) as unknown as z.ZodType<
600
+ File | undefined
601
+ >,
602
+ usage: z.string(),
603
+ focus: z
604
+ .string()
605
+ .regex(focusCoordinatesPattern, 'focus must be "<integer>,<integer>"')
606
+ .optional(),
607
+ });
608
+ export type MediaStorageRequest = z.infer<typeof mediaStorageRequestSchema>;
609
+ // `z.input` widens `z.any()` to `unknown`, which is incompatible with the
610
+ // `FormDataSource` constraint used by `@openpeepshq/fetch-client`. We retain the
611
+ // pre-transform `focus` input but pin `file` / `thumbnail` to the binary types
612
+ // that the client actually sends.
613
+ export type MediaStorageRequestInput = Omit<
614
+ z.input<typeof mediaStorageRequestSchema>,
615
+ 'file' | 'thumbnail'
616
+ > & {
617
+ file: File;
618
+ thumbnail?: File;
619
+ };
620
+
621
+ export const mediaProgressEventSchema = z
622
+ .object({
623
+ mediaAttachment: mediaAttachmentSchema,
624
+ progressPercent: z.number().min(0).max(100),
625
+ estimatedRemainingMs: z.number().optional(),
626
+ })
627
+ .openapi('MediaProgressEvent');
628
+ // Using a manual type because `modelSchema(...)` widens to `ZodObject<ZodRawShape>`
629
+ // and loses the precise field types when inferred via `z.infer`.
630
+ export type MediaProgressEvent = {
631
+ mediaAttachment: MediaAttachment;
632
+ progressPercent: number;
633
+ estimatedRemainingMs?: number;
634
+ };
635
+
636
+ export const mediaStreamStatusSchema = z
637
+ .enum(['processing', 'ready', 'error'])
638
+ .openapi('MediaStreamStatus');
639
+ export type MediaStreamStatus = z.infer<typeof mediaStreamStatusSchema>;
640
+
641
+ export const mediaStreamSchema = z
642
+ .object({
643
+ storageId: z.string(),
644
+ status: mediaStreamStatusSchema,
645
+ error: z.string().optional(),
646
+ })
647
+ .openapi('MediaStream');
648
+ export type MediaStream = z.infer<typeof mediaStreamSchema>;
649
+
650
+ export const mediaStreamRequestSchema = z
651
+ .object({
652
+ url: z.string().url(),
653
+ })
654
+ .openapi('MediaStreamRequest');
655
+ export type MediaStreamRequest = z.infer<typeof mediaStreamRequestSchema>;
656
+
657
+ export const updateProfileRequestSchema = profileDataSchema
658
+ .omit({ pinnedPostId: true })
659
+ .partial({
660
+ handle: true,
661
+ })
662
+ .superRefine((value, ctx) => {
663
+ if (value.handle === undefined || value.type === 'federated') return;
664
+ if (!accountNameSchema.safeParse(value.handle).success) {
665
+ ctx.addIssue({
666
+ code: 'custom',
667
+ path: ['handle'],
668
+ message:
669
+ 'Handle must be 1–16 characters: letters, numbers, underscores, or hyphens (no spaces or punctuation)',
670
+ });
671
+ }
672
+ });
673
+ export type UpdateProfileRequest = z.infer<typeof updateProfileRequestSchema>;
674
+
675
+ export const updateAccountPasswordRequestSchema = z.object({
676
+ email: z.string().email().optional(),
677
+ newPassword: z.preprocess(
678
+ (s) => s || undefined,
679
+ z.string().min(8).optional(),
680
+ ),
681
+ oldPassword: z.string().min(8),
682
+ confirmPassword: z.preprocess(
683
+ (s) => s || undefined,
684
+ z.string().min(8).optional(),
685
+ ),
686
+ });
687
+ export type UpdateAccountPasswordRequest = z.infer<
688
+ typeof updateAccountPasswordRequestSchema
689
+ >;
690
+ export const updateAccountPasswordFormSchema =
691
+ updateAccountPasswordRequestSchema
692
+ .refine((data) => data.newPassword === data.confirmPassword, {
693
+ message: 'Passwords do not match',
694
+ path: ['confirmPassword'],
695
+ })
696
+ .refine((data) => data.oldPassword, {
697
+ message:
698
+ 'You must provide your old password to change your password or email',
699
+ path: ['__form__'],
700
+ });
701
+
702
+ export const updateAccountEmailRequestSchema = z.object({
703
+ newEmail: z.email(),
704
+ oldEmail: z.email(),
705
+ });
706
+
707
+ export type UpdateAccountEmailRequest = z.infer<
708
+ typeof updateAccountEmailRequestSchema
709
+ >;
710
+
711
+ export const geocodingResultSchema = z.object({
712
+ name: z.string(),
713
+ bbox: latLngSchema.array().length(2),
714
+ center: latLngSchema,
715
+ icon: z.string().optional(),
716
+ properties: z.record(z.string(), z.any()).optional(),
717
+ });
718
+ export type GeocodingResult = z.infer<typeof geocodingResultSchema>;
719
+
720
+ export const reportCreationDataSchema = z.object({
721
+ report: reportDataSchema,
722
+ profileId: z.string(),
723
+ postIds: z.string().array(),
724
+ });
725
+ export type ReportCreationData = z.infer<typeof reportCreationDataSchema>;
726
+
727
+ export const jamStateSchema = z.object({
728
+ active: z.boolean(),
729
+ participants: z.uuid().array(),
730
+ });
731
+ export type JamState = z.infer<typeof jamStateSchema>;
732
+
733
+ export const publicReportSchema = reportSchema.extend({
734
+ reporterProfile: publicProfileSchema,
735
+ reportedProfile: publicProfileSchema,
736
+ reportedPosts: z.array(publicPostSchema),
737
+ });
738
+ export type PublicReport = Report & {
739
+ reporterProfile: PublicProfile;
740
+ reportedProfile: PublicProfile;
741
+ reportedPosts: PublicPost[];
742
+ };
743
+
744
+ export const chronologicalInfiniteQueryParamsSchema = z.object({
745
+ start: z.string().optional(),
746
+ limit: z.coerce.number().optional(),
747
+ format: z.enum(['threaded', 'linear']).optional(),
748
+ });
749
+ export type ChronologicalInfiniteQueryParams =
750
+ | z.infer<typeof chronologicalInfiniteQueryParamsSchema>
751
+ | undefined;
752
+ export const offsetInfiniteQueryParamsSchema = z.object({
753
+ offset: z.coerce.number().optional(),
754
+ limit: z.coerce.number().optional(),
755
+ });
756
+ export type OffsetInfiniteQueryParams =
757
+ | z.infer<typeof offsetInfiniteQueryParamsSchema>
758
+ | undefined;
759
+
760
+ export const searchResultItemSchema = (baseSchema: z.ZodType) =>
761
+ z.object({
762
+ score: z.number(),
763
+ data: baseSchema,
764
+ });
765
+ export type SearchResultItem<T> = {
766
+ score: number;
767
+ data: T;
768
+ };
769
+ export const searchResultSchema = (baseSchema: z.ZodType) =>
770
+ searchResultItemSchema(baseSchema).array();
771
+ export type SearchResult<T> = SearchResultItem<T>[];
772
+
773
+ export const searchResultCountsSchema = z.object({
774
+ groups: z.number(),
775
+ profiles: z.number(),
776
+ posts: z.number(),
777
+ events: z.number(),
778
+ jams: z.number(),
779
+ });
780
+ export type SearchResultCounts = z.infer<typeof searchResultCountsSchema>;
781
+
782
+ // Plain object schema — used as API contract & in OpenAPI generation. Cross-
783
+ // field validation lives on `postCreationDataFormSchema` below to keep this
784
+ // schema introspectable by zod-to-openapi (which can't walk zod-4 `.refine()`
785
+ // wrappers, as they appear as a `ZodCustom` with `def.type === 'custom'`).
786
+ export const postCreationDataSchema = z.object({
787
+ visibility: visibilityTypeSchema,
788
+ type: postTypeSchema,
789
+ data: postDataUnionSchema,
790
+ inReplyToId: z.uuid().nullable().optional(),
791
+ mentions: mentionWithPublicProfileSchema.array().nullable().optional(),
792
+ audience: publicProfileSchema.array().nullable().optional(),
793
+ groupId: z.uuid().nullable().optional(),
794
+ reportId: z.uuid().nullable().optional(),
795
+ capabilitiesNeeded: z.string().array().nullable().optional(),
796
+ });
797
+
798
+ export type PostCreationData = z.infer<typeof postCreationDataSchema>;
799
+
800
+ export const postCreationDataFormSchema = postCreationDataSchema
801
+ .refine(
802
+ (data) => {
803
+ if (data.type !== 'event') return true;
804
+ if (data.data.type !== 'event') return true;
805
+ return !!data.data.name;
806
+ },
807
+ {
808
+ message: 'Name is required',
809
+ path: ['data', 'name'],
810
+ },
811
+ )
812
+ .refine(
813
+ (data) => {
814
+ if (data.type !== 'event') return true;
815
+ if (data.data.type !== 'event') return true;
816
+
817
+ const { start, end } = data.data;
818
+
819
+ if (end && start && new Date(end) < new Date(start)) {
820
+ return false;
821
+ }
822
+
823
+ return true;
824
+ },
825
+ {
826
+ message: 'End date cannot be before start date',
827
+ path: ['data', 'end'],
828
+ },
829
+ );
830
+
831
+ const answerWithPublicProfileSchema = answerSchema.extend({
832
+ profile: publicProfileSchema,
833
+ });
834
+ export type AnswerWithPublicProfile = z.infer<
835
+ typeof answerWithPublicProfileSchema
836
+ >;
837
+
838
+ export const paymentCheckoutSchema = successFailureResponseSchema.extend({
839
+ url: z.url().nullable(),
840
+ });
841
+ export type PaymentCheckoutResponse = z.infer<typeof paymentCheckoutSchema>;
842
+
843
+ export const jamObserverResponseSchema = z.object({
844
+ path: z.string().optional(),
845
+ });
846
+
847
+ export type JamObserverResponseData = z.infer<typeof jamObserverResponseSchema>;
848
+
849
+ export const jamRtmpStreamRequestSchema = z.object({
850
+ url: z.string().min(1),
851
+ streamKey: z.string().min(1),
852
+ });
853
+ export type JamRtmpStreamRequest = z.infer<typeof jamRtmpStreamRequestSchema>;
854
+
855
+ export const jamRtmpStreamResponseSchema = z.object({
856
+ id: z.string(),
857
+ status: jamRecordingStatusSchema,
858
+ destinationHost: z.string().optional(),
859
+ egressId: z.string().optional(),
860
+ });
861
+ export type JamRtmpStreamResponse = z.infer<typeof jamRtmpStreamResponseSchema>;
862
+
863
+ export const accessTokenCreationDataSchema = z.object({
864
+ name: z.string(),
865
+ description: z.string().optional(),
866
+ scopes: z.array(scopeSchema).optional(),
867
+ expirationTime: z.string(),
868
+ });
869
+ export type AccessTokenCreationData = z.infer<
870
+ typeof accessTokenCreationDataSchema
871
+ >;