@openpeepshq/common 0.1.46 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/dist/lib/adminSections.js +1 -1
  2. package/dist/lib/capabilitiesHelpers.js +30 -40
  3. package/dist/lib/csvHelpers.js +1 -1
  4. package/dist/lib/eventIcs.js +26 -32
  5. package/dist/lib/eventRecurrence.d.ts +17 -0
  6. package/dist/lib/eventRecurrence.js +75 -18
  7. package/dist/lib/eventTime.js +9 -11
  8. package/dist/lib/groupHelpers.js +13 -34
  9. package/dist/lib/groupTemplateHelpers.js +6 -10
  10. package/dist/lib/jamHelpers.js +6 -9
  11. package/dist/lib/markdownHelpers.d.ts +37 -0
  12. package/dist/lib/markdownHelpers.js +151 -3
  13. package/dist/lib/postHelpers.js +70 -97
  14. package/dist/lib/profileHelpers.js +17 -24
  15. package/dist/lib/pushHelpers.js +3 -4
  16. package/dist/lib/scopeHelpers.js +6 -9
  17. package/dist/lib/ssoLoginUrl.js +4 -6
  18. package/dist/lib/ssoProviders.js +35 -39
  19. package/dist/lib/tokenHelpers.js +5 -5
  20. package/dist/lib/utils.js +6 -7
  21. package/dist/types/admin-db.js +1 -1
  22. package/dist/types/api.d.ts +1 -0
  23. package/dist/types/api.js +1 -1
  24. package/dist/types/config.d.ts +3 -0
  25. package/dist/types/config.js +3 -0
  26. package/dist/types/models.js +1 -1
  27. package/dist/types/plugins.js +2 -2
  28. package/dist/zod.d.ts +1 -0
  29. package/dist/zod.js +1 -0
  30. package/package.json +36 -6
  31. package/src/index.ts +4 -0
  32. package/src/lib/adminSections.ts +84 -0
  33. package/src/lib/attachmentHelpers.ts +14 -0
  34. package/src/lib/capabilitiesHelpers.ts +532 -0
  35. package/src/lib/colors.ts +20 -0
  36. package/src/lib/csvHelpers.ts +31 -0
  37. package/src/lib/eventIcs.ts +265 -0
  38. package/src/lib/eventRecurrence.ts +495 -0
  39. package/src/lib/eventTime.ts +206 -0
  40. package/src/lib/federationHosts.ts +22 -0
  41. package/src/lib/feedCursor.ts +27 -0
  42. package/src/lib/feedFormat.ts +24 -0
  43. package/src/lib/groupHelpers.ts +421 -0
  44. package/src/lib/groupTemplateHelpers.ts +83 -0
  45. package/src/lib/index.ts +29 -0
  46. package/src/lib/jamHelpers.ts +164 -0
  47. package/src/lib/legacyThemeRoot.ts +14 -0
  48. package/src/lib/markdownHelpers.ts +290 -0
  49. package/src/lib/mediaDimensions.ts +21 -0
  50. package/src/lib/postHelpers.ts +783 -0
  51. package/src/lib/profileHelpers.ts +220 -0
  52. package/src/lib/pushHelpers.ts +34 -0
  53. package/src/lib/reactions.ts +52 -0
  54. package/src/lib/reportHelpers.ts +7 -0
  55. package/src/lib/scopeHelpers.ts +176 -0
  56. package/src/lib/ssoLoginUrl.ts +93 -0
  57. package/src/lib/ssoProviders.ts +472 -0
  58. package/src/lib/text.ts +26 -0
  59. package/src/lib/timeZone.ts +52 -0
  60. package/src/lib/tokenHelpers.ts +119 -0
  61. package/src/lib/utils.ts +322 -0
  62. package/src/types/admin-db.ts +74 -0
  63. package/src/types/admin-email.ts +55 -0
  64. package/src/types/admin-jobs.ts +17 -0
  65. package/src/types/admin-performance.ts +20 -0
  66. package/src/types/analytics.ts +318 -0
  67. package/src/types/api.ts +871 -0
  68. package/src/types/apple-app-site-association.ts +54 -0
  69. package/src/types/auth.ts +22 -0
  70. package/src/types/capabilities.ts +280 -0
  71. package/src/types/config.ts +546 -0
  72. package/src/types/db.ts +138 -0
  73. package/src/types/export.ts +10 -0
  74. package/src/types/index.ts +20 -0
  75. package/src/types/internal.ts +338 -0
  76. package/src/types/models.ts +939 -0
  77. package/src/types/notifications.ts +92 -0
  78. package/src/types/plugins.ts +150 -0
  79. package/src/types/roleDefaults.ts +132 -0
  80. package/src/types/stats.ts +195 -0
  81. package/src/types/stripe.ts +45 -0
  82. package/src/types/utils.ts +100 -0
  83. package/src/zod.ts +1 -0
@@ -0,0 +1,338 @@
1
+ import { z } from 'zod';
2
+ import {
3
+ Account,
4
+ accountSchema,
5
+ baseSchemaShape,
6
+ Profile,
7
+ ProfileStats,
8
+ profileStatsSchema,
9
+ Role,
10
+ profileDataSchema,
11
+ idSchemaShape,
12
+ roleSchema,
13
+ profileSchema,
14
+ groupDataSchema,
15
+ modelSchema,
16
+ groupRoleSchema,
17
+ mentionDataSchema,
18
+ reactionDataSchema,
19
+ answerSchema,
20
+ rsvpSchema,
21
+ postDataUnionSchema,
22
+ postTypeSchema,
23
+ visibilityTypeSchema,
24
+ applicationDataSchema,
25
+ hashtagSchema,
26
+ Hashtag,
27
+ accountInteractionsSchema,
28
+ GroupRoleData,
29
+ inviteLinkSchema,
30
+ InviteLink,
31
+ Model,
32
+ reportSchema,
33
+ ProfileData,
34
+ Report,
35
+ groupSchema,
36
+ Group,
37
+ jamRecordingSchema,
38
+ JamRecording,
39
+ accessTokenSchema,
40
+ AccessToken,
41
+ scopeSchema,
42
+ Scope,
43
+ } from './models';
44
+ import { jsonSchema } from './utils';
45
+
46
+ export const groupWithMetaSchema = groupDataSchema.extend({
47
+ ...baseSchemaShape,
48
+ ...idSchemaShape,
49
+ membersCount: z.number(),
50
+ lastPostAt: z.string().datetime().nullable().optional(),
51
+ });
52
+
53
+ export const adminGroupSchema = groupWithMetaSchema.extend({
54
+ postsCount: z.number(),
55
+ owners: profileSchema.array(),
56
+ });
57
+
58
+ export const membershipSchema = groupRoleSchema.extend({
59
+ group: modelSchema(groupWithMetaSchema),
60
+ });
61
+
62
+ export type Membership = z.infer<typeof membershipSchema>;
63
+
64
+ export type GroupWithMeta = z.infer<typeof groupWithMetaSchema>;
65
+ export type GroupWithMetaInput = z.input<typeof groupWithMetaSchema>;
66
+ export type AdminGroup = z.infer<typeof adminGroupSchema>;
67
+
68
+ export const profileWithMetaSchema = profileDataSchema.extend({
69
+ ...baseSchemaShape,
70
+ ...idSchemaShape,
71
+ roles: roleSchema.array(),
72
+ followers: profileSchema.array(),
73
+ following: profileSchema.array(),
74
+ controllers: accountSchema.array(),
75
+ memberships: membershipSchema.array(),
76
+ profileStats: profileStatsSchema,
77
+ blockingIds: z.array(z.string()).default([]),
78
+ blockedByIds: z.array(z.string()).default([]),
79
+ followedHashtags: hashtagSchema.array().default([]),
80
+ });
81
+
82
+ /** Actor/object columns used internally; omitted from public profile JSON. */
83
+ export type ProfileActorFields = {
84
+ uri?: string | null;
85
+ inboxUrl?: string | null;
86
+ sharedInboxUrl?: string | null;
87
+ publicKeyPem?: string | null;
88
+ keyId?: string | null;
89
+ fetchedAt?: string | null;
90
+ };
91
+
92
+ export type ProfileWithMeta = Model<ProfileData> &
93
+ ProfileActorFields & {
94
+ roles: Role[];
95
+ followers: Profile[];
96
+ following: Profile[];
97
+ controllers: Account[];
98
+ memberships: Membership[];
99
+ profileStats: ProfileStats;
100
+ blockingIds: string[];
101
+ blockedByIds: string[];
102
+ followedHashtags: Hashtag[];
103
+ };
104
+
105
+ export const memberExportStatsSchema = z.object({
106
+ postsCount: z.number(),
107
+ reactionsCount: z.number(),
108
+ lastSeen: z.iso.datetime().nullable(),
109
+ });
110
+
111
+ export type MemberExportStats = z.infer<typeof memberExportStatsSchema>;
112
+
113
+ export type MemberExportRow = ProfileWithMeta & MemberExportStats;
114
+
115
+ export const accessTokenWithMetaSchema = accessTokenSchema.extend({
116
+ profile: profileWithMetaSchema,
117
+ scopes: z.array(scopeSchema).optional(),
118
+ });
119
+ export type AccessTokenWithMeta = AccessToken & {
120
+ ownedBy?: ProfileWithMeta;
121
+ scopes?: Scope[];
122
+ };
123
+
124
+ export const mentionWithProfileSchema = mentionDataSchema.extend({
125
+ profile: profileWithMetaSchema,
126
+ });
127
+ export type MentionWithProfile = z.infer<typeof mentionWithProfileSchema>;
128
+
129
+ const reactionWithProfileSchema = reactionDataSchema.extend({
130
+ profile: profileWithMetaSchema,
131
+ });
132
+ export type ReactionProfile = z.infer<typeof reactionWithProfileSchema>;
133
+
134
+ const repostWithProfileSchema = z.object({
135
+ profile: profileWithMetaSchema,
136
+ createdAt: z.string().datetime(),
137
+ });
138
+ export type RepostWithProfile = z.infer<typeof repostWithProfileSchema>;
139
+
140
+ const _answerWithProfileSchema = answerSchema.extend({
141
+ profile: profileWithMetaSchema,
142
+ });
143
+ export type AnswerWithProfile = z.infer<typeof _answerWithProfileSchema>;
144
+
145
+ const rsvpWithMetaSchema = rsvpSchema.extend({
146
+ profile: profileWithMetaSchema,
147
+ createdAt: z.string().datetime(),
148
+ });
149
+ export type RSVPWithMeta = z.infer<typeof rsvpWithMetaSchema>;
150
+
151
+ export const entryWithProfileSchema = z.discriminatedUnion('type', [
152
+ z.object({
153
+ type: z.literal('create'),
154
+ data: postDataUnionSchema,
155
+ profile: profileWithMetaSchema,
156
+ createdAt: z.string().datetime(),
157
+ }),
158
+ z.object({
159
+ type: z.literal('edit'),
160
+ data: postDataUnionSchema,
161
+ profile: profileWithMetaSchema,
162
+ createdAt: z.string().datetime(),
163
+ }),
164
+ z.object({
165
+ type: z.literal('delete'),
166
+ data: z.any(),
167
+ profile: profileWithMetaSchema,
168
+ createdAt: z.string().datetime(),
169
+ }),
170
+ z.object({
171
+ type: z.literal('answer'),
172
+ data: answerSchema,
173
+ profile: profileWithMetaSchema,
174
+ createdAt: z.string().datetime(),
175
+ }),
176
+ z.object({
177
+ type: z.literal('rsvp'),
178
+ data: rsvpSchema,
179
+ profile: profileWithMetaSchema,
180
+ createdAt: z.string().datetime(),
181
+ }),
182
+ ]);
183
+
184
+ export type EntryWithProfile = z.infer<typeof entryWithProfileSchema>;
185
+
186
+ export const replyPostSchema = z.object({
187
+ id: z.string(),
188
+ type: postTypeSchema,
189
+ profile: profileWithMetaSchema,
190
+ data: postDataUnionSchema,
191
+ creatorId: z.string(),
192
+ entries: entryWithProfileSchema.array(),
193
+ createdAt: z.string().datetime(),
194
+ deletedAt: z.string().datetime().optional().nullable(),
195
+ visibility: visibilityTypeSchema,
196
+ group: groupWithMetaSchema.optional().nullable(),
197
+ audience: z.array(profileWithMetaSchema).optional().nullable(),
198
+ seen: z.boolean().optional(),
199
+ inReplyToId: z.string().optional().nullable(),
200
+ hidden: z.boolean().optional(),
201
+ });
202
+ export type ReplyPost = z.infer<typeof replyPostSchema> & {
203
+ replyTo?: ReplyPost | null;
204
+ };
205
+
206
+ const basePostSchema = replyPostSchema.extend({
207
+ repostCount: z.number(),
208
+ replyCount: z.number(),
209
+ reactions: reactionWithProfileSchema.array(),
210
+ /** Capped lean list of who reposted (most recent). Count stays in repostCount. */
211
+ reposts: repostWithProfileSchema.array(),
212
+ application: applicationDataSchema.optional(),
213
+ mentions: z.array(mentionWithProfileSchema),
214
+ tags: z.array(hashtagSchema),
215
+ groupId: z.string().optional().nullable(),
216
+ groupDiscoverable: z.boolean().optional().nullable(),
217
+ updatedAt: z.string().datetime(),
218
+ accountInteractions: accountInteractionsSchema.optional(),
219
+ rsvps: rsvpWithMetaSchema.array(),
220
+ seen: z.boolean().optional(),
221
+ occurrenceRecurrenceId: z.string().datetime().optional(),
222
+ occurrenceStart: z.string().datetime().optional(),
223
+ occurrenceEnd: z.string().datetime().optional(),
224
+ });
225
+ export type BasePost = z.infer<typeof basePostSchema> & {
226
+ latestReplies?: ReplyPost[];
227
+ latestRepliesHasMore?: boolean;
228
+ lastActivityAt?: string;
229
+ };
230
+
231
+ const withReplyPostSchema = basePostSchema.extend({
232
+ inReplyToId: z.string().optional().nullable(),
233
+ replyTo: replyPostSchema.optional().nullable(),
234
+ });
235
+
236
+ export const postWithMetaSchema = withReplyPostSchema
237
+ .extend({
238
+ repost: basePostSchema.optional().nullable(),
239
+ })
240
+ .openapi('Post');
241
+
242
+ export type PostWithMetaInput = z.input<typeof postWithMetaSchema>;
243
+ export type PostWithMeta = BasePost & {
244
+ uri?: string | null;
245
+ inReplyToUri?: string | null;
246
+ inReplyToId?: string | null;
247
+ replyTo?: ReplyPost | null;
248
+ repost?: BasePost | null;
249
+ occurrenceRecurrenceId?: string;
250
+ occurrenceStart?: string;
251
+ occurrenceEnd?: string;
252
+ };
253
+
254
+ export interface ExpandedNotification {
255
+ id: string;
256
+ profileId: string;
257
+ pushHandled?: boolean;
258
+ emailHandled?: boolean;
259
+ type: string;
260
+ seen?: boolean;
261
+ read?: boolean;
262
+ createdAt: string;
263
+ updatedAt: string;
264
+ recipientProfile: z.infer<typeof profileWithMetaSchema>;
265
+ senderProfile?: z.infer<typeof profileWithMetaSchema> | null;
266
+ group?: Group | null;
267
+ post?: PostWithMeta | null;
268
+ data?: unknown;
269
+ }
270
+
271
+ export const expandedNotificationSchema = z.object({
272
+ id: z.string().uuid(),
273
+ profileId: z.string().uuid(),
274
+ pushHandled: z.boolean().optional(),
275
+ emailHandled: z.boolean().optional(),
276
+ type: z.string(),
277
+ seen: z.boolean().optional(),
278
+ read: z.boolean().optional(),
279
+ createdAt: z.string().datetime(),
280
+ updatedAt: z.string().datetime(),
281
+ recipientProfile: profileWithMetaSchema,
282
+ senderProfile: profileWithMetaSchema.nullable().optional(),
283
+ group: groupSchema.nullable().optional(),
284
+ post: postWithMetaSchema.nullable().optional(),
285
+ data: jsonSchema.optional(),
286
+ });
287
+
288
+ export const groupMemberSchema = groupRoleSchema.extend({
289
+ profile: profileWithMetaSchema,
290
+ });
291
+
292
+ export interface GroupMember extends GroupRoleData {
293
+ profile: ProfileWithMeta;
294
+ }
295
+
296
+ export const inviteLinkWithMetaSchema = inviteLinkSchema.extend({
297
+ profile: profileWithMetaSchema,
298
+ redemptions: profileWithMetaSchema.array(),
299
+ /** Resolved from `groupIds` by the mapping so the UI can show group names. */
300
+ groups: groupWithMetaSchema.array(),
301
+ });
302
+
303
+ export interface InviteLinkWithMeta extends InviteLink {
304
+ profile: ProfileWithMeta;
305
+ redemptions: ProfileWithMeta[];
306
+ groups: GroupWithMeta[];
307
+ }
308
+
309
+ export interface PostContext {
310
+ ancestors: PostWithMetaInput[];
311
+ descendants: PostWithMetaInput[];
312
+ }
313
+
314
+ export const postContextSchema: z.ZodType<PostContext> = z.object({
315
+ ancestors: postWithMetaSchema.array(),
316
+ descendants: postWithMetaSchema.array(),
317
+ });
318
+
319
+ export const reportWithMetaSchema = reportSchema.extend({
320
+ reporterProfile: profileWithMetaSchema,
321
+ reportedProfile: profileWithMetaSchema,
322
+ reportedPosts: z.array(postWithMetaSchema),
323
+ });
324
+ export type ReportWithMeta = Report & {
325
+ reporterProfile: ProfileWithMeta;
326
+ reportedProfile: ProfileWithMeta;
327
+ reportedPosts: PostWithMeta[];
328
+ };
329
+
330
+ export const jamRecordingWithMetaSchema = jamRecordingSchema.extend({
331
+ profile: profileWithMetaSchema,
332
+ post: postWithMetaSchema,
333
+ });
334
+
335
+ export type JamRecordingWithMeta = JamRecording & {
336
+ profile: ProfileWithMeta;
337
+ post: PostWithMeta;
338
+ };