@openpeepshq/common 0.1.45 → 0.2.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 (126) hide show
  1. package/dist/lib/adminSections.js +1 -1
  2. package/dist/lib/capabilitiesHelpers.d.ts +9 -7
  3. package/dist/lib/capabilitiesHelpers.js +43 -38
  4. package/dist/lib/csvHelpers.js +1 -1
  5. package/dist/lib/eventIcs.d.ts +17 -0
  6. package/dist/lib/eventIcs.js +91 -15
  7. package/dist/lib/eventRecurrence.d.ts +19 -0
  8. package/dist/lib/eventRecurrence.js +82 -20
  9. package/dist/lib/eventTime.d.ts +7 -0
  10. package/dist/lib/eventTime.js +23 -9
  11. package/dist/lib/federationHosts.d.ts +3 -0
  12. package/dist/lib/federationHosts.js +17 -0
  13. package/dist/lib/feedCursor.d.ts +14 -0
  14. package/dist/lib/feedCursor.js +22 -0
  15. package/dist/lib/feedFormat.d.ts +12 -0
  16. package/dist/lib/feedFormat.js +14 -0
  17. package/dist/lib/groupHelpers.js +13 -34
  18. package/dist/lib/groupTemplateHelpers.js +6 -10
  19. package/dist/lib/index.d.ts +7 -0
  20. package/dist/lib/index.js +7 -0
  21. package/dist/lib/jamHelpers.d.ts +11 -2
  22. package/dist/lib/jamHelpers.js +43 -9
  23. package/dist/lib/legacyThemeRoot.d.ts +3 -0
  24. package/dist/lib/legacyThemeRoot.js +10 -0
  25. package/dist/lib/markdownHelpers.d.ts +8 -0
  26. package/dist/lib/markdownHelpers.js +34 -6
  27. package/dist/lib/postHelpers.d.ts +142 -3
  28. package/dist/lib/postHelpers.js +323 -47
  29. package/dist/lib/profileHelpers.d.ts +11 -0
  30. package/dist/lib/profileHelpers.js +34 -10
  31. package/dist/lib/pushHelpers.js +3 -4
  32. package/dist/lib/reactions.d.ts +17 -0
  33. package/dist/lib/reactions.js +37 -0
  34. package/dist/lib/scopeHelpers.d.ts +31 -2
  35. package/dist/lib/scopeHelpers.js +39 -8
  36. package/dist/lib/ssoLoginUrl.js +4 -6
  37. package/dist/lib/ssoProviders.d.ts +72 -0
  38. package/dist/lib/ssoProviders.js +366 -0
  39. package/dist/lib/timeZone.d.ts +9 -0
  40. package/dist/lib/timeZone.js +44 -0
  41. package/dist/lib/tokenHelpers.js +5 -5
  42. package/dist/lib/utils.js +6 -7
  43. package/dist/types/admin-db.js +1 -1
  44. package/dist/types/analytics.d.ts +20 -0
  45. package/dist/types/analytics.js +4 -0
  46. package/dist/types/api.d.ts +41800 -11853
  47. package/dist/types/api.js +53 -5
  48. package/dist/types/auth.d.ts +20 -6
  49. package/dist/types/capabilities.d.ts +15 -1
  50. package/dist/types/capabilities.js +51 -0
  51. package/dist/types/config.d.ts +99 -0
  52. package/dist/types/config.js +56 -4
  53. package/dist/types/db.d.ts +1155 -164
  54. package/dist/types/db.js +14 -0
  55. package/dist/types/export.d.ts +120 -0
  56. package/dist/types/export.js +7 -0
  57. package/dist/types/index.d.ts +2 -0
  58. package/dist/types/index.js +2 -0
  59. package/dist/types/internal.d.ts +2577 -524
  60. package/dist/types/internal.js +6 -0
  61. package/dist/types/models.d.ts +63 -7
  62. package/dist/types/models.js +40 -3
  63. package/dist/types/plugins.d.ts +22 -0
  64. package/dist/types/plugins.js +66 -0
  65. package/dist/types/roleDefaults.d.ts +31 -0
  66. package/dist/types/roleDefaults.js +110 -0
  67. package/dist/types/stats.d.ts +54606 -6065
  68. package/dist/types/stats.js +30 -0
  69. package/dist/types/utils.d.ts +2 -0
  70. package/dist/types/utils.js +1 -3
  71. package/dist/zod.d.ts +1 -0
  72. package/dist/zod.js +1 -0
  73. package/package.json +36 -6
  74. package/src/index.ts +4 -0
  75. package/src/lib/adminSections.ts +84 -0
  76. package/src/lib/attachmentHelpers.ts +14 -0
  77. package/src/lib/capabilitiesHelpers.ts +532 -0
  78. package/src/lib/colors.ts +20 -0
  79. package/src/lib/csvHelpers.ts +31 -0
  80. package/src/lib/eventIcs.ts +265 -0
  81. package/src/lib/eventRecurrence.ts +495 -0
  82. package/src/lib/eventTime.ts +206 -0
  83. package/src/lib/federationHosts.ts +22 -0
  84. package/src/lib/feedCursor.ts +27 -0
  85. package/src/lib/feedFormat.ts +24 -0
  86. package/src/lib/groupHelpers.ts +421 -0
  87. package/src/lib/groupTemplateHelpers.ts +83 -0
  88. package/src/lib/index.ts +29 -0
  89. package/src/lib/jamHelpers.ts +164 -0
  90. package/src/lib/legacyThemeRoot.ts +14 -0
  91. package/src/lib/markdownHelpers.ts +122 -0
  92. package/src/lib/mediaDimensions.ts +21 -0
  93. package/src/lib/postHelpers.ts +783 -0
  94. package/src/lib/profileHelpers.ts +220 -0
  95. package/src/lib/pushHelpers.ts +34 -0
  96. package/src/lib/reactions.ts +52 -0
  97. package/src/lib/reportHelpers.ts +7 -0
  98. package/src/lib/scopeHelpers.ts +176 -0
  99. package/src/lib/ssoLoginUrl.ts +93 -0
  100. package/src/lib/ssoProviders.ts +472 -0
  101. package/src/lib/text.ts +26 -0
  102. package/src/lib/timeZone.ts +52 -0
  103. package/src/lib/tokenHelpers.ts +119 -0
  104. package/src/lib/utils.ts +322 -0
  105. package/src/types/admin-db.ts +74 -0
  106. package/src/types/admin-email.ts +55 -0
  107. package/src/types/admin-jobs.ts +17 -0
  108. package/src/types/admin-performance.ts +20 -0
  109. package/src/types/analytics.ts +318 -0
  110. package/src/types/api.ts +871 -0
  111. package/src/types/apple-app-site-association.ts +54 -0
  112. package/src/types/auth.ts +22 -0
  113. package/src/types/capabilities.ts +280 -0
  114. package/src/types/config.ts +546 -0
  115. package/src/types/db.ts +138 -0
  116. package/src/types/export.ts +10 -0
  117. package/src/types/index.ts +20 -0
  118. package/src/types/internal.ts +338 -0
  119. package/src/types/models.ts +939 -0
  120. package/src/types/notifications.ts +92 -0
  121. package/src/types/plugins.ts +150 -0
  122. package/src/types/roleDefaults.ts +132 -0
  123. package/src/types/stats.ts +195 -0
  124. package/src/types/stripe.ts +45 -0
  125. package/src/types/utils.ts +100 -0
  126. package/src/zod.ts +1 -0
@@ -0,0 +1,546 @@
1
+ import type { ReadableStream } from 'node:stream/web';
2
+ import { z, ZodString, type ZodType } from 'zod';
3
+ import {
4
+ accessTokenCapabilities,
5
+ accessTokenRelationships,
6
+ profileCapabilities,
7
+ profileRelationships,
8
+ reportCapabilities,
9
+ reportRelationships,
10
+ } from './capabilities';
11
+ import { postCapabilities } from './capabilities';
12
+ import { postRelationships } from './capabilities';
13
+
14
+ export const passwordPlaceHolder = '*********';
15
+
16
+ export const password = (sanitize?: boolean) =>
17
+ sanitize
18
+ ? z
19
+ .string()
20
+ .transform(() => passwordPlaceHolder)
21
+ .describe('password')
22
+ : z.string();
23
+
24
+ export const fixed = <T extends ZodType>(type: T, sanitize?: boolean): T =>
25
+ (sanitize ? type.describe('fixed') : type) as T;
26
+
27
+ export const hidden = <T extends ZodType>(type: T): T =>
28
+ type.describe('hidden') as T;
29
+
30
+ export const longText = (type: ZodString) => type.describe('longText');
31
+
32
+ export const mediaStorageParamsSchema = z.object({
33
+ path: z.string(),
34
+ prefix: z.string(),
35
+ host: z.string().optional(),
36
+ });
37
+ export type MediaStorageParams = z.infer<typeof mediaStorageParamsSchema>;
38
+
39
+ /** MiB. 1024 is 1 GiB — the default shown in the admin media section. */
40
+ export const DEFAULT_MAX_MEDIA_UPLOAD_MB = 1024;
41
+
42
+ export const mediaUploadLimitBytes = (maxUploadMb: number) => {
43
+ const mb =
44
+ Number.isInteger(maxUploadMb) && maxUploadMb >= 1
45
+ ? maxUploadMb
46
+ : DEFAULT_MAX_MEDIA_UPLOAD_MB;
47
+ return mb * 1024 * 1024;
48
+ };
49
+
50
+ export const stripePaymentConfigSchema = (sanitize?: boolean) =>
51
+ z.object({
52
+ paidMembership: z
53
+ .object({
54
+ enabled: z.boolean(),
55
+ productId: z.string().optional(),
56
+ trialPeriodDays: z.number().optional(),
57
+ })
58
+ .optional(),
59
+ publishableKey: password(sanitize).optional(),
60
+ secretKey: password(sanitize).optional(),
61
+ webhookSecret: password(sanitize).optional(),
62
+ });
63
+ export type StripePaymentConfig = z.infer<
64
+ ReturnType<typeof stripePaymentConfigSchema>
65
+ >;
66
+
67
+ export const emailConfigSchemaFactory = (sanitize?: boolean) =>
68
+ z.object({
69
+ service: z.string(),
70
+ defaultTemplatePath: z.string(),
71
+ defaultFrom: z.string().optional(),
72
+ transportConfig: z.object({
73
+ host: z.string(),
74
+ port: z.number(),
75
+ secure: z.boolean().default(true),
76
+ // Optional so unauthenticated SMTP (e.g. Mailpit) can omit credentials.
77
+ auth: z
78
+ .object({
79
+ user: z.string().optional(),
80
+ pass: password(sanitize).optional(),
81
+ })
82
+ .optional(),
83
+ }),
84
+ });
85
+
86
+ export const emailConfigSchema = emailConfigSchemaFactory(false);
87
+ export const emailConfigSanitizedSchema = emailConfigSchemaFactory(true);
88
+ export type EmailConfig = z.infer<typeof emailConfigSchema>;
89
+
90
+ export type ConfigValue = string | number | boolean | undefined;
91
+ export interface ConfigTree {
92
+ [key: string]:
93
+ | ConfigTree
94
+ | ConfigValue
95
+ | (ConfigTree | undefined)[]
96
+ | (ConfigValue | undefined)[];
97
+ }
98
+ export type ConfigElement =
99
+ | ConfigTree
100
+ | ConfigValue
101
+ | (ConfigTree | undefined)[]
102
+ | (ConfigValue | undefined)[];
103
+ export type ConfigSchemaFactory<T> = (sanitize?: boolean) => ZodType<T>;
104
+
105
+ export interface ConfigSchema<T> {
106
+ factory: ConfigSchemaFactory<T>;
107
+ defaults: T;
108
+ }
109
+
110
+ export const coreConfigSchemaFactory = (sanitize?: boolean) =>
111
+ z.object({
112
+ version: fixed(z.string(), sanitize),
113
+ environment: fixed(z.string(), sanitize),
114
+ server: z.object({
115
+ host: z.string(),
116
+ signUpsOpen: z.boolean(),
117
+ publicContent: z.boolean(),
118
+ /** Cap on non-deleted profiles; 0 / unset = unlimited. Env-only (not admin-editable). */
119
+ maxProfiles: fixed(z.number().int().nonnegative().optional(), sanitize),
120
+ }),
121
+ db: fixed(
122
+ z.object({
123
+ // Optional legacy fields so older stored configs still parse.
124
+ url: z.string().url().optional(),
125
+ databaseName: z.string().optional(),
126
+ databaseUrl: z.string(),
127
+ }),
128
+ sanitize,
129
+ ),
130
+ redis: fixed(
131
+ z.object({
132
+ host: z.string(),
133
+ }),
134
+ sanitize,
135
+ ),
136
+ email: emailConfigSchemaFactory(sanitize).describe('hidden'),
137
+ logs: fixed(
138
+ z.object({
139
+ local: fixed(
140
+ z.object({
141
+ path: z.string(),
142
+ }),
143
+ sanitize,
144
+ ),
145
+ }),
146
+ sanitize,
147
+ ),
148
+ media: z.object({
149
+ maxUploadMb: z
150
+ .number()
151
+ .int()
152
+ .min(1)
153
+ .default(DEFAULT_MAX_MEDIA_UPLOAD_MB)
154
+ .catch(DEFAULT_MAX_MEDIA_UPLOAD_MB),
155
+ storage: z.object({
156
+ driver: z.enum(['openpeeps']),
157
+ params: mediaStorageParamsSchema,
158
+ }),
159
+ }),
160
+ network: z.object({
161
+ port: z.number(),
162
+ }),
163
+ plugins: z.object({
164
+ path: z.string(),
165
+ rootPackageJsonPath: z.string(),
166
+ }),
167
+ secrets: z.object({
168
+ jwt: password(sanitize),
169
+ }),
170
+ jams: z.object({
171
+ livekit: z.object({
172
+ url: z.string(),
173
+ apiKey: z.string().optional(),
174
+ apiSecret: password(sanitize).optional(),
175
+ recordingEnabled: z.boolean().optional(),
176
+ }),
177
+ }),
178
+ vapid: z.object({
179
+ privateKey: password(sanitize).optional(),
180
+ publicKey: z.string().optional(),
181
+ }),
182
+ federation: z.object({
183
+ active: z.boolean(),
184
+ /** Host patterns (`mastodon.social`, `*.example.com`). Empty = fail closed. */
185
+ allowedHosts: z.array(z.string()).default([]),
186
+ }),
187
+ activityPub: z.object({
188
+ defaultDomain: z.string(),
189
+ itemsPerPage: z.number(),
190
+ threadDepth: z.number(),
191
+ federation: z.object({
192
+ requestTimeout: z.number(),
193
+ }),
194
+ }),
195
+ sso: z
196
+ .object({
197
+ onlySSO: z.boolean().optional(),
198
+ generic: z
199
+ .object({
200
+ id: z.string().default('example-generic'),
201
+ name: z.string().default('Generic SSO'),
202
+ /** URL or path shown on the login page to start this provider's flow. */
203
+ loginLink: z.string().optional(),
204
+ userProfileRequest: z.object({
205
+ url: z.string(),
206
+ authHeader: z.string().optional(),
207
+ }),
208
+ userProfilePaths: z.object({
209
+ email: z.string(),
210
+ handle: z.string().optional(),
211
+ avatar: z.string().optional(),
212
+ displayName: z.string().optional(),
213
+ }),
214
+ createAccounts: z.boolean().optional(),
215
+ createProfiles: z.boolean().optional(),
216
+ })
217
+ .default({
218
+ id: 'example-generic',
219
+ name: 'Generic SSO',
220
+ loginLink: '',
221
+ userProfileRequest: {
222
+ url: 'https://example.com/profile',
223
+ authHeader: 'Bearer ${token}',
224
+ },
225
+ userProfilePaths: {
226
+ email: '$.data.account.email',
227
+ },
228
+ createAccounts: true,
229
+ createProfiles: true,
230
+ })
231
+ .array(),
232
+ oidc: z
233
+ .object({
234
+ id: z.string(),
235
+ name: z.string(),
236
+ kind: z
237
+ .enum([
238
+ 'oidc',
239
+ 'github',
240
+ 'gitlab',
241
+ 'gitlab-selfhosted',
242
+ 'google',
243
+ 'entra',
244
+ 'auth0',
245
+ 'keycloak',
246
+ 'authentik',
247
+ 'okta',
248
+ 'discord',
249
+ 'pocketid',
250
+ ])
251
+ .optional(),
252
+ instanceUrl: z.string().optional(),
253
+ tenant: z.string().optional(),
254
+ authorizationUrl: z.string(),
255
+ tokenUrl: z.string(),
256
+ userinfoUrl: z.string(),
257
+ emailsUrl: z.string().optional(),
258
+ jwksUri: z.string().optional(),
259
+ clientId: z.string(),
260
+ clientSecret: password(sanitize).optional(),
261
+ scope: z.string().optional(),
262
+ claimMapping: z
263
+ .object({
264
+ email: z.string().optional(),
265
+ handle: z.string().optional(),
266
+ displayName: z.string().optional(),
267
+ avatar: z.string().optional(),
268
+ })
269
+ .optional(),
270
+ approvalRequired: z.boolean().optional(),
271
+ })
272
+ .default({
273
+ id: 'example-oidc',
274
+ name: 'OIDC Provider',
275
+ kind: 'oidc',
276
+ authorizationUrl: 'https://example.com/authorize',
277
+ tokenUrl: 'https://example.com/token',
278
+ userinfoUrl: 'https://example.com/userinfo',
279
+ clientId: '',
280
+ scope: 'openid email profile',
281
+ claimMapping: {
282
+ email: 'email',
283
+ handle: 'preferred_username',
284
+ displayName: 'name',
285
+ avatar: 'picture',
286
+ },
287
+ approvalRequired: false,
288
+ })
289
+ .array(),
290
+ })
291
+ .describe('hidden'),
292
+ services: z.object({
293
+ sentry: z.object({
294
+ enabled: z.boolean(),
295
+ dsn: z.string().optional(),
296
+ replayEnabled: z.boolean().optional(),
297
+ }),
298
+ location: z.object({
299
+ type: z.string(),
300
+ url: z.string(),
301
+ apiKey: password(sanitize).optional(),
302
+ }),
303
+ }),
304
+ apps: z.object({
305
+ ios: z.object({
306
+ url: z.string().optional(),
307
+ bundleIdentifier: z.string().optional(),
308
+ teamId: z.string().optional(),
309
+ appId: z.string().optional(),
310
+ apnKeyId: z.string().optional(),
311
+ apnSigningKey: longText(z.string()).optional(),
312
+ }),
313
+ android: z.object({
314
+ url: z.string().optional(),
315
+ packageName: z.string().optional(),
316
+ appId: z.string().optional(),
317
+ fcmCredentials: longText(z.string()).optional(),
318
+ }),
319
+ }),
320
+ payments: z.object({
321
+ stripe: stripePaymentConfigSchema(sanitize),
322
+ }),
323
+ });
324
+
325
+ export const coreConfigSchema = coreConfigSchemaFactory(false);
326
+ export const coreConfigSanitizedSchema = coreConfigSchemaFactory(true);
327
+ export type CoreConfig = z.infer<typeof coreConfigSchema>;
328
+
329
+ /** Community-configured member profile fields (`profiles.additionalFields`). */
330
+ export const communityProfileAdditionalFieldSchema = z.object({
331
+ // Trim so whitespace-only keys fail the same as "".
332
+ key: z.string().trim().min(1),
333
+ label: z.string(),
334
+ icon: z.string().optional(),
335
+ linkPattern: z.string().optional(),
336
+ });
337
+ export type CommunityProfileAdditionalField = z.infer<
338
+ typeof communityProfileAdditionalFieldSchema
339
+ >;
340
+
341
+ export const communityConfigSchemaFactory = (_sanitize?: boolean) =>
342
+ z.object({
343
+ theme: z.object({
344
+ base: z.string(),
345
+ icon: z.string().optional(),
346
+ mobileIcon: z.string().optional(),
347
+ // Kept so /server/info still satisfies common 0.1.44 (required
348
+ // theme.primaryHex) and RN 0.3.1 root-theme reads.
349
+ primaryHex: z.string().optional(),
350
+ logoFull: z.string().optional(),
351
+ logoSmall: z.string().optional(),
352
+ defaultProfileAvatar: z.string().optional(),
353
+ defaultGroupAvatar: z.string().optional(),
354
+ backgroundAuth: z.string().optional(),
355
+ background: z.string().optional(),
356
+ light: z.object({
357
+ primaryHex: z.string(),
358
+ secondaryHex: z.string().optional(),
359
+ fontFamily: z.string().optional(),
360
+ buttonRadius: z.string().optional(),
361
+ radius: z.string().optional(),
362
+ logoSmall: z.string().optional(),
363
+ defaultProfileAvatar: z.string().optional(),
364
+ defaultGroupAvatar: z.string().optional(),
365
+ backgroundAuth: z.string().optional(),
366
+ background: z.string().optional(),
367
+ }),
368
+ dark: z.object({
369
+ primaryHex: z.string(),
370
+ secondaryHex: z.string().optional(),
371
+ fontFamily: z.string().optional(),
372
+ buttonRadius: z.string().optional(),
373
+ radius: z.string().optional(),
374
+ logoSmall: z.string().optional(),
375
+ defaultProfileAvatar: z.string().optional(),
376
+ defaultGroupAvatar: z.string().optional(),
377
+ backgroundAuth: z.string().optional(),
378
+ background: z.string().optional(),
379
+ }),
380
+ }),
381
+ profiles: z
382
+ .object({
383
+ additionalFields: z
384
+ .array(communityProfileAdditionalFieldSchema)
385
+ .optional(),
386
+ })
387
+ .optional(),
388
+ info: z.object({
389
+ name: z.string(),
390
+ tagLine: z.string(),
391
+ contactEmail: z.string().email().optional(),
392
+ privacyPolicy: z.string().optional(),
393
+ termsAndConditions: z.string().optional(),
394
+ }),
395
+ content: z.object({
396
+ aboutPage: z.string().optional(),
397
+ welcomePage: z.string().optional(),
398
+ codeOfConduct: z.string().optional(),
399
+ welcomeEmail: z.string().optional(),
400
+ pinnedPost: z.string().optional(),
401
+ }),
402
+ settings: z.object({
403
+ openRegistrations: z.boolean(),
404
+ defaultLanguage: z.string().optional(),
405
+ defaultTimeZone: z.string().optional(),
406
+ defaultFeedFormat: z.enum(['threaded', 'linear']).optional(),
407
+ /** Adds member profile pages to the sitemap. Off by default: a crawled
408
+ * profile is cached by search engines long after the member leaves. */
409
+ indexProfiles: z.boolean().optional(),
410
+ }),
411
+ roles: z.object({
412
+ onRegistration: z.object({
413
+ add: z.string().array(),
414
+ remove: z.string().array(),
415
+ }),
416
+ onEmailValidation: z.object({
417
+ add: z.string().array(),
418
+ remove: z.string().array(),
419
+ }),
420
+ }),
421
+ });
422
+ export const communityConfigSchema = communityConfigSchemaFactory(false);
423
+ export const communityConfigSanitizedSchema =
424
+ communityConfigSchemaFactory(true);
425
+ export type CommunityConfig = z.infer<typeof communityConfigSchema>;
426
+
427
+ const addWildCardOptions = (
428
+ capabilities: [string, ...string[]],
429
+ ): [string, ...string[]] => {
430
+ const wildCard = '*';
431
+ const firstLevelCategories = new Set(
432
+ capabilities.map((capability) => capability.split('-')[0]),
433
+ );
434
+ const secondLevelCategories = [...firstLevelCategories].map(
435
+ (flc) =>
436
+ new Set(
437
+ capabilities
438
+ .map((c) => c.split('-'))
439
+ .filter((clist) => clist[0] === flc)
440
+ .map((clist) => `${flc}-${clist[1]}`),
441
+ ),
442
+ );
443
+ return [
444
+ wildCard,
445
+ ...capabilities,
446
+ [...firstLevelCategories].map((flc) => `${flc}-${wildCard}`),
447
+ [...secondLevelCategories].flatMap((slc) => [
448
+ ...slc,
449
+ ...[...slc].map((key) => `${key}-${wildCard}`),
450
+ ]),
451
+ ].flat() as [string, ...string[]];
452
+ };
453
+
454
+ export const capabilitiesSchema = z
455
+ .object({
456
+ add: z.string().array().optional(),
457
+ remove: z.string().array().optional(),
458
+ })
459
+ .optional();
460
+ export type Capabilities = z.infer<typeof capabilitiesSchema>;
461
+
462
+ const capabilitiesGroupSchema = <C extends string>(capabilities: [C, ...C[]]) =>
463
+ z
464
+ .object({
465
+ add: z
466
+ .array(z.enum(addWildCardOptions(capabilities)))
467
+ .optional()
468
+ .default([]),
469
+ remove: z
470
+ .array(z.enum(addWildCardOptions(capabilities)))
471
+ .optional()
472
+ .default([]),
473
+ })
474
+ .optional()
475
+ .default({ add: [], remove: [] });
476
+
477
+ const relationshipsGroupSchema = <
478
+ R extends readonly string[],
479
+ C extends string,
480
+ >(
481
+ relationships: R,
482
+ capabilities: [C, ...C[]],
483
+ ) =>
484
+ z.object(
485
+ Object.fromEntries(
486
+ relationships.map((relationship) => [
487
+ relationship,
488
+ capabilitiesGroupSchema(capabilities),
489
+ ]),
490
+ ),
491
+ );
492
+
493
+ export const capabilitiesConfigSchema = z.object({
494
+ post: relationshipsGroupSchema(postRelationships, [...postCapabilities]),
495
+ profile: relationshipsGroupSchema(profileRelationships, [
496
+ ...profileCapabilities,
497
+ ...postCapabilities,
498
+ ]),
499
+ report: relationshipsGroupSchema(reportRelationships, [
500
+ ...reportCapabilities,
501
+ ]),
502
+ accessToken: relationshipsGroupSchema(accessTokenRelationships, [
503
+ ...accessTokenCapabilities,
504
+ ]),
505
+ });
506
+ export const capabilitiesConfigSchemaFactory = (_sanitize?: boolean) =>
507
+ z.object({
508
+ post: relationshipsGroupSchema(postRelationships, [...postCapabilities]),
509
+ profile: relationshipsGroupSchema(profileRelationships, [
510
+ ...profileCapabilities,
511
+ ...postCapabilities,
512
+ ]),
513
+ report: relationshipsGroupSchema(reportRelationships, [
514
+ ...reportCapabilities,
515
+ ]),
516
+ accessToken: relationshipsGroupSchema(accessTokenRelationships, [
517
+ ...accessTokenCapabilities,
518
+ ]),
519
+ });
520
+ export type CapabilitiesConfig = z.infer<typeof capabilitiesConfigSchema>;
521
+ export type CapabilitiesConfigInput = z.input<typeof capabilitiesConfigSchema>;
522
+
523
+ export interface MediaStorage {
524
+ store: (data: ArrayBuffer | SharedArrayBuffer) => Promise<string>;
525
+ /**
526
+ * Stream-based variant of {@link MediaStorage.store}. Consumes the given
527
+ * web `ReadableStream`, hashes its bytes while writing them straight to disk,
528
+ * and resolves to the resulting content-addressed key plus the byte count
529
+ * that was actually written. This avoids buffering the full payload in
530
+ * memory before persisting it, which matters for large media uploads.
531
+ *
532
+ * The chunk type is intentionally untyped here: the DOM lib's
533
+ * `ReadableStream<Uint8Array>` and `node:stream/web`'s ditto are
534
+ * structurally identical at runtime but TypeScript treats them as
535
+ * incompatible, so leaving the chunk type open keeps both call sites
536
+ * — `File.stream()` in the request handler and `Readable.fromWeb` in the
537
+ * Node implementation — assignable without explicit casts at the boundary.
538
+ */
539
+ storeStream: (
540
+ stream: ReadableStream,
541
+ ) => Promise<{ key: string; size: number }>;
542
+ getPath: (id: string, filename: string) => string;
543
+ getStream: (id: string) => Promise<ReadableStream>;
544
+ getData: (id: string) => Promise<ArrayBuffer | SharedArrayBuffer>;
545
+ isLocal: () => boolean;
546
+ }
@@ -0,0 +1,138 @@
1
+ import { z } from 'zod';
2
+ import {
3
+ answerSchema,
4
+ Entry,
5
+ Group,
6
+ Hashtag,
7
+ hashtagSchema,
8
+ MentionData,
9
+ mentionDataSchema,
10
+ Notification,
11
+ notificationSchema,
12
+ Post,
13
+ PostDataUnion,
14
+ postDataUnionSchema,
15
+ postSchema,
16
+ Profile,
17
+ profileSchema,
18
+ ReactionData,
19
+ reactionDataSchema,
20
+ rsvpSchema,
21
+ } from './models';
22
+ import { GroupWithMeta, groupWithMetaSchema } from './internal';
23
+
24
+ export const dbNotificationSchema = notificationSchema.extend({
25
+ post: postSchema.nullable().optional(),
26
+ });
27
+ export type DbNotification = Notification & {
28
+ post?: DbPost | null;
29
+ group?: Group | null;
30
+ };
31
+
32
+ const entryWithProfileSchema = z.discriminatedUnion('type', [
33
+ z.object({
34
+ type: z.literal('create'),
35
+ data: postDataUnionSchema,
36
+ profile: profileSchema,
37
+ createdAt: z.string().datetime(),
38
+ }),
39
+ z.object({
40
+ type: z.literal('edit'),
41
+ data: postDataUnionSchema,
42
+ profile: profileSchema,
43
+ createdAt: z.string().datetime(),
44
+ }),
45
+ z.object({
46
+ type: z.literal('delete'),
47
+ data: z.any(),
48
+ profile: profileSchema,
49
+ createdAt: z.string().datetime(),
50
+ }),
51
+ z.object({
52
+ type: z.literal('answer'),
53
+ data: answerSchema,
54
+ profile: profileSchema,
55
+ createdAt: z.string().datetime(),
56
+ }),
57
+ z.object({
58
+ type: z.literal('rsvp'),
59
+ data: rsvpSchema,
60
+ profile: profileSchema,
61
+ createdAt: z.string().datetime(),
62
+ }),
63
+ z.object({
64
+ type: z.literal('reaction'),
65
+ data: z.object({ reaction: z.string().min(1) }),
66
+ uri: z.string().url().optional(),
67
+ profile: profileSchema,
68
+ createdAt: z.string().datetime(),
69
+ }),
70
+ z.object({
71
+ type: z.literal('unreaction'),
72
+ data: z.object({ reaction: z.string().min(1) }),
73
+ uri: z.string().url().optional(),
74
+ profile: profileSchema,
75
+ createdAt: z.string().datetime(),
76
+ }),
77
+ ]);
78
+ export type DbEntry = Entry & { profile: Profile };
79
+
80
+ const mentionWithProfileSchema = mentionDataSchema.extend({
81
+ profile: profileSchema,
82
+ });
83
+ export type DbMention = MentionData & { profile: Profile };
84
+
85
+ const reactionWithProfileSchema = reactionDataSchema.extend({
86
+ profile: profileSchema,
87
+ });
88
+ export type DbReaction = ReactionData & { profile: Profile };
89
+
90
+ export const dbBasePostSchema = postSchema.extend({
91
+ entries: entryWithProfileSchema.array(),
92
+ audience: profileSchema.array(),
93
+ group: groupWithMetaSchema,
94
+ mentions: mentionWithProfileSchema.array(),
95
+ replyCount: z.number(),
96
+ repostCount: z.number(),
97
+ reactions: reactionWithProfileSchema.array(),
98
+ tags: hashtagSchema.array(),
99
+ profile: profileSchema,
100
+ data: postDataUnionSchema,
101
+ groupId: z.string().nullable().optional(),
102
+ seen: z.boolean().optional(),
103
+ });
104
+
105
+ export interface DbBasePost extends Post {
106
+ entries: DbEntry[];
107
+ audience: Profile[];
108
+ group: GroupWithMeta;
109
+ mentions: DbMention[];
110
+ replyCount: number;
111
+ repostCount: number;
112
+ reactions: DbReaction[];
113
+ /** Inbound repost wrappers (lean mapping: entries only) before transform. */
114
+ reposts?: DbBasePost[];
115
+ /** Newest conversation descendants (lean mapping: entries only) before transform. */
116
+ latestReplies?: DbBasePost[];
117
+ latestRepliesHasMore?: boolean;
118
+ lastActivityAt?: string;
119
+ tags: Hashtag[];
120
+ profile: Profile;
121
+ data: PostDataUnion;
122
+ groupId: string | null | undefined;
123
+ seen?: boolean;
124
+ }
125
+
126
+ export const dbPostWithReplySchema = dbBasePostSchema.extend({
127
+ replyTo: dbBasePostSchema.nullable().optional(),
128
+ inReplyToId: z.string().nullable().optional(),
129
+ });
130
+
131
+ export const dbPostSchema = dbPostWithReplySchema.extend({
132
+ repost: dbPostWithReplySchema.nullable().optional(),
133
+ });
134
+ export interface DbPost extends DbBasePost {
135
+ replyTo?: DbBasePost | null;
136
+ repost?: DbPost | null;
137
+ inReplyToId?: string | null;
138
+ }
@@ -0,0 +1,10 @@
1
+ import { z } from 'zod';
2
+ import { publicAccountSchema, publicProfileSchema } from './api';
3
+
4
+ /** Data a user can download as their account export. */
5
+ export const accountExportSchema = z.object({
6
+ account: publicAccountSchema,
7
+ profiles: publicProfileSchema.array(),
8
+ });
9
+
10
+ export type AccountExport = z.infer<typeof accountExportSchema>;
@@ -0,0 +1,20 @@
1
+ export * from './models';
2
+ export * from './roleDefaults';
3
+ export * from './export';
4
+ export * from './apple-app-site-association';
5
+ export * from './capabilities';
6
+ export * from './api';
7
+ export * from './plugins';
8
+ export * from './internal';
9
+ export * from './utils';
10
+ export * from './config';
11
+ export * from './auth';
12
+ export * from './stats';
13
+ export * from './analytics';
14
+ export * from './notifications';
15
+ export * from './stripe';
16
+ export * from './db';
17
+ export * from './admin-email';
18
+ export * from './admin-jobs';
19
+ export * from './admin-db';
20
+ export * from './admin-performance';