@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.
- package/dist/lib/adminSections.js +1 -1
- package/dist/lib/capabilitiesHelpers.d.ts +9 -7
- package/dist/lib/capabilitiesHelpers.js +43 -38
- package/dist/lib/csvHelpers.js +1 -1
- package/dist/lib/eventIcs.d.ts +17 -0
- package/dist/lib/eventIcs.js +91 -15
- package/dist/lib/eventRecurrence.d.ts +19 -0
- package/dist/lib/eventRecurrence.js +82 -20
- package/dist/lib/eventTime.d.ts +7 -0
- package/dist/lib/eventTime.js +23 -9
- package/dist/lib/federationHosts.d.ts +3 -0
- package/dist/lib/federationHosts.js +17 -0
- package/dist/lib/feedCursor.d.ts +14 -0
- package/dist/lib/feedCursor.js +22 -0
- package/dist/lib/feedFormat.d.ts +12 -0
- package/dist/lib/feedFormat.js +14 -0
- package/dist/lib/groupHelpers.js +13 -34
- package/dist/lib/groupTemplateHelpers.js +6 -10
- package/dist/lib/index.d.ts +7 -0
- package/dist/lib/index.js +7 -0
- package/dist/lib/jamHelpers.d.ts +11 -2
- package/dist/lib/jamHelpers.js +43 -9
- package/dist/lib/legacyThemeRoot.d.ts +3 -0
- package/dist/lib/legacyThemeRoot.js +10 -0
- package/dist/lib/markdownHelpers.d.ts +8 -0
- package/dist/lib/markdownHelpers.js +34 -6
- package/dist/lib/postHelpers.d.ts +142 -3
- package/dist/lib/postHelpers.js +323 -47
- package/dist/lib/profileHelpers.d.ts +11 -0
- package/dist/lib/profileHelpers.js +34 -10
- package/dist/lib/pushHelpers.js +3 -4
- package/dist/lib/reactions.d.ts +17 -0
- package/dist/lib/reactions.js +37 -0
- package/dist/lib/scopeHelpers.d.ts +31 -2
- package/dist/lib/scopeHelpers.js +39 -8
- package/dist/lib/ssoLoginUrl.js +4 -6
- package/dist/lib/ssoProviders.d.ts +72 -0
- package/dist/lib/ssoProviders.js +366 -0
- package/dist/lib/timeZone.d.ts +9 -0
- package/dist/lib/timeZone.js +44 -0
- package/dist/lib/tokenHelpers.js +5 -5
- package/dist/lib/utils.js +6 -7
- package/dist/types/admin-db.js +1 -1
- package/dist/types/analytics.d.ts +20 -0
- package/dist/types/analytics.js +4 -0
- package/dist/types/api.d.ts +41800 -11853
- package/dist/types/api.js +53 -5
- package/dist/types/auth.d.ts +20 -6
- package/dist/types/capabilities.d.ts +15 -1
- package/dist/types/capabilities.js +51 -0
- package/dist/types/config.d.ts +99 -0
- package/dist/types/config.js +56 -4
- package/dist/types/db.d.ts +1155 -164
- package/dist/types/db.js +14 -0
- package/dist/types/export.d.ts +120 -0
- package/dist/types/export.js +7 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +2 -0
- package/dist/types/internal.d.ts +2577 -524
- package/dist/types/internal.js +6 -0
- package/dist/types/models.d.ts +63 -7
- package/dist/types/models.js +40 -3
- package/dist/types/plugins.d.ts +22 -0
- package/dist/types/plugins.js +66 -0
- package/dist/types/roleDefaults.d.ts +31 -0
- package/dist/types/roleDefaults.js +110 -0
- package/dist/types/stats.d.ts +54606 -6065
- package/dist/types/stats.js +30 -0
- package/dist/types/utils.d.ts +2 -0
- package/dist/types/utils.js +1 -3
- package/dist/zod.d.ts +1 -0
- package/dist/zod.js +1 -0
- package/package.json +36 -6
- package/src/index.ts +4 -0
- package/src/lib/adminSections.ts +84 -0
- package/src/lib/attachmentHelpers.ts +14 -0
- package/src/lib/capabilitiesHelpers.ts +532 -0
- package/src/lib/colors.ts +20 -0
- package/src/lib/csvHelpers.ts +31 -0
- package/src/lib/eventIcs.ts +265 -0
- package/src/lib/eventRecurrence.ts +495 -0
- package/src/lib/eventTime.ts +206 -0
- package/src/lib/federationHosts.ts +22 -0
- package/src/lib/feedCursor.ts +27 -0
- package/src/lib/feedFormat.ts +24 -0
- package/src/lib/groupHelpers.ts +421 -0
- package/src/lib/groupTemplateHelpers.ts +83 -0
- package/src/lib/index.ts +29 -0
- package/src/lib/jamHelpers.ts +164 -0
- package/src/lib/legacyThemeRoot.ts +14 -0
- package/src/lib/markdownHelpers.ts +122 -0
- package/src/lib/mediaDimensions.ts +21 -0
- package/src/lib/postHelpers.ts +783 -0
- package/src/lib/profileHelpers.ts +220 -0
- package/src/lib/pushHelpers.ts +34 -0
- package/src/lib/reactions.ts +52 -0
- package/src/lib/reportHelpers.ts +7 -0
- package/src/lib/scopeHelpers.ts +176 -0
- package/src/lib/ssoLoginUrl.ts +93 -0
- package/src/lib/ssoProviders.ts +472 -0
- package/src/lib/text.ts +26 -0
- package/src/lib/timeZone.ts +52 -0
- package/src/lib/tokenHelpers.ts +119 -0
- package/src/lib/utils.ts +322 -0
- package/src/types/admin-db.ts +74 -0
- package/src/types/admin-email.ts +55 -0
- package/src/types/admin-jobs.ts +17 -0
- package/src/types/admin-performance.ts +20 -0
- package/src/types/analytics.ts +318 -0
- package/src/types/api.ts +871 -0
- package/src/types/apple-app-site-association.ts +54 -0
- package/src/types/auth.ts +22 -0
- package/src/types/capabilities.ts +280 -0
- package/src/types/config.ts +546 -0
- package/src/types/db.ts +138 -0
- package/src/types/export.ts +10 -0
- package/src/types/index.ts +20 -0
- package/src/types/internal.ts +338 -0
- package/src/types/models.ts +939 -0
- package/src/types/notifications.ts +92 -0
- package/src/types/plugins.ts +150 -0
- package/src/types/roleDefaults.ts +132 -0
- package/src/types/stats.ts +195 -0
- package/src/types/stripe.ts +45 -0
- package/src/types/utils.ts +100 -0
- package/src/zod.ts +1 -0
|
@@ -0,0 +1,939 @@
|
|
|
1
|
+
import { z, util, ZodObject, ZodRawShape } from 'zod';
|
|
2
|
+
import validator from 'validator';
|
|
3
|
+
import ISO6391 from 'iso-639-1';
|
|
4
|
+
import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi';
|
|
5
|
+
import { groupRelationships } from './capabilities';
|
|
6
|
+
import { capabilitiesSchema } from './config';
|
|
7
|
+
|
|
8
|
+
extendZodWithOpenApi(z);
|
|
9
|
+
|
|
10
|
+
export const handleRegexBase = '[a-zA-Z0-9_-]{1,16}';
|
|
11
|
+
|
|
12
|
+
export const handleRegex = new RegExp(`^${handleRegexBase}$`);
|
|
13
|
+
|
|
14
|
+
/** `@handle` using the allowed handle charset. No `\\b` — hyphens are not word chars. */
|
|
15
|
+
export const mentionHandleRegexBase = `(^|[\\s(>])@(${handleRegexBase})(?=\\s|$|[.,!?;:])`;
|
|
16
|
+
|
|
17
|
+
export const forbiddenHandles = [
|
|
18
|
+
'admin',
|
|
19
|
+
'allpeep',
|
|
20
|
+
'api',
|
|
21
|
+
'app',
|
|
22
|
+
'auth',
|
|
23
|
+
'config',
|
|
24
|
+
'core',
|
|
25
|
+
'db',
|
|
26
|
+
'email',
|
|
27
|
+
'federation',
|
|
28
|
+
'jam',
|
|
29
|
+
'media',
|
|
30
|
+
'network',
|
|
31
|
+
'plugins',
|
|
32
|
+
'undefined',
|
|
33
|
+
'jamStarted',
|
|
34
|
+
'jamSpeaker',
|
|
35
|
+
'jamModerator',
|
|
36
|
+
'new',
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
export const baseSchemaShape = {
|
|
40
|
+
createdAt: z.iso.datetime(),
|
|
41
|
+
updatedAt: z.iso.datetime(),
|
|
42
|
+
deletedAt: z.iso.datetime().nullable().optional(),
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const baseSchema = z.object(baseSchemaShape);
|
|
46
|
+
export type Base<T> = z.infer<typeof baseSchema> & T;
|
|
47
|
+
|
|
48
|
+
export const idSchemaShape = {
|
|
49
|
+
id: z.uuid(),
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const idSchema = z.object(idSchemaShape);
|
|
53
|
+
export type Id = z.infer<typeof idSchema>;
|
|
54
|
+
|
|
55
|
+
const modelBaseFields = {
|
|
56
|
+
...baseSchemaShape,
|
|
57
|
+
...idSchemaShape,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Preserves the data-schema shape through declaration emit (see ZodObject extend typing).
|
|
62
|
+
* A non-generic parameter used to widen `ZodObject<ZodRawShape>` destroys output `.d.ts`
|
|
63
|
+
* (index signature + unknown), which breaks consumers that need structural JSON types.
|
|
64
|
+
*/
|
|
65
|
+
export const modelSchema = <T extends ZodRawShape>(
|
|
66
|
+
dataSchema: ZodObject<T>,
|
|
67
|
+
): ZodObject<util.Extend<T, util.Writeable<typeof modelBaseFields>>> =>
|
|
68
|
+
dataSchema.extend(modelBaseFields);
|
|
69
|
+
|
|
70
|
+
export type Model<T> = Base<T> & { id: string };
|
|
71
|
+
|
|
72
|
+
const connectionSchema = <
|
|
73
|
+
T extends ZodRawShape,
|
|
74
|
+
TFrom extends ZodRawShape,
|
|
75
|
+
TTo extends ZodRawShape,
|
|
76
|
+
>(
|
|
77
|
+
dataSchema: ZodObject<T>,
|
|
78
|
+
from: ZodObject<TFrom>,
|
|
79
|
+
to: ZodObject<TTo>,
|
|
80
|
+
) =>
|
|
81
|
+
modelSchema(dataSchema).extend({
|
|
82
|
+
from,
|
|
83
|
+
to,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
export const applicationDataSchema = z.object({
|
|
87
|
+
id: z.string(),
|
|
88
|
+
secret: z.string(),
|
|
89
|
+
name: z.string(),
|
|
90
|
+
website: z.string(),
|
|
91
|
+
});
|
|
92
|
+
export type ApplicationData = z.infer<typeof applicationDataSchema>;
|
|
93
|
+
export type Application = Model<ApplicationData>;
|
|
94
|
+
|
|
95
|
+
export const accountDataSchema = z.object({
|
|
96
|
+
email: z.string().email(),
|
|
97
|
+
passwordHash: z.string(),
|
|
98
|
+
emailValidated: z.boolean().default(false).optional(),
|
|
99
|
+
guest: z.boolean().optional(),
|
|
100
|
+
});
|
|
101
|
+
export type AccountData = z.infer<typeof accountDataSchema>;
|
|
102
|
+
export const accountSchema = modelSchema(accountDataSchema);
|
|
103
|
+
export type Account = Model<AccountData>;
|
|
104
|
+
|
|
105
|
+
export const roleDataSchema = z.object({
|
|
106
|
+
key: z.string().regex(/^[a-z-]{1,32}$/),
|
|
107
|
+
default: z.boolean(),
|
|
108
|
+
/** Defaults history version the role's capabilities were based on. */
|
|
109
|
+
baseVersion: z.string().optional(),
|
|
110
|
+
displayName: z.string().max(32),
|
|
111
|
+
description: z.string().optional(),
|
|
112
|
+
capabilities: capabilitiesSchema,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
export type RoleData = z.infer<typeof roleDataSchema>;
|
|
116
|
+
export const roleSchema = modelSchema(roleDataSchema);
|
|
117
|
+
export type Role = Model<RoleData>;
|
|
118
|
+
|
|
119
|
+
export const profileSettingsDefaultsSchema = z.object({
|
|
120
|
+
privacy: z.enum(['public', 'unlisted', 'private']).optional(),
|
|
121
|
+
sensitive: z.boolean().optional(),
|
|
122
|
+
language: z
|
|
123
|
+
.string()
|
|
124
|
+
.refine(validator.isISO6391)
|
|
125
|
+
.optional()
|
|
126
|
+
.openapi({ type: 'string', description: 'ISO-639-1 language code' }),
|
|
127
|
+
});
|
|
128
|
+
export type ProfileSettingsDefaults = z.infer<
|
|
129
|
+
typeof profileSettingsDefaultsSchema
|
|
130
|
+
>;
|
|
131
|
+
|
|
132
|
+
export const profileNotificationSettings = z.object({
|
|
133
|
+
create: z.boolean(),
|
|
134
|
+
push: z.boolean(),
|
|
135
|
+
email: z.boolean(),
|
|
136
|
+
});
|
|
137
|
+
export type ProfileNotificationSettings = z.infer<
|
|
138
|
+
typeof profileNotificationSettings
|
|
139
|
+
>;
|
|
140
|
+
export const jamSettingsSchema = z.object({
|
|
141
|
+
backgroundObfuscation: z
|
|
142
|
+
.discriminatedUnion('type', [
|
|
143
|
+
z.object({
|
|
144
|
+
type: z.literal('blur'),
|
|
145
|
+
radius: z.number().int().positive().optional(),
|
|
146
|
+
}),
|
|
147
|
+
z.object({
|
|
148
|
+
type: z.literal('image'),
|
|
149
|
+
image: z.string().url(),
|
|
150
|
+
}),
|
|
151
|
+
z.object({
|
|
152
|
+
type: z.literal('video'),
|
|
153
|
+
video: z.string().url(),
|
|
154
|
+
}),
|
|
155
|
+
z.object({
|
|
156
|
+
type: z.literal('none'),
|
|
157
|
+
}),
|
|
158
|
+
])
|
|
159
|
+
.optional(),
|
|
160
|
+
});
|
|
161
|
+
export const THEME_OPTIONS = ['community', 'light', 'dark', 'system'] as const;
|
|
162
|
+
export const ThemeOptionsSchema = z.enum(THEME_OPTIONS);
|
|
163
|
+
export type ThemeOptions = z.infer<typeof ThemeOptionsSchema>;
|
|
164
|
+
|
|
165
|
+
export type JamSettings = z.infer<typeof jamSettingsSchema>;
|
|
166
|
+
export const profileSettingsDataSchema = z.object({
|
|
167
|
+
id: z.string(),
|
|
168
|
+
language: z.string().optional(),
|
|
169
|
+
timeZone: z.string().optional(),
|
|
170
|
+
theme: ThemeOptionsSchema.optional(),
|
|
171
|
+
defaults: profileSettingsDefaultsSchema.optional(),
|
|
172
|
+
notifications: z.record(z.string(), profileNotificationSettings).optional(),
|
|
173
|
+
jamSettings: jamSettingsSchema.optional(),
|
|
174
|
+
stripeSettings: z
|
|
175
|
+
.object({
|
|
176
|
+
customerId: z.string().optional(),
|
|
177
|
+
})
|
|
178
|
+
.optional(),
|
|
179
|
+
feedSettings: z
|
|
180
|
+
.object({
|
|
181
|
+
format: z.enum(['threaded', 'linear']).optional(),
|
|
182
|
+
communityFeed: z
|
|
183
|
+
.object({
|
|
184
|
+
showGroupPosts: z.boolean().optional(),
|
|
185
|
+
})
|
|
186
|
+
.optional(),
|
|
187
|
+
})
|
|
188
|
+
.default({ communityFeed: { showGroupPosts: true } })
|
|
189
|
+
.optional(),
|
|
190
|
+
});
|
|
191
|
+
export type ProfileSettingsData = z.infer<typeof profileSettingsDataSchema>;
|
|
192
|
+
|
|
193
|
+
export const profileSettingsSchema = modelSchema(profileSettingsDataSchema);
|
|
194
|
+
export type ProfileSettings = Model<ProfileSettingsData>;
|
|
195
|
+
|
|
196
|
+
export const accountNameSchema = z
|
|
197
|
+
.string()
|
|
198
|
+
.refine((value: string) => !forbiddenHandles.includes(value.toLowerCase()), {
|
|
199
|
+
message: 'Handle is reserved',
|
|
200
|
+
})
|
|
201
|
+
.refine((value: string) => handleRegex.test(value ?? ''), {
|
|
202
|
+
message:
|
|
203
|
+
'Handle must be 1–16 characters: letters, numbers, underscores, or hyphens (no spaces or punctuation)',
|
|
204
|
+
})
|
|
205
|
+
.openapi({
|
|
206
|
+
type: 'string',
|
|
207
|
+
pattern: `^${handleRegexBase}$`,
|
|
208
|
+
description:
|
|
209
|
+
'Account handle: 1-16 alphanumeric / underscore / hyphen characters, excluding a reserved set.',
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
const profileResourceTypes = [
|
|
213
|
+
'jams',
|
|
214
|
+
'posts',
|
|
215
|
+
'self',
|
|
216
|
+
'profiles',
|
|
217
|
+
'posts',
|
|
218
|
+
'groups',
|
|
219
|
+
'reports',
|
|
220
|
+
'webhooks',
|
|
221
|
+
'notifications',
|
|
222
|
+
] as const;
|
|
223
|
+
|
|
224
|
+
export const profileResourceTypeSchema = z.enum(profileResourceTypes);
|
|
225
|
+
export type ProfileResourceType = z.infer<typeof profileResourceTypeSchema>;
|
|
226
|
+
|
|
227
|
+
const serviceResourceTypes = [
|
|
228
|
+
'analytics',
|
|
229
|
+
'render', // Deprecated
|
|
230
|
+
'webhooks',
|
|
231
|
+
'posts',
|
|
232
|
+
'profiles',
|
|
233
|
+
'db',
|
|
234
|
+
] as const;
|
|
235
|
+
|
|
236
|
+
export const serviceResourceTypeSchema = z.enum(serviceResourceTypes);
|
|
237
|
+
export type ServiceResourceType = z.infer<typeof serviceResourceTypeSchema>;
|
|
238
|
+
|
|
239
|
+
export type ResourceType = ProfileResourceType | ServiceResourceType | '*';
|
|
240
|
+
|
|
241
|
+
const resourceTypeSchema = z.enum([
|
|
242
|
+
...profileResourceTypes,
|
|
243
|
+
...serviceResourceTypes,
|
|
244
|
+
'*',
|
|
245
|
+
]);
|
|
246
|
+
|
|
247
|
+
export const resourceSchema = z.object({
|
|
248
|
+
type: resourceTypeSchema,
|
|
249
|
+
id: z.union([z.string(), z.literal('*')]).optional(),
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
export type Resource = {
|
|
253
|
+
type: ResourceType;
|
|
254
|
+
id?: string | '*';
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
export const scopeLevelSchema = z.enum(['write', 'read', 'admin']);
|
|
258
|
+
export type ScopeLevel = z.infer<typeof scopeLevelSchema>;
|
|
259
|
+
|
|
260
|
+
export const scopeSchema = z.object({
|
|
261
|
+
scopeLevel: scopeLevelSchema.optional(),
|
|
262
|
+
resource: resourceSchema,
|
|
263
|
+
});
|
|
264
|
+
export type Scope = z.infer<typeof scopeSchema>;
|
|
265
|
+
|
|
266
|
+
export const accessTokenDataSchema = z.object({
|
|
267
|
+
name: z.string(),
|
|
268
|
+
description: z.string().optional(),
|
|
269
|
+
signedToken: z.string(),
|
|
270
|
+
revokedAt: z.iso.datetime().nullable().optional(),
|
|
271
|
+
expiresAt: z.iso.datetime().nullable().optional(),
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
export type AccessTokenData = z.infer<typeof accessTokenDataSchema>;
|
|
275
|
+
export const accessTokenSchema = modelSchema(accessTokenDataSchema);
|
|
276
|
+
|
|
277
|
+
export const latLngSchema = z.object({
|
|
278
|
+
lat: z.number(),
|
|
279
|
+
lng: z.number(),
|
|
280
|
+
alt: z.number().optional(),
|
|
281
|
+
});
|
|
282
|
+
export type LatLng = z.infer<typeof latLngSchema>;
|
|
283
|
+
|
|
284
|
+
export const locationSchema = z.object({
|
|
285
|
+
text: z.string(),
|
|
286
|
+
coordinates: latLngSchema.optional(),
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
export type Location = z.infer<typeof locationSchema>;
|
|
290
|
+
export const federatedHandleSchema = z
|
|
291
|
+
.string()
|
|
292
|
+
.min(1)
|
|
293
|
+
.max(64)
|
|
294
|
+
.regex(/^[a-zA-Z0-9_.-]+$/, {
|
|
295
|
+
message:
|
|
296
|
+
'Federated handle: 1–64 letters, numbers, underscores, dots, or hyphens',
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
export const profileDataSchema = z.object({
|
|
300
|
+
handle: federatedHandleSchema,
|
|
301
|
+
deletedHandle: accountNameSchema.optional(),
|
|
302
|
+
avatar: z.url().nullable().optional(),
|
|
303
|
+
header: z.url().nullable().optional(),
|
|
304
|
+
displayName: z.string().max(30).optional(),
|
|
305
|
+
bio: z.string().optional(),
|
|
306
|
+
timeZone: z.string().optional(),
|
|
307
|
+
location: locationSchema.optional(),
|
|
308
|
+
locked: z.boolean().optional(),
|
|
309
|
+
bot: z.boolean().optional(),
|
|
310
|
+
discoverable: z.boolean().optional(),
|
|
311
|
+
hideSocialGraph: z.boolean().optional(),
|
|
312
|
+
indexable: z.boolean().optional(),
|
|
313
|
+
fields: z
|
|
314
|
+
.array(
|
|
315
|
+
z.object({
|
|
316
|
+
name: z.string().max(255).min(1),
|
|
317
|
+
value: z.string().max(255),
|
|
318
|
+
}),
|
|
319
|
+
)
|
|
320
|
+
.optional(),
|
|
321
|
+
activityPub: z
|
|
322
|
+
.object({
|
|
323
|
+
domain: z.string().min(4), // TODO maybe replace with regex
|
|
324
|
+
})
|
|
325
|
+
.optional(),
|
|
326
|
+
type: z.enum(['local', 'guest', 'federated']),
|
|
327
|
+
guestData: z
|
|
328
|
+
.object({
|
|
329
|
+
email: z.email().optional(),
|
|
330
|
+
resource: resourceSchema.optional(),
|
|
331
|
+
})
|
|
332
|
+
.optional(),
|
|
333
|
+
pinnedPostId: z.string().optional(),
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
export type ProfileData = z.infer<typeof profileDataSchema>;
|
|
337
|
+
export const profileSchema = modelSchema(profileDataSchema);
|
|
338
|
+
export type Profile = Model<Base<ProfileData>>;
|
|
339
|
+
|
|
340
|
+
/** `ownedBy` is present when loaded via mapping; not stored on the token document. */
|
|
341
|
+
export type AccessToken = Model<AccessTokenData> & { ownedBy?: Profile };
|
|
342
|
+
|
|
343
|
+
export const accountWithMetaSchema = accountSchema.extend({
|
|
344
|
+
profiles: z.array(profileSchema),
|
|
345
|
+
});
|
|
346
|
+
export interface AccountWithMeta extends Account {
|
|
347
|
+
profiles: Profile[];
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export const jamDataSchema = z
|
|
351
|
+
.object({
|
|
352
|
+
moderators: z.string().array(),
|
|
353
|
+
speakers: z.string().array().optional(),
|
|
354
|
+
presenters: z.string().array().optional(),
|
|
355
|
+
audience: z.string().array().optional(),
|
|
356
|
+
videoEnabled: z.boolean(),
|
|
357
|
+
type: z.enum(['video-call']),
|
|
358
|
+
maxSpeakers: z.number().int().positive().optional(),
|
|
359
|
+
maxPresenters: z.number().int().positive().optional(),
|
|
360
|
+
maxAudience: z.number().int().positive().optional(),
|
|
361
|
+
waitingRoom: z.boolean().optional(),
|
|
362
|
+
})
|
|
363
|
+
.openapi('Jam');
|
|
364
|
+
|
|
365
|
+
export const jamSchema = jamDataSchema;
|
|
366
|
+
export type JamData = z.infer<typeof jamDataSchema>;
|
|
367
|
+
export type Jam = JamData;
|
|
368
|
+
|
|
369
|
+
export const followDataSchema = z.object({
|
|
370
|
+
/** ActivityPub Follow activity id when federated. */
|
|
371
|
+
uri: z.string().url().optional(),
|
|
372
|
+
reblogs: z.boolean().optional(),
|
|
373
|
+
notify: z.boolean().optional(),
|
|
374
|
+
languages: z
|
|
375
|
+
.array(
|
|
376
|
+
z
|
|
377
|
+
.string()
|
|
378
|
+
.refine(validator.isISO6391)
|
|
379
|
+
.openapi({ type: 'string', description: 'ISO-639-1 language code' }),
|
|
380
|
+
)
|
|
381
|
+
.optional(),
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
export type FollowData = z.infer<typeof followDataSchema>;
|
|
385
|
+
export const followSchema = connectionSchema(
|
|
386
|
+
followDataSchema,
|
|
387
|
+
profileSchema,
|
|
388
|
+
profileSchema,
|
|
389
|
+
);
|
|
390
|
+
|
|
391
|
+
export type Follow = z.infer<typeof followSchema>;
|
|
392
|
+
|
|
393
|
+
export const visibilityTypeValues = [
|
|
394
|
+
'public',
|
|
395
|
+
'unlisted',
|
|
396
|
+
'private',
|
|
397
|
+
'direct',
|
|
398
|
+
'local',
|
|
399
|
+
'group',
|
|
400
|
+
'report',
|
|
401
|
+
] as const;
|
|
402
|
+
|
|
403
|
+
export const visibilityTypeSchema = z.enum(visibilityTypeValues);
|
|
404
|
+
|
|
405
|
+
export type VisibilityType = z.infer<typeof visibilityTypeSchema>;
|
|
406
|
+
|
|
407
|
+
export const postTypeSchema = z.enum(['note', 'question', 'event', 'article']);
|
|
408
|
+
export type PostType = z.infer<typeof postTypeSchema>;
|
|
409
|
+
|
|
410
|
+
export const mediaAttachmentStatusSchema = z.enum([
|
|
411
|
+
'processing',
|
|
412
|
+
'ready',
|
|
413
|
+
'failed',
|
|
414
|
+
]);
|
|
415
|
+
export type MediaAttachmentStatus = z.infer<typeof mediaAttachmentStatusSchema>;
|
|
416
|
+
|
|
417
|
+
export const mediaAttachmentDataSchema = z
|
|
418
|
+
.object({
|
|
419
|
+
type: z.string(),
|
|
420
|
+
url: z.url(),
|
|
421
|
+
previewUrl: z.url().nullable(),
|
|
422
|
+
textUrl: z.null(),
|
|
423
|
+
filename: z.string(),
|
|
424
|
+
meta: z.object({
|
|
425
|
+
usage: z.string().optional(),
|
|
426
|
+
focus: z
|
|
427
|
+
.object({
|
|
428
|
+
x: z.number(),
|
|
429
|
+
y: z.number(),
|
|
430
|
+
})
|
|
431
|
+
.optional(),
|
|
432
|
+
mimetype: z.string().optional(),
|
|
433
|
+
size: z.number().optional(),
|
|
434
|
+
}),
|
|
435
|
+
description: z.string().optional(),
|
|
436
|
+
blurhash: z.string().optional(),
|
|
437
|
+
status: mediaAttachmentStatusSchema.optional(),
|
|
438
|
+
error: z.string().optional(),
|
|
439
|
+
})
|
|
440
|
+
.openapi('MediaAttachment');
|
|
441
|
+
export const mediaAttachmentSchema = modelSchema(mediaAttachmentDataSchema);
|
|
442
|
+
export type MediaAttachmentData = z.infer<typeof mediaAttachmentDataSchema>;
|
|
443
|
+
export type MediaAttachment = Model<MediaAttachmentData>;
|
|
444
|
+
|
|
445
|
+
export const processingStatsDataSchema = z
|
|
446
|
+
.object({
|
|
447
|
+
mediaAttachmentId: z.string().uuid(),
|
|
448
|
+
filesize: z.number(),
|
|
449
|
+
filetype: z.string(),
|
|
450
|
+
durationMs: z.number(),
|
|
451
|
+
})
|
|
452
|
+
.openapi('ProcessingStats');
|
|
453
|
+
export const processingStatsSchema = modelSchema(processingStatsDataSchema);
|
|
454
|
+
export type ProcessingStatsData = z.infer<typeof processingStatsDataSchema>;
|
|
455
|
+
export type ProcessingStats = Model<ProcessingStatsData>;
|
|
456
|
+
|
|
457
|
+
export const customEmojiSchema = z
|
|
458
|
+
.object({
|
|
459
|
+
shortcode: z.string(),
|
|
460
|
+
url: z.url(),
|
|
461
|
+
staticUrl: z.url(),
|
|
462
|
+
visibleInPicker: z.boolean(),
|
|
463
|
+
category: z.string(),
|
|
464
|
+
})
|
|
465
|
+
.openapi('CustomEmoji');
|
|
466
|
+
export type CustomEmoji = z.infer<typeof customEmojiSchema>;
|
|
467
|
+
|
|
468
|
+
export const noteSchema = z
|
|
469
|
+
.object({
|
|
470
|
+
type: z.literal('note'),
|
|
471
|
+
content: z.string().optional(),
|
|
472
|
+
sensitive: z.boolean().optional(),
|
|
473
|
+
spoilerText: z.string().optional(),
|
|
474
|
+
attachments: z.array(mediaAttachmentDataSchema).optional(),
|
|
475
|
+
customEmojis: z.array(customEmojiSchema).optional(),
|
|
476
|
+
language: z.enum(ISO6391.getAllCodes() as [string, ...string[]]).optional(),
|
|
477
|
+
})
|
|
478
|
+
.openapi('Note');
|
|
479
|
+
export type Note = z.infer<typeof noteSchema>;
|
|
480
|
+
|
|
481
|
+
/** Poll choices are stored short so they fit the vote UI on small screens. */
|
|
482
|
+
export const POLL_OPTION_MAX_LENGTH = 30;
|
|
483
|
+
|
|
484
|
+
export const questionSchema = noteSchema
|
|
485
|
+
.extend({
|
|
486
|
+
type: z.literal('question'),
|
|
487
|
+
options: z
|
|
488
|
+
.object({
|
|
489
|
+
content: z.string().max(POLL_OPTION_MAX_LENGTH),
|
|
490
|
+
type: z.literal('note'),
|
|
491
|
+
})
|
|
492
|
+
.array(),
|
|
493
|
+
multiple: z.boolean().optional(),
|
|
494
|
+
votersVisible: z.boolean().optional(),
|
|
495
|
+
expiresAt: z.iso.datetime().optional(),
|
|
496
|
+
})
|
|
497
|
+
.openapi('Question');
|
|
498
|
+
|
|
499
|
+
export type Question = z.infer<typeof questionSchema>;
|
|
500
|
+
|
|
501
|
+
export const articleSchema = noteSchema
|
|
502
|
+
.extend({
|
|
503
|
+
type: z.literal('article'),
|
|
504
|
+
image: z.url().optional(),
|
|
505
|
+
title: z.string().optional(),
|
|
506
|
+
})
|
|
507
|
+
.openapi('Article');
|
|
508
|
+
|
|
509
|
+
export type Article = z.infer<typeof articleSchema>;
|
|
510
|
+
|
|
511
|
+
export const eventIsoDatetimeSchema = z.iso.datetime({
|
|
512
|
+
offset: true,
|
|
513
|
+
precision: 3,
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
export const recurrenceFreqSchema = z.enum(['DAILY', 'WEEKLY', 'MONTHLY']);
|
|
517
|
+
export type RecurrenceFreq = z.infer<typeof recurrenceFreqSchema>;
|
|
518
|
+
|
|
519
|
+
export const recurrenceWeekdaySchema = z.enum([
|
|
520
|
+
'MO',
|
|
521
|
+
'TU',
|
|
522
|
+
'WE',
|
|
523
|
+
'TH',
|
|
524
|
+
'FR',
|
|
525
|
+
'SA',
|
|
526
|
+
'SU',
|
|
527
|
+
]);
|
|
528
|
+
export type RecurrenceWeekday = z.infer<typeof recurrenceWeekdaySchema>;
|
|
529
|
+
|
|
530
|
+
export const eventRecurrenceSchema = z
|
|
531
|
+
.object({
|
|
532
|
+
freq: recurrenceFreqSchema,
|
|
533
|
+
interval: z.number().int().positive().optional(),
|
|
534
|
+
byDay: recurrenceWeekdaySchema.array().optional(),
|
|
535
|
+
until: eventIsoDatetimeSchema.optional(),
|
|
536
|
+
count: z.number().int().positive().optional(),
|
|
537
|
+
})
|
|
538
|
+
.refine((value) => !(value.until && value.count), {
|
|
539
|
+
message: 'until and count are mutually exclusive',
|
|
540
|
+
path: ['until'],
|
|
541
|
+
})
|
|
542
|
+
.openapi('EventRecurrence');
|
|
543
|
+
export type EventRecurrence = z.infer<typeof eventRecurrenceSchema>;
|
|
544
|
+
|
|
545
|
+
export const eventOccurrenceExceptionSchema = z
|
|
546
|
+
.object({
|
|
547
|
+
recurrenceId: eventIsoDatetimeSchema,
|
|
548
|
+
cancelled: z.boolean().optional(),
|
|
549
|
+
start: eventIsoDatetimeSchema.optional(),
|
|
550
|
+
end: eventIsoDatetimeSchema.optional(),
|
|
551
|
+
physicalLocation: locationSchema.optional(),
|
|
552
|
+
})
|
|
553
|
+
.openapi('EventOccurrenceException');
|
|
554
|
+
export type EventOccurrenceException = z.infer<
|
|
555
|
+
typeof eventOccurrenceExceptionSchema
|
|
556
|
+
>;
|
|
557
|
+
|
|
558
|
+
export const eventSchema = noteSchema
|
|
559
|
+
.extend({
|
|
560
|
+
type: z.literal('event'),
|
|
561
|
+
name: z.string().optional(),
|
|
562
|
+
timeZone: z.string().optional(),
|
|
563
|
+
image: z.url().optional(),
|
|
564
|
+
start: eventIsoDatetimeSchema,
|
|
565
|
+
end: eventIsoDatetimeSchema.optional(),
|
|
566
|
+
wholeDay: z.boolean(),
|
|
567
|
+
maxAttendees: z.number().int().positive().optional(),
|
|
568
|
+
attendeeListPublic: z.boolean().optional(),
|
|
569
|
+
moderators: z.string().uuid().array().optional(),
|
|
570
|
+
jam: jamSchema.optional(),
|
|
571
|
+
physicalLocation: locationSchema.optional(),
|
|
572
|
+
url: z.url().optional(),
|
|
573
|
+
recurrence: eventRecurrenceSchema.optional(),
|
|
574
|
+
exceptions: eventOccurrenceExceptionSchema.array().optional(),
|
|
575
|
+
})
|
|
576
|
+
.openapi('Event');
|
|
577
|
+
|
|
578
|
+
export type Event = z.infer<typeof eventSchema>;
|
|
579
|
+
export type EventWithId = z.infer<typeof eventSchema> & { id: string };
|
|
580
|
+
|
|
581
|
+
export const postDataUnionSchema = z.discriminatedUnion('type', [
|
|
582
|
+
noteSchema,
|
|
583
|
+
questionSchema,
|
|
584
|
+
eventSchema,
|
|
585
|
+
articleSchema,
|
|
586
|
+
]);
|
|
587
|
+
|
|
588
|
+
export type PostDataUnion = z.infer<typeof postDataUnionSchema>;
|
|
589
|
+
|
|
590
|
+
export const postDataSchema = z.object({
|
|
591
|
+
type: postTypeSchema,
|
|
592
|
+
visibility: visibilityTypeSchema,
|
|
593
|
+
capabilitiesNeeded: z.string().array().optional(),
|
|
594
|
+
data: postDataUnionSchema.optional(),
|
|
595
|
+
creatorId: z.string(),
|
|
596
|
+
});
|
|
597
|
+
export type PostData = z.infer<typeof postDataSchema>;
|
|
598
|
+
export const postSchema = modelSchema(postDataSchema);
|
|
599
|
+
export type Post = Model<PostData>;
|
|
600
|
+
|
|
601
|
+
export const answerSchema = z
|
|
602
|
+
.object({
|
|
603
|
+
selection: z.number().array(),
|
|
604
|
+
})
|
|
605
|
+
.openapi('Answer');
|
|
606
|
+
|
|
607
|
+
export type Answer = z.infer<typeof answerSchema>;
|
|
608
|
+
|
|
609
|
+
export const rsvpResponseSchema = z.enum(['yes', 'no', 'tentative', 'removed']);
|
|
610
|
+
export type RsvpResponse = z.infer<typeof rsvpResponseSchema>;
|
|
611
|
+
|
|
612
|
+
export const rsvpSchema = z.object({
|
|
613
|
+
response: rsvpResponseSchema,
|
|
614
|
+
recurrenceId: eventIsoDatetimeSchema.optional(),
|
|
615
|
+
});
|
|
616
|
+
export type RSVP = z.infer<typeof rsvpSchema>;
|
|
617
|
+
|
|
618
|
+
export const rsvpRequestSchema = rsvpSchema.extend({
|
|
619
|
+
recurrenceIds: z.array(eventIsoDatetimeSchema).min(1).optional(),
|
|
620
|
+
});
|
|
621
|
+
export type RsvpRequest = z.infer<typeof rsvpRequestSchema>;
|
|
622
|
+
|
|
623
|
+
export const entryReactionDataSchema = z.object({
|
|
624
|
+
reaction: z.string().min(1),
|
|
625
|
+
});
|
|
626
|
+
|
|
627
|
+
export const entryDataSchema = z.discriminatedUnion('type', [
|
|
628
|
+
z.object({
|
|
629
|
+
type: z.literal('create'),
|
|
630
|
+
data: postDataUnionSchema,
|
|
631
|
+
}),
|
|
632
|
+
z.object({
|
|
633
|
+
type: z.literal('edit'),
|
|
634
|
+
data: postDataUnionSchema,
|
|
635
|
+
}),
|
|
636
|
+
z.object({
|
|
637
|
+
type: z.literal('delete'),
|
|
638
|
+
data: z.any(),
|
|
639
|
+
}),
|
|
640
|
+
z.object({
|
|
641
|
+
type: z.literal('answer'),
|
|
642
|
+
data: answerSchema,
|
|
643
|
+
}),
|
|
644
|
+
z.object({
|
|
645
|
+
type: z.literal('rsvp'),
|
|
646
|
+
data: rsvpSchema,
|
|
647
|
+
}),
|
|
648
|
+
z.object({
|
|
649
|
+
type: z.literal('reaction'),
|
|
650
|
+
data: entryReactionDataSchema,
|
|
651
|
+
uri: z.string().url().optional(),
|
|
652
|
+
}),
|
|
653
|
+
z.object({
|
|
654
|
+
type: z.literal('unreaction'),
|
|
655
|
+
data: entryReactionDataSchema,
|
|
656
|
+
uri: z.string().url().optional(),
|
|
657
|
+
}),
|
|
658
|
+
]);
|
|
659
|
+
|
|
660
|
+
export type EntryData = z.infer<typeof entryDataSchema>;
|
|
661
|
+
|
|
662
|
+
export type Entry = Model<EntryData & { profile: Profile }>;
|
|
663
|
+
|
|
664
|
+
export const accountInteractionsSchema = z.object({
|
|
665
|
+
favorited: z.boolean(),
|
|
666
|
+
reposted: z.boolean(),
|
|
667
|
+
muted: z.boolean(),
|
|
668
|
+
bookmarked: z.boolean(),
|
|
669
|
+
pinned: z.boolean(),
|
|
670
|
+
});
|
|
671
|
+
|
|
672
|
+
export type AccountInteractions = z.infer<typeof accountInteractionsSchema>;
|
|
673
|
+
|
|
674
|
+
export const reportResolutionSchema = z.enum([
|
|
675
|
+
'ignore',
|
|
676
|
+
'remove',
|
|
677
|
+
'warn',
|
|
678
|
+
'ban',
|
|
679
|
+
'other',
|
|
680
|
+
]);
|
|
681
|
+
|
|
682
|
+
export type ReportResolution = z.infer<typeof reportResolutionSchema>;
|
|
683
|
+
|
|
684
|
+
export const reportDataSchema = z
|
|
685
|
+
.object({
|
|
686
|
+
comment: z.string().max(1000),
|
|
687
|
+
uri: z.string().url().optional(),
|
|
688
|
+
forward: z.boolean().optional(),
|
|
689
|
+
category: z.enum(['spam', 'violation', 'other']),
|
|
690
|
+
ruleIds: z.array(z.number()).optional(),
|
|
691
|
+
resolution: reportResolutionSchema.optional(),
|
|
692
|
+
})
|
|
693
|
+
.openapi('Report');
|
|
694
|
+
|
|
695
|
+
export type ReportData = z.infer<typeof reportDataSchema>;
|
|
696
|
+
export const reportSchema = modelSchema(reportDataSchema);
|
|
697
|
+
export type Report = Model<ReportData>;
|
|
698
|
+
|
|
699
|
+
export const notificationDataSchema = z.object({
|
|
700
|
+
type: z.string(),
|
|
701
|
+
profileId: z.string().uuid(),
|
|
702
|
+
pushHandled: z.boolean().optional(),
|
|
703
|
+
emailHandled: z.boolean().optional(),
|
|
704
|
+
read: z.boolean().optional(),
|
|
705
|
+
seen: z.boolean().optional(),
|
|
706
|
+
postId: z.string().optional(),
|
|
707
|
+
fromProfileId: z.string().uuid().optional(),
|
|
708
|
+
groupId: z.string().uuid().optional(),
|
|
709
|
+
data: z.unknown().optional(),
|
|
710
|
+
});
|
|
711
|
+
export const notificationSchema = modelSchema(notificationDataSchema);
|
|
712
|
+
export type NotificationData = z.infer<typeof notificationDataSchema>;
|
|
713
|
+
|
|
714
|
+
export type Notification<DataType = unknown> = Model<
|
|
715
|
+
NotificationData & { data?: DataType }
|
|
716
|
+
>;
|
|
717
|
+
|
|
718
|
+
export const configDataSchema = z.object({
|
|
719
|
+
config: z.any(),
|
|
720
|
+
});
|
|
721
|
+
export type ConfigData = z.infer<typeof configDataSchema>;
|
|
722
|
+
export type Config = Model<ConfigData>;
|
|
723
|
+
|
|
724
|
+
export const configDataWithDefaultsSchema = configDataSchema.extend({
|
|
725
|
+
defaults: z.any(),
|
|
726
|
+
});
|
|
727
|
+
export type ConfigDataWithDefaults = z.infer<
|
|
728
|
+
typeof configDataWithDefaultsSchema
|
|
729
|
+
>;
|
|
730
|
+
|
|
731
|
+
export const alertsSchema = z.object({
|
|
732
|
+
poll: z.boolean(),
|
|
733
|
+
followRequest: z.boolean(),
|
|
734
|
+
status: z.boolean(),
|
|
735
|
+
favorite: z.boolean(),
|
|
736
|
+
follow: z.boolean(),
|
|
737
|
+
repost: z.boolean(),
|
|
738
|
+
mention: z.boolean(),
|
|
739
|
+
update: z.boolean(),
|
|
740
|
+
admin: z.object({
|
|
741
|
+
signUp: z.boolean(),
|
|
742
|
+
report: z.boolean(),
|
|
743
|
+
}),
|
|
744
|
+
});
|
|
745
|
+
|
|
746
|
+
const pushSubscriptionWebDataSchema = z.object({
|
|
747
|
+
type: z.literal('web'),
|
|
748
|
+
deviceName: z.string().optional(),
|
|
749
|
+
endpoint: z.string().url(),
|
|
750
|
+
keys: z.object({
|
|
751
|
+
auth: z.string(),
|
|
752
|
+
p256dh: z.string(),
|
|
753
|
+
}),
|
|
754
|
+
alerts: alertsSchema.optional(),
|
|
755
|
+
});
|
|
756
|
+
|
|
757
|
+
const pushSubscriptionApnDataSchema = z.object({
|
|
758
|
+
type: z.literal('apn'),
|
|
759
|
+
deviceName: z.string().optional(),
|
|
760
|
+
apnToken: z.string(),
|
|
761
|
+
alerts: alertsSchema.optional(),
|
|
762
|
+
});
|
|
763
|
+
|
|
764
|
+
const pushSubscriptionFcmDataSchema = z.object({
|
|
765
|
+
type: z.literal('fcm'),
|
|
766
|
+
deviceName: z.string().optional(),
|
|
767
|
+
fcmToken: z.string(),
|
|
768
|
+
alerts: alertsSchema.optional(),
|
|
769
|
+
});
|
|
770
|
+
|
|
771
|
+
const pushSubscriptionWebhookDataSchema = z.object({
|
|
772
|
+
type: z.literal('webhook'),
|
|
773
|
+
url: z.url(),
|
|
774
|
+
publicKey: z.string().min(1),
|
|
775
|
+
alerts: alertsSchema.optional(),
|
|
776
|
+
});
|
|
777
|
+
|
|
778
|
+
export const pushSubscriptionDataSchema = z.discriminatedUnion('type', [
|
|
779
|
+
pushSubscriptionWebDataSchema,
|
|
780
|
+
pushSubscriptionApnDataSchema,
|
|
781
|
+
pushSubscriptionFcmDataSchema,
|
|
782
|
+
pushSubscriptionWebhookDataSchema,
|
|
783
|
+
]);
|
|
784
|
+
export type PushSubscriptionData = z.infer<typeof pushSubscriptionDataSchema>;
|
|
785
|
+
|
|
786
|
+
export const pushSubscriptionSchema = z.discriminatedUnion('type', [
|
|
787
|
+
modelSchema(pushSubscriptionWebDataSchema),
|
|
788
|
+
modelSchema(pushSubscriptionApnDataSchema),
|
|
789
|
+
modelSchema(pushSubscriptionFcmDataSchema),
|
|
790
|
+
modelSchema(pushSubscriptionWebhookDataSchema),
|
|
791
|
+
]);
|
|
792
|
+
export type PushSubscription = z.infer<typeof pushSubscriptionSchema>;
|
|
793
|
+
export const reactionTypeSchema = z.enum(['👍']);
|
|
794
|
+
|
|
795
|
+
export const reactionDataSchema = z.object({
|
|
796
|
+
reaction: reactionTypeSchema,
|
|
797
|
+
});
|
|
798
|
+
export type ReactionData = z.infer<typeof reactionDataSchema>;
|
|
799
|
+
export type Reaction = Model<ReactionData>;
|
|
800
|
+
|
|
801
|
+
export const mentionDataSchema = z.object({
|
|
802
|
+
text: z.string().optional(),
|
|
803
|
+
});
|
|
804
|
+
export type MentionData = z.infer<typeof mentionDataSchema>;
|
|
805
|
+
export type Mention = Model<MentionData>;
|
|
806
|
+
|
|
807
|
+
export const timelineValueSchema = z.object({
|
|
808
|
+
start: z.string().datetime(),
|
|
809
|
+
end: z.string().datetime(),
|
|
810
|
+
value: z.number(),
|
|
811
|
+
});
|
|
812
|
+
export type TimelineValue = z.infer<typeof timelineValueSchema>;
|
|
813
|
+
|
|
814
|
+
export const profileStatsSchema = z.object({
|
|
815
|
+
followersCount: z.number(),
|
|
816
|
+
followingCount: z.number(),
|
|
817
|
+
});
|
|
818
|
+
export type ProfileStats = z.infer<typeof profileStatsSchema>;
|
|
819
|
+
|
|
820
|
+
export const GROUP_DISPLAY_NAME_MAX_LENGTH = 30;
|
|
821
|
+
|
|
822
|
+
export const groupDataSchema = z.object({
|
|
823
|
+
handle: accountNameSchema,
|
|
824
|
+
avatar: z.string().url().nullable().optional(),
|
|
825
|
+
header: z.string().url().nullable().optional(),
|
|
826
|
+
displayName: z
|
|
827
|
+
.string()
|
|
828
|
+
.max(GROUP_DISPLAY_NAME_MAX_LENGTH, {
|
|
829
|
+
message: `Group name should be ${GROUP_DISPLAY_NAME_MAX_LENGTH} characters or fewer`,
|
|
830
|
+
})
|
|
831
|
+
.optional(),
|
|
832
|
+
description: z.string().optional(),
|
|
833
|
+
rules: z.string().optional(),
|
|
834
|
+
pinnedPostId: z.string().optional(),
|
|
835
|
+
discoverable: z.boolean().optional(),
|
|
836
|
+
capabilities: z.record(z.string(), capabilitiesSchema),
|
|
837
|
+
});
|
|
838
|
+
|
|
839
|
+
export type GroupData = z.infer<typeof groupDataSchema>;
|
|
840
|
+
|
|
841
|
+
export const groupSchema = modelSchema(groupDataSchema);
|
|
842
|
+
export type Group = z.infer<typeof groupSchema>;
|
|
843
|
+
|
|
844
|
+
export const groupRoleSchema = z.object({
|
|
845
|
+
roles: z.enum(groupRelationships).array().optional().nullable(),
|
|
846
|
+
});
|
|
847
|
+
|
|
848
|
+
export type GroupRoleData = z.infer<typeof groupRoleSchema>;
|
|
849
|
+
|
|
850
|
+
export const guestDataSchema = z.object({
|
|
851
|
+
displayName: z.string(),
|
|
852
|
+
email: z.email(),
|
|
853
|
+
});
|
|
854
|
+
|
|
855
|
+
export type GuestData = z.infer<typeof guestDataSchema>;
|
|
856
|
+
|
|
857
|
+
export const jamEventDataSchema = z.object({
|
|
858
|
+
id: z.string(),
|
|
859
|
+
jamId: z.string(),
|
|
860
|
+
type: z.enum([
|
|
861
|
+
'message',
|
|
862
|
+
'reaction',
|
|
863
|
+
'join',
|
|
864
|
+
'leave',
|
|
865
|
+
'start',
|
|
866
|
+
'close',
|
|
867
|
+
'recordStart',
|
|
868
|
+
'recordStop',
|
|
869
|
+
'streamStart',
|
|
870
|
+
'streamStop',
|
|
871
|
+
]),
|
|
872
|
+
profileId: z.string(),
|
|
873
|
+
content: z.string().optional(),
|
|
874
|
+
reaction: reactionTypeSchema.optional(),
|
|
875
|
+
recurrenceId: eventIsoDatetimeSchema.optional(),
|
|
876
|
+
});
|
|
877
|
+
|
|
878
|
+
export type JamEventData = z.infer<typeof jamEventDataSchema>;
|
|
879
|
+
|
|
880
|
+
export const jamEventSchema = modelSchema(jamEventDataSchema);
|
|
881
|
+
export type JamEvent = Model<JamEventData>;
|
|
882
|
+
|
|
883
|
+
export const inviteLinkDataSchema = z.object({
|
|
884
|
+
slug: z.string(),
|
|
885
|
+
active: z.boolean(),
|
|
886
|
+
emailPatterns: z.string().array().optional(),
|
|
887
|
+
maxUses: z.number(),
|
|
888
|
+
expiresAt: z.string().datetime(),
|
|
889
|
+
customInvitationMessage: z.string().optional(),
|
|
890
|
+
/** New members who redeem this link are added to these groups (as members). */
|
|
891
|
+
groupIds: z.array(z.string()).optional(),
|
|
892
|
+
});
|
|
893
|
+
export type InviteLinkData = z.infer<typeof inviteLinkDataSchema>;
|
|
894
|
+
|
|
895
|
+
export const inviteLinkSchema = modelSchema(inviteLinkDataSchema);
|
|
896
|
+
export type InviteLink = Model<InviteLinkData>;
|
|
897
|
+
|
|
898
|
+
export const hashtagDataSchema = z.object({
|
|
899
|
+
tag: z.string().optional(),
|
|
900
|
+
});
|
|
901
|
+
export type HashtagData = z.infer<typeof hashtagDataSchema>;
|
|
902
|
+
export const hashtagSchema = modelSchema(hashtagDataSchema);
|
|
903
|
+
export type Hashtag = Model<HashtagData>;
|
|
904
|
+
|
|
905
|
+
export const normalizeHashtagTag = (tag: string) => tag.toLowerCase();
|
|
906
|
+
|
|
907
|
+
export const hashtagRegexBase = '(?<!\\S)#([a-z0-9_]+)(?![a-z0-9_])';
|
|
908
|
+
export const hashtagRegex = new RegExp(hashtagRegexBase, 'gi');
|
|
909
|
+
|
|
910
|
+
export const jamRecordingTypeSchema = z.enum([
|
|
911
|
+
'compositeVideo',
|
|
912
|
+
'compositeAudio',
|
|
913
|
+
'streams',
|
|
914
|
+
]);
|
|
915
|
+
export type JamRecordingType = z.infer<typeof jamRecordingTypeSchema>;
|
|
916
|
+
|
|
917
|
+
export const jamRecordingKindSchema = z.enum(['file', 'rtmp']);
|
|
918
|
+
export type JamRecordingKind = z.infer<typeof jamRecordingKindSchema>;
|
|
919
|
+
|
|
920
|
+
export const jamRecordingStatusSchema = z.enum([
|
|
921
|
+
'requested',
|
|
922
|
+
'active',
|
|
923
|
+
'finalizing',
|
|
924
|
+
'completed',
|
|
925
|
+
'failed',
|
|
926
|
+
]);
|
|
927
|
+
export type JamRecordingStatus = z.infer<typeof jamRecordingStatusSchema>;
|
|
928
|
+
|
|
929
|
+
export const jamRecordingDataSchema = z.object({
|
|
930
|
+
status: jamRecordingStatusSchema,
|
|
931
|
+
kind: jamRecordingKindSchema.optional(),
|
|
932
|
+
destinationHost: z.string().optional(),
|
|
933
|
+
egressId: z.string().optional(),
|
|
934
|
+
attachment: mediaAttachmentSchema.optional(),
|
|
935
|
+
replyPostId: z.string().optional(),
|
|
936
|
+
});
|
|
937
|
+
export type JamRecordingData = z.infer<typeof jamRecordingDataSchema>;
|
|
938
|
+
export const jamRecordingSchema = modelSchema(jamRecordingDataSchema);
|
|
939
|
+
export type JamRecording = Model<JamRecordingData>;
|