@openpeepshq/common 0.1.43
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/LICENSE.md +21 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/lib/adminSections.d.ts +53 -0
- package/dist/lib/adminSections.js +62 -0
- package/dist/lib/attachmentHelpers.d.ts +1 -0
- package/dist/lib/attachmentHelpers.js +13 -0
- package/dist/lib/capabilitiesHelpers.d.ts +118 -0
- package/dist/lib/capabilitiesHelpers.js +238 -0
- package/dist/lib/colors.d.ts +5 -0
- package/dist/lib/colors.js +17 -0
- package/dist/lib/csvHelpers.d.ts +6 -0
- package/dist/lib/csvHelpers.js +17 -0
- package/dist/lib/eventIcs.d.ts +4 -0
- package/dist/lib/eventIcs.js +83 -0
- package/dist/lib/groupHelpers.d.ts +134 -0
- package/dist/lib/groupHelpers.js +216 -0
- package/dist/lib/index.d.ts +17 -0
- package/dist/lib/index.js +17 -0
- package/dist/lib/jamHelpers.d.ts +5 -0
- package/dist/lib/jamHelpers.js +37 -0
- package/dist/lib/markdownHelpers.d.ts +1 -0
- package/dist/lib/markdownHelpers.js +24 -0
- package/dist/lib/mediaDimensions.d.ts +19 -0
- package/dist/lib/mediaDimensions.js +19 -0
- package/dist/lib/postHelpers.d.ts +146 -0
- package/dist/lib/postHelpers.js +144 -0
- package/dist/lib/profileHelpers.d.ts +30 -0
- package/dist/lib/profileHelpers.js +75 -0
- package/dist/lib/pushHelpers.d.ts +4 -0
- package/dist/lib/pushHelpers.js +6 -0
- package/dist/lib/scopeHelpers.d.ts +25 -0
- package/dist/lib/scopeHelpers.js +85 -0
- package/dist/lib/text.d.ts +3 -0
- package/dist/lib/text.js +18 -0
- package/dist/lib/tokenHelpers.d.ts +21 -0
- package/dist/lib/tokenHelpers.js +81 -0
- package/dist/lib/utils.d.ts +43 -0
- package/dist/lib/utils.js +200 -0
- package/dist/types/admin-db.d.ts +62 -0
- package/dist/types/admin-db.js +41 -0
- package/dist/types/admin-email.d.ts +39 -0
- package/dist/types/admin-email.js +41 -0
- package/dist/types/admin-jobs.d.ts +15 -0
- package/dist/types/admin-jobs.js +14 -0
- package/dist/types/admin-performance.d.ts +23 -0
- package/dist/types/admin-performance.js +14 -0
- package/dist/types/analytics.d.ts +583 -0
- package/dist/types/analytics.js +213 -0
- package/dist/types/api.d.ts +20076 -0
- package/dist/types/api.js +492 -0
- package/dist/types/apple-app-site-association.d.ts +50 -0
- package/dist/types/apple-app-site-association.js +38 -0
- package/dist/types/auth.d.ts +367 -0
- package/dist/types/auth.js +17 -0
- package/dist/types/capabilities.d.ts +24 -0
- package/dist/types/capabilities.js +144 -0
- package/dist/types/config.d.ts +858 -0
- package/dist/types/config.js +352 -0
- package/dist/types/db.d.ts +8780 -0
- package/dist/types/db.js +65 -0
- package/dist/types/index.d.ts +18 -0
- package/dist/types/index.js +18 -0
- package/dist/types/internal.d.ts +44337 -0
- package/dist/types/internal.js +154 -0
- package/dist/types/models.d.ts +2619 -0
- package/dist/types/models.js +599 -0
- package/dist/types/notifications.d.ts +148 -0
- package/dist/types/notifications.js +40 -0
- package/dist/types/plugins.d.ts +66 -0
- package/dist/types/plugins.js +29 -0
- package/dist/types/stats.d.ts +10216 -0
- package/dist/types/stats.js +109 -0
- package/dist/types/stripe.d.ts +42 -0
- package/dist/types/stripe.js +35 -0
- package/dist/types/utils.d.ts +84 -0
- package/dist/types/utils.js +39 -0
- package/package.json +54 -0
|
@@ -0,0 +1,599 @@
|
|
|
1
|
+
import { z } 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.js';
|
|
6
|
+
import { capabilitiesSchema } from './config.js';
|
|
7
|
+
extendZodWithOpenApi(z);
|
|
8
|
+
export const handleRegexBase = '[a-zA-Z0-9_-]{1,16}';
|
|
9
|
+
export const handleRegex = new RegExp(`^${handleRegexBase}$`);
|
|
10
|
+
export const forbiddenHandles = [
|
|
11
|
+
'admin',
|
|
12
|
+
'allpeep',
|
|
13
|
+
'api',
|
|
14
|
+
'app',
|
|
15
|
+
'auth',
|
|
16
|
+
'config',
|
|
17
|
+
'core',
|
|
18
|
+
'db',
|
|
19
|
+
'email',
|
|
20
|
+
'federation',
|
|
21
|
+
'jam',
|
|
22
|
+
'media',
|
|
23
|
+
'network',
|
|
24
|
+
'plugins',
|
|
25
|
+
'undefined',
|
|
26
|
+
'jamStarted',
|
|
27
|
+
'jamSpeaker',
|
|
28
|
+
'jamModerator',
|
|
29
|
+
'new',
|
|
30
|
+
];
|
|
31
|
+
export const baseSchemaShape = {
|
|
32
|
+
createdAt: z.iso.datetime(),
|
|
33
|
+
updatedAt: z.iso.datetime(),
|
|
34
|
+
deletedAt: z.iso.datetime().nullable().optional(),
|
|
35
|
+
};
|
|
36
|
+
export const baseSchema = z.object(baseSchemaShape);
|
|
37
|
+
export const idSchemaShape = {
|
|
38
|
+
id: z.uuid(),
|
|
39
|
+
};
|
|
40
|
+
export const idSchema = z.object(idSchemaShape);
|
|
41
|
+
const modelBaseFields = {
|
|
42
|
+
...baseSchemaShape,
|
|
43
|
+
...idSchemaShape,
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Preserves the data-schema shape through declaration emit (see ZodObject extend typing).
|
|
47
|
+
* A non-generic parameter used to widen `ZodObject<ZodRawShape>` destroys output `.d.ts`
|
|
48
|
+
* (index signature + unknown), which breaks consumers that need structural JSON types.
|
|
49
|
+
*/
|
|
50
|
+
export const modelSchema = (dataSchema) => dataSchema.extend(modelBaseFields);
|
|
51
|
+
const connectionSchema = (dataSchema, from, to) => modelSchema(dataSchema).extend({
|
|
52
|
+
from,
|
|
53
|
+
to,
|
|
54
|
+
});
|
|
55
|
+
export const applicationDataSchema = z.object({
|
|
56
|
+
id: z.string(),
|
|
57
|
+
secret: z.string(),
|
|
58
|
+
name: z.string(),
|
|
59
|
+
website: z.string(),
|
|
60
|
+
});
|
|
61
|
+
export const accountDataSchema = z.object({
|
|
62
|
+
email: z.string().email(),
|
|
63
|
+
passwordHash: z.string(),
|
|
64
|
+
emailValidated: z.boolean().default(false).optional(),
|
|
65
|
+
guest: z.boolean().optional(),
|
|
66
|
+
});
|
|
67
|
+
export const accountSchema = modelSchema(accountDataSchema);
|
|
68
|
+
export const roleDataSchema = z.object({
|
|
69
|
+
key: z.string().regex(/^[a-z-]{1,32}$/),
|
|
70
|
+
default: z.boolean(),
|
|
71
|
+
displayName: z.string().max(32),
|
|
72
|
+
description: z.string().optional(),
|
|
73
|
+
capabilities: capabilitiesSchema,
|
|
74
|
+
});
|
|
75
|
+
export const roleSchema = modelSchema(roleDataSchema);
|
|
76
|
+
export const profileSettingsDefaultsSchema = z.object({
|
|
77
|
+
privacy: z.enum(['public', 'unlisted', 'private']).optional(),
|
|
78
|
+
sensitive: z.boolean().optional(),
|
|
79
|
+
language: z
|
|
80
|
+
.string()
|
|
81
|
+
.refine(validator.isISO6391)
|
|
82
|
+
.optional()
|
|
83
|
+
.openapi({ type: 'string', description: 'ISO-639-1 language code' }),
|
|
84
|
+
});
|
|
85
|
+
export const profileNotificationSettings = z.object({
|
|
86
|
+
create: z.boolean(),
|
|
87
|
+
push: z.boolean(),
|
|
88
|
+
email: z.boolean(),
|
|
89
|
+
});
|
|
90
|
+
export const jamSettingsSchema = z.object({
|
|
91
|
+
backgroundObfuscation: z
|
|
92
|
+
.discriminatedUnion('type', [
|
|
93
|
+
z.object({
|
|
94
|
+
type: z.literal('blur'),
|
|
95
|
+
radius: z.number().int().positive().optional(),
|
|
96
|
+
}),
|
|
97
|
+
z.object({
|
|
98
|
+
type: z.literal('image'),
|
|
99
|
+
image: z.string().url(),
|
|
100
|
+
}),
|
|
101
|
+
z.object({
|
|
102
|
+
type: z.literal('video'),
|
|
103
|
+
video: z.string().url(),
|
|
104
|
+
}),
|
|
105
|
+
z.object({
|
|
106
|
+
type: z.literal('none'),
|
|
107
|
+
}),
|
|
108
|
+
])
|
|
109
|
+
.optional(),
|
|
110
|
+
});
|
|
111
|
+
export const THEME_OPTIONS = ['community', 'light', 'dark', 'system'];
|
|
112
|
+
export const ThemeOptionsSchema = z.enum(THEME_OPTIONS);
|
|
113
|
+
export const profileSettingsDataSchema = z.object({
|
|
114
|
+
id: z.string(),
|
|
115
|
+
language: z.string().optional(),
|
|
116
|
+
theme: ThemeOptionsSchema.optional(),
|
|
117
|
+
defaults: profileSettingsDefaultsSchema.optional(),
|
|
118
|
+
notifications: z.record(z.string(), profileNotificationSettings).optional(),
|
|
119
|
+
jamSettings: jamSettingsSchema.optional(),
|
|
120
|
+
stripeSettings: z
|
|
121
|
+
.object({
|
|
122
|
+
customerId: z.string().optional(),
|
|
123
|
+
})
|
|
124
|
+
.optional(),
|
|
125
|
+
feedSettings: z
|
|
126
|
+
.object({
|
|
127
|
+
communityFeed: z
|
|
128
|
+
.object({
|
|
129
|
+
showGroupPosts: z.boolean().optional(),
|
|
130
|
+
})
|
|
131
|
+
.optional(),
|
|
132
|
+
})
|
|
133
|
+
.default({ communityFeed: { showGroupPosts: true } })
|
|
134
|
+
.optional(),
|
|
135
|
+
});
|
|
136
|
+
export const profileSettingsSchema = modelSchema(profileSettingsDataSchema);
|
|
137
|
+
export const accountNameSchema = z
|
|
138
|
+
.string()
|
|
139
|
+
.refine((value) => !forbiddenHandles.includes(value.toLowerCase()), {
|
|
140
|
+
message: 'Handle is reserved',
|
|
141
|
+
})
|
|
142
|
+
.refine((value) => handleRegex.test(value !== null && value !== void 0 ? value : ''), {
|
|
143
|
+
message: 'Handle must be 1–16 characters: letters, numbers, underscores, or hyphens (no spaces or punctuation)',
|
|
144
|
+
})
|
|
145
|
+
.openapi({
|
|
146
|
+
type: 'string',
|
|
147
|
+
pattern: `^${handleRegexBase}$`,
|
|
148
|
+
description: 'Account handle: 1-16 alphanumeric / underscore / hyphen characters, excluding a reserved set.',
|
|
149
|
+
});
|
|
150
|
+
const profileResourceTypes = [
|
|
151
|
+
'jam',
|
|
152
|
+
'jams',
|
|
153
|
+
'posts',
|
|
154
|
+
'self',
|
|
155
|
+
'profiles',
|
|
156
|
+
'posts',
|
|
157
|
+
'groups',
|
|
158
|
+
'reports',
|
|
159
|
+
'webhooks',
|
|
160
|
+
'notifications',
|
|
161
|
+
];
|
|
162
|
+
export const profileResourceTypeSchema = z.enum(profileResourceTypes);
|
|
163
|
+
const serviceResourceTypes = [
|
|
164
|
+
'analytics',
|
|
165
|
+
'render', // Deprecated
|
|
166
|
+
'webhooks',
|
|
167
|
+
'posts',
|
|
168
|
+
'profiles',
|
|
169
|
+
'db',
|
|
170
|
+
];
|
|
171
|
+
export const serviceResourceTypeSchema = z.enum(serviceResourceTypes);
|
|
172
|
+
const resourceTypeSchema = z.enum([
|
|
173
|
+
...profileResourceTypes,
|
|
174
|
+
...serviceResourceTypes,
|
|
175
|
+
'*',
|
|
176
|
+
]);
|
|
177
|
+
export const resourceSchema = z.object({
|
|
178
|
+
type: resourceTypeSchema,
|
|
179
|
+
id: z.union([z.string(), z.literal('*')]).optional(),
|
|
180
|
+
});
|
|
181
|
+
export const scopeLevelSchema = z.enum(['write', 'read', 'admin']);
|
|
182
|
+
export const scopeSchema = z.object({
|
|
183
|
+
scopeLevel: scopeLevelSchema.optional(),
|
|
184
|
+
resource: resourceSchema,
|
|
185
|
+
});
|
|
186
|
+
export const accessTokenDataSchema = z.object({
|
|
187
|
+
name: z.string(),
|
|
188
|
+
description: z.string().optional(),
|
|
189
|
+
signedToken: z.string(),
|
|
190
|
+
revokedAt: z.iso.datetime().nullable().optional(),
|
|
191
|
+
expiresAt: z.iso.datetime().nullable().optional(),
|
|
192
|
+
});
|
|
193
|
+
export const accessTokenSchema = modelSchema(accessTokenDataSchema);
|
|
194
|
+
export const latLngSchema = z.object({
|
|
195
|
+
lat: z.number(),
|
|
196
|
+
lng: z.number(),
|
|
197
|
+
alt: z.number().optional(),
|
|
198
|
+
});
|
|
199
|
+
export const locationSchema = z.object({
|
|
200
|
+
text: z.string(),
|
|
201
|
+
coordinates: latLngSchema.optional(),
|
|
202
|
+
});
|
|
203
|
+
export const profileDataSchema = z.object({
|
|
204
|
+
handle: accountNameSchema,
|
|
205
|
+
deletedHandle: accountNameSchema.optional(),
|
|
206
|
+
avatar: z.url().nullable().optional(),
|
|
207
|
+
header: z.url().nullable().optional(),
|
|
208
|
+
displayName: z.string().max(30).optional(),
|
|
209
|
+
bio: z.string().optional(),
|
|
210
|
+
timeZone: z.string().optional(),
|
|
211
|
+
location: locationSchema.optional(),
|
|
212
|
+
locked: z.boolean().optional(),
|
|
213
|
+
bot: z.boolean().optional(),
|
|
214
|
+
discoverable: z.boolean().optional(),
|
|
215
|
+
hideSocialGraph: z.boolean().optional(),
|
|
216
|
+
indexable: z.boolean().optional(),
|
|
217
|
+
fields: z
|
|
218
|
+
.array(z.object({
|
|
219
|
+
name: z.string().max(255).min(1),
|
|
220
|
+
value: z.string().max(255),
|
|
221
|
+
}))
|
|
222
|
+
.optional(),
|
|
223
|
+
activityPub: z
|
|
224
|
+
.object({
|
|
225
|
+
domain: z.string().min(4), // TODO maybe replace with regex
|
|
226
|
+
})
|
|
227
|
+
.optional(),
|
|
228
|
+
type: z.enum(['local', 'guest', 'federated']),
|
|
229
|
+
guestData: z
|
|
230
|
+
.object({
|
|
231
|
+
email: z.email().optional(),
|
|
232
|
+
resource: resourceSchema.optional(),
|
|
233
|
+
})
|
|
234
|
+
.optional(),
|
|
235
|
+
});
|
|
236
|
+
export const profileSchema = modelSchema(profileDataSchema);
|
|
237
|
+
export const accountWithMetaSchema = accountSchema.extend({
|
|
238
|
+
profiles: z.array(profileSchema),
|
|
239
|
+
});
|
|
240
|
+
export const jamDataSchema = z
|
|
241
|
+
.object({
|
|
242
|
+
moderators: z.string().array(),
|
|
243
|
+
speakers: z.string().array().optional(),
|
|
244
|
+
presenters: z.string().array().optional(),
|
|
245
|
+
audience: z.string().array().optional(),
|
|
246
|
+
videoEnabled: z.boolean(),
|
|
247
|
+
type: z.enum(['video-call']),
|
|
248
|
+
maxSpeakers: z.number().int().positive().optional(),
|
|
249
|
+
maxPresenters: z.number().int().positive().optional(),
|
|
250
|
+
maxAudience: z.number().int().positive().optional(),
|
|
251
|
+
waitingRoom: z.boolean().optional(),
|
|
252
|
+
})
|
|
253
|
+
.openapi('Jam');
|
|
254
|
+
export const jamSchema = jamDataSchema;
|
|
255
|
+
export const followDataSchema = z.object({
|
|
256
|
+
reblogs: z.boolean().optional(),
|
|
257
|
+
notify: z.boolean().optional(),
|
|
258
|
+
languages: z
|
|
259
|
+
.array(z
|
|
260
|
+
.string()
|
|
261
|
+
.refine(validator.isISO6391)
|
|
262
|
+
.openapi({ type: 'string', description: 'ISO-639-1 language code' }))
|
|
263
|
+
.optional(),
|
|
264
|
+
});
|
|
265
|
+
export const followSchema = connectionSchema(followDataSchema, profileSchema, profileSchema);
|
|
266
|
+
export const visibilityTypeValues = [
|
|
267
|
+
'public',
|
|
268
|
+
'unlisted',
|
|
269
|
+
'private',
|
|
270
|
+
'direct',
|
|
271
|
+
'local',
|
|
272
|
+
'group',
|
|
273
|
+
'report',
|
|
274
|
+
];
|
|
275
|
+
export const visibilityTypeSchema = z.enum(visibilityTypeValues);
|
|
276
|
+
export const postTypeSchema = z.enum(['note', 'question', 'event', 'article']);
|
|
277
|
+
export const mediaAttachmentStatusSchema = z.enum([
|
|
278
|
+
'processing',
|
|
279
|
+
'ready',
|
|
280
|
+
'failed',
|
|
281
|
+
]);
|
|
282
|
+
export const mediaAttachmentDataSchema = z
|
|
283
|
+
.object({
|
|
284
|
+
type: z.string(),
|
|
285
|
+
url: z.url(),
|
|
286
|
+
previewUrl: z.url().nullable(),
|
|
287
|
+
textUrl: z.null(),
|
|
288
|
+
filename: z.string(),
|
|
289
|
+
meta: z.object({
|
|
290
|
+
usage: z.string().optional(),
|
|
291
|
+
focus: z
|
|
292
|
+
.object({
|
|
293
|
+
x: z.number(),
|
|
294
|
+
y: z.number(),
|
|
295
|
+
})
|
|
296
|
+
.optional(),
|
|
297
|
+
mimetype: z.string().optional(),
|
|
298
|
+
size: z.number().optional(),
|
|
299
|
+
}),
|
|
300
|
+
description: z.string().optional(),
|
|
301
|
+
blurhash: z.string().optional(),
|
|
302
|
+
status: mediaAttachmentStatusSchema.optional(),
|
|
303
|
+
error: z.string().optional(),
|
|
304
|
+
})
|
|
305
|
+
.openapi('MediaAttachment');
|
|
306
|
+
export const mediaAttachmentSchema = modelSchema(mediaAttachmentDataSchema);
|
|
307
|
+
export const processingStatsDataSchema = z
|
|
308
|
+
.object({
|
|
309
|
+
mediaAttachmentId: z.string().uuid(),
|
|
310
|
+
filesize: z.number(),
|
|
311
|
+
filetype: z.string(),
|
|
312
|
+
durationMs: z.number(),
|
|
313
|
+
})
|
|
314
|
+
.openapi('ProcessingStats');
|
|
315
|
+
export const processingStatsSchema = modelSchema(processingStatsDataSchema);
|
|
316
|
+
export const customEmojiSchema = z
|
|
317
|
+
.object({
|
|
318
|
+
shortcode: z.string(),
|
|
319
|
+
url: z.url(),
|
|
320
|
+
staticUrl: z.url(),
|
|
321
|
+
visibleInPicker: z.boolean(),
|
|
322
|
+
category: z.string(),
|
|
323
|
+
})
|
|
324
|
+
.openapi('CustomEmoji');
|
|
325
|
+
export const noteSchema = z
|
|
326
|
+
.object({
|
|
327
|
+
type: z.literal('note'),
|
|
328
|
+
content: z.string().optional(),
|
|
329
|
+
sensitive: z.boolean().optional(),
|
|
330
|
+
spoilerText: z.string().optional(),
|
|
331
|
+
attachments: z.array(mediaAttachmentDataSchema).optional(),
|
|
332
|
+
customEmojis: z.array(customEmojiSchema).optional(),
|
|
333
|
+
language: z.enum(ISO6391.getAllCodes()).optional(),
|
|
334
|
+
})
|
|
335
|
+
.openapi('Note');
|
|
336
|
+
export const questionSchema = noteSchema
|
|
337
|
+
.extend({
|
|
338
|
+
type: z.literal('question'),
|
|
339
|
+
options: z
|
|
340
|
+
.object({
|
|
341
|
+
content: z.string().max(30),
|
|
342
|
+
type: z.literal('note'),
|
|
343
|
+
})
|
|
344
|
+
.array(),
|
|
345
|
+
multiple: z.boolean().optional(),
|
|
346
|
+
votersVisible: z.boolean().optional(),
|
|
347
|
+
expiresAt: z.iso.datetime().optional(),
|
|
348
|
+
})
|
|
349
|
+
.openapi('Question');
|
|
350
|
+
export const articleSchema = noteSchema
|
|
351
|
+
.extend({
|
|
352
|
+
type: z.literal('article'),
|
|
353
|
+
image: z.url().optional(),
|
|
354
|
+
title: z.string().optional(),
|
|
355
|
+
})
|
|
356
|
+
.openapi('Article');
|
|
357
|
+
export const eventSchema = noteSchema
|
|
358
|
+
.extend({
|
|
359
|
+
type: z.literal('event'),
|
|
360
|
+
name: z.string().optional(),
|
|
361
|
+
timeZone: z.string().optional(),
|
|
362
|
+
image: z.url().optional(),
|
|
363
|
+
start: z.iso.datetime({ offset: true, precision: 3 }),
|
|
364
|
+
end: z.iso.datetime({ offset: true, precision: 3 }).optional(),
|
|
365
|
+
wholeDay: z.boolean(),
|
|
366
|
+
maxAttendees: z.number().int().positive().optional(),
|
|
367
|
+
attendeeListPublic: z.boolean().optional(),
|
|
368
|
+
moderators: z.string().uuid().array().optional(),
|
|
369
|
+
jam: jamSchema.optional(),
|
|
370
|
+
physicalLocation: locationSchema.optional(),
|
|
371
|
+
url: z.url().optional(),
|
|
372
|
+
})
|
|
373
|
+
.openapi('Event');
|
|
374
|
+
export const postDataUnionSchema = z.discriminatedUnion('type', [
|
|
375
|
+
noteSchema,
|
|
376
|
+
questionSchema,
|
|
377
|
+
eventSchema,
|
|
378
|
+
articleSchema,
|
|
379
|
+
]);
|
|
380
|
+
export const postDataSchema = z.object({
|
|
381
|
+
type: postTypeSchema,
|
|
382
|
+
visibility: visibilityTypeSchema,
|
|
383
|
+
capabilitiesNeeded: z.string().array().optional(),
|
|
384
|
+
data: postDataUnionSchema.optional(),
|
|
385
|
+
creatorId: z.string(),
|
|
386
|
+
});
|
|
387
|
+
export const postSchema = modelSchema(postDataSchema);
|
|
388
|
+
export const answerSchema = z
|
|
389
|
+
.object({
|
|
390
|
+
selection: z.number().array(),
|
|
391
|
+
})
|
|
392
|
+
.openapi('Answer');
|
|
393
|
+
export const rsvpResponseSchema = z.enum(['yes', 'no', 'tentative', 'removed']);
|
|
394
|
+
export const rsvpSchema = z.object({
|
|
395
|
+
response: rsvpResponseSchema,
|
|
396
|
+
});
|
|
397
|
+
export const entryDataSchema = z.discriminatedUnion('type', [
|
|
398
|
+
z.object({
|
|
399
|
+
type: z.literal('create'),
|
|
400
|
+
data: postDataUnionSchema,
|
|
401
|
+
}),
|
|
402
|
+
z.object({
|
|
403
|
+
type: z.literal('edit'),
|
|
404
|
+
data: postDataUnionSchema,
|
|
405
|
+
}),
|
|
406
|
+
z.object({
|
|
407
|
+
type: z.literal('delete'),
|
|
408
|
+
data: z.any(),
|
|
409
|
+
}),
|
|
410
|
+
z.object({
|
|
411
|
+
type: z.literal('answer'),
|
|
412
|
+
data: answerSchema,
|
|
413
|
+
}),
|
|
414
|
+
z.object({
|
|
415
|
+
type: z.literal('rsvp'),
|
|
416
|
+
data: rsvpSchema,
|
|
417
|
+
}),
|
|
418
|
+
]);
|
|
419
|
+
export const accountInteractionsSchema = z.object({
|
|
420
|
+
favorited: z.boolean(),
|
|
421
|
+
reposted: z.boolean(),
|
|
422
|
+
muted: z.boolean(),
|
|
423
|
+
bookmarked: z.boolean(),
|
|
424
|
+
pinned: z.boolean(),
|
|
425
|
+
});
|
|
426
|
+
export const reportResolutionSchema = z.enum([
|
|
427
|
+
'ignore',
|
|
428
|
+
'remove',
|
|
429
|
+
'warn',
|
|
430
|
+
'ban',
|
|
431
|
+
'other',
|
|
432
|
+
]);
|
|
433
|
+
export const reportDataSchema = z
|
|
434
|
+
.object({
|
|
435
|
+
comment: z.string().max(1000),
|
|
436
|
+
uri: z.string().url().optional(),
|
|
437
|
+
forward: z.boolean().optional(),
|
|
438
|
+
category: z.enum(['spam', 'violation', 'other']),
|
|
439
|
+
ruleIds: z.array(z.number()).optional(),
|
|
440
|
+
resolution: reportResolutionSchema.optional(),
|
|
441
|
+
})
|
|
442
|
+
.openapi('Report');
|
|
443
|
+
export const reportSchema = modelSchema(reportDataSchema);
|
|
444
|
+
export const notificationDataSchema = z.object({
|
|
445
|
+
type: z.string(),
|
|
446
|
+
profileId: z.string().uuid(),
|
|
447
|
+
pushHandled: z.boolean().optional(),
|
|
448
|
+
emailHandled: z.boolean().optional(),
|
|
449
|
+
read: z.boolean().optional(),
|
|
450
|
+
seen: z.boolean().optional(),
|
|
451
|
+
postId: z.string().optional(),
|
|
452
|
+
fromProfileId: z.string().uuid().optional(),
|
|
453
|
+
groupId: z.string().uuid().optional(),
|
|
454
|
+
data: z.unknown().optional(),
|
|
455
|
+
});
|
|
456
|
+
export const notificationSchema = modelSchema(notificationDataSchema);
|
|
457
|
+
export const configDataSchema = z.object({
|
|
458
|
+
config: z.any(),
|
|
459
|
+
});
|
|
460
|
+
export const configDataWithDefaultsSchema = configDataSchema.extend({
|
|
461
|
+
defaults: z.any(),
|
|
462
|
+
});
|
|
463
|
+
export const alertsSchema = z.object({
|
|
464
|
+
poll: z.boolean(),
|
|
465
|
+
followRequest: z.boolean(),
|
|
466
|
+
status: z.boolean(),
|
|
467
|
+
favorite: z.boolean(),
|
|
468
|
+
follow: z.boolean(),
|
|
469
|
+
repost: z.boolean(),
|
|
470
|
+
mention: z.boolean(),
|
|
471
|
+
update: z.boolean(),
|
|
472
|
+
admin: z.object({
|
|
473
|
+
signUp: z.boolean(),
|
|
474
|
+
report: z.boolean(),
|
|
475
|
+
}),
|
|
476
|
+
});
|
|
477
|
+
const pushSubscriptionWebDataSchema = z.object({
|
|
478
|
+
type: z.literal('web'),
|
|
479
|
+
deviceName: z.string().optional(),
|
|
480
|
+
endpoint: z.string().url(),
|
|
481
|
+
keys: z.object({
|
|
482
|
+
auth: z.string(),
|
|
483
|
+
p256dh: z.string(),
|
|
484
|
+
}),
|
|
485
|
+
alerts: alertsSchema.optional(),
|
|
486
|
+
});
|
|
487
|
+
const pushSubscriptionApnDataSchema = z.object({
|
|
488
|
+
type: z.literal('apn'),
|
|
489
|
+
deviceName: z.string().optional(),
|
|
490
|
+
apnToken: z.string(),
|
|
491
|
+
alerts: alertsSchema.optional(),
|
|
492
|
+
});
|
|
493
|
+
const pushSubscriptionFcmDataSchema = z.object({
|
|
494
|
+
type: z.literal('fcm'),
|
|
495
|
+
deviceName: z.string().optional(),
|
|
496
|
+
fcmToken: z.string(),
|
|
497
|
+
alerts: alertsSchema.optional(),
|
|
498
|
+
});
|
|
499
|
+
const pushSubscriptionWebhookDataSchema = z.object({
|
|
500
|
+
type: z.literal('webhook'),
|
|
501
|
+
url: z.url(),
|
|
502
|
+
publicKey: z.string().min(1),
|
|
503
|
+
alerts: alertsSchema.optional(),
|
|
504
|
+
});
|
|
505
|
+
export const pushSubscriptionDataSchema = z.discriminatedUnion('type', [
|
|
506
|
+
pushSubscriptionWebDataSchema,
|
|
507
|
+
pushSubscriptionApnDataSchema,
|
|
508
|
+
pushSubscriptionFcmDataSchema,
|
|
509
|
+
pushSubscriptionWebhookDataSchema,
|
|
510
|
+
]);
|
|
511
|
+
export const pushSubscriptionSchema = z.discriminatedUnion('type', [
|
|
512
|
+
modelSchema(pushSubscriptionWebDataSchema),
|
|
513
|
+
modelSchema(pushSubscriptionApnDataSchema),
|
|
514
|
+
modelSchema(pushSubscriptionFcmDataSchema),
|
|
515
|
+
modelSchema(pushSubscriptionWebhookDataSchema),
|
|
516
|
+
]);
|
|
517
|
+
export const reactionTypeSchema = z.enum(['👍']);
|
|
518
|
+
export const reactionDataSchema = z.object({
|
|
519
|
+
reaction: reactionTypeSchema,
|
|
520
|
+
});
|
|
521
|
+
export const mentionDataSchema = z.object({
|
|
522
|
+
text: z.string().optional(),
|
|
523
|
+
});
|
|
524
|
+
export const timelineValueSchema = z.object({
|
|
525
|
+
start: z.string().datetime(),
|
|
526
|
+
end: z.string().datetime(),
|
|
527
|
+
value: z.number(),
|
|
528
|
+
});
|
|
529
|
+
export const profileStatsSchema = z.object({
|
|
530
|
+
followersCount: z.number(),
|
|
531
|
+
followingCount: z.number(),
|
|
532
|
+
});
|
|
533
|
+
export const groupDataSchema = z.object({
|
|
534
|
+
handle: accountNameSchema,
|
|
535
|
+
avatar: z.string().url().nullable().optional(),
|
|
536
|
+
header: z.string().url().nullable().optional(),
|
|
537
|
+
displayName: z.string().max(30).optional(),
|
|
538
|
+
description: z.string().optional(),
|
|
539
|
+
rules: z.string().optional(),
|
|
540
|
+
pinnedPostId: z.string().optional(),
|
|
541
|
+
discoverable: z.boolean().optional(),
|
|
542
|
+
capabilities: z.record(z.string(), capabilitiesSchema),
|
|
543
|
+
});
|
|
544
|
+
export const groupSchema = modelSchema(groupDataSchema);
|
|
545
|
+
export const groupRoleSchema = z.object({
|
|
546
|
+
roles: z.enum(groupRelationships).array().optional().nullable(),
|
|
547
|
+
});
|
|
548
|
+
export const guestDataSchema = z.object({
|
|
549
|
+
displayName: z.string(),
|
|
550
|
+
email: z.email(),
|
|
551
|
+
});
|
|
552
|
+
export const jamEventDataSchema = z.object({
|
|
553
|
+
id: z.string(),
|
|
554
|
+
jamId: z.string(),
|
|
555
|
+
type: z.enum([
|
|
556
|
+
'message',
|
|
557
|
+
'reaction',
|
|
558
|
+
'join',
|
|
559
|
+
'leave',
|
|
560
|
+
'start',
|
|
561
|
+
'close',
|
|
562
|
+
'recordStart',
|
|
563
|
+
'recordStop',
|
|
564
|
+
]),
|
|
565
|
+
profileId: z.string(),
|
|
566
|
+
content: z.string().optional(),
|
|
567
|
+
reaction: reactionTypeSchema.optional(),
|
|
568
|
+
});
|
|
569
|
+
export const jamEventSchema = modelSchema(jamEventDataSchema);
|
|
570
|
+
export const inviteLinkDataSchema = z.object({
|
|
571
|
+
slug: z.string(),
|
|
572
|
+
active: z.boolean(),
|
|
573
|
+
emailPatterns: z.string().array().optional(),
|
|
574
|
+
maxUses: z.number(),
|
|
575
|
+
expiresAt: z.string().datetime(),
|
|
576
|
+
customInvitationMessage: z.string().optional(),
|
|
577
|
+
/** New members who redeem this link are added to these groups (as members). */
|
|
578
|
+
groupIds: z.array(z.string()).optional(),
|
|
579
|
+
});
|
|
580
|
+
export const inviteLinkSchema = modelSchema(inviteLinkDataSchema);
|
|
581
|
+
export const hashtagDataSchema = z.object({
|
|
582
|
+
tag: z.string().optional(),
|
|
583
|
+
});
|
|
584
|
+
export const hashtagSchema = modelSchema(hashtagDataSchema);
|
|
585
|
+
export const normalizeHashtagTag = (tag) => tag.toLowerCase();
|
|
586
|
+
export const hashtagRegexBase = '(?<!\\S)#([a-z0-9_]+)(?![a-z0-9_])';
|
|
587
|
+
export const hashtagRegex = new RegExp(hashtagRegexBase, 'gi');
|
|
588
|
+
export const jamRecordingTypeSchema = z.enum([
|
|
589
|
+
'compositeVideo',
|
|
590
|
+
'compositeAudio',
|
|
591
|
+
'streams',
|
|
592
|
+
]);
|
|
593
|
+
export const jamRecordingDataSchema = z.object({
|
|
594
|
+
status: z.enum(['requested', 'active', 'completed', 'failed']),
|
|
595
|
+
egressId: z.string().optional(),
|
|
596
|
+
attachment: mediaAttachmentSchema.optional(),
|
|
597
|
+
replyPostId: z.string().optional(),
|
|
598
|
+
});
|
|
599
|
+
export const jamRecordingSchema = modelSchema(jamRecordingDataSchema);
|