@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,92 @@
1
+ import { z } from 'zod';
2
+ import { roleCapabilities, RoleCapability } from './capabilities';
3
+ import { ExpandedNotification } from './internal';
4
+
5
+ export const actionSchema = z.object({
6
+ action: z.string(),
7
+ title: z.string(),
8
+ });
9
+ export type Action = z.infer<typeof actionSchema>;
10
+ export type ActionType = { actions?: { action: string; title: string }[] };
11
+
12
+ export const notificationOptionsSchema = z.object({
13
+ body: z.string().optional(),
14
+ icon: z.string().optional(),
15
+ image: z.string().optional(),
16
+ link: z.string().optional(),
17
+ tag: z.string().optional(),
18
+ badge: z.number().optional(),
19
+ data: z.record(z.string(), z.unknown()).optional(),
20
+ actions: actionSchema.array().optional(),
21
+ });
22
+ export type NotificationOptions = z.infer<typeof notificationOptionsSchema>;
23
+
24
+ export const pushNotificationSchema = z.object({
25
+ title: z.string().optional(),
26
+ options: notificationOptionsSchema.optional(),
27
+ invalidateQueries: z.array(z.array(z.string())).optional(),
28
+ });
29
+ export type PushNotification = z.infer<typeof pushNotificationSchema>;
30
+
31
+ export const notificationStatsSchema = z.object({
32
+ unread: z.number(),
33
+ unseen: z.number(),
34
+ });
35
+ export type NotificationStats = z.infer<typeof notificationStatsSchema>;
36
+
37
+ export interface PushMessage {
38
+ notificationStats: NotificationStats;
39
+ notification: PushNotification;
40
+ }
41
+
42
+ /** Session SSE / presence platform. */
43
+ export const sessionPlatformSchema = z.enum(['web', 'ios', 'android']);
44
+ export type SessionPlatform = z.infer<typeof sessionPlatformSchema>;
45
+
46
+ /** Invalidate-light envelope mirrored from web push. */
47
+ export const sessionEventSchema = z.object({
48
+ type: z.literal('invalidate'),
49
+ notification: pushNotificationSchema.optional(),
50
+ notificationStats: notificationStatsSchema.optional(),
51
+ });
52
+ export type SessionEvent = z.infer<typeof sessionEventSchema>;
53
+
54
+ export interface NotificationHandler {
55
+ type: string;
56
+ event: string;
57
+ requiredCapabilities?: RoleCapability[];
58
+ defaultSettings?: { create: boolean; push: boolean; email: boolean };
59
+ eventHandler: (...data: unknown[]) => Promise<void> | void;
60
+ expander?: (
61
+ notification: ExpandedNotification,
62
+ ) => Promise<ExpandedNotification>;
63
+ pushRenderer: (
64
+ notification: ExpandedNotification,
65
+ ) => Promise<PushNotification>;
66
+ }
67
+
68
+ export const notificationTypeSchema = z.object({
69
+ type: z.string(),
70
+ requiredCapabilities: z.enum(roleCapabilities).array().optional(),
71
+ defaultSettings: z.object({
72
+ create: z.boolean(),
73
+ push: z.boolean(),
74
+ email: z.boolean(),
75
+ }).optional(),
76
+ });
77
+
78
+ export type NotificationType = z.infer<typeof notificationTypeSchema>;
79
+
80
+ export const notificationDefaults = {
81
+ create: true,
82
+ push: true,
83
+ email: false,
84
+ } as const;
85
+
86
+ export const notificationAll = {
87
+ create: true,
88
+ push: true,
89
+ email: true,
90
+ } as const;
91
+
92
+
@@ -0,0 +1,150 @@
1
+ import { z } from 'zod';
2
+ import { PackageJson } from 'type-fest';
3
+
4
+ export interface Plugin {
5
+ key: string;
6
+ namespace: string;
7
+ name: string;
8
+ info: PackageJson;
9
+ path: string;
10
+ status?: 'loaded' | 'failed' | 'disabled';
11
+ error?: string;
12
+ }
13
+
14
+ export const pluginInfoSchema = z.object({
15
+ key: z.string(),
16
+ namespace: z.string(),
17
+ name: z.string(),
18
+ version: z.string().optional(),
19
+ displayName: z.string().optional(),
20
+ description: z.string().optional(),
21
+ status: z.enum(['loaded', 'failed', 'disabled']).optional(),
22
+ });
23
+
24
+ export type PluginInfo = z.infer<typeof pluginInfoSchema>;
25
+
26
+ export const adminPluginInfoSchema = pluginInfoSchema.extend({
27
+ error: z.string().optional(),
28
+ /** Persisted desired state (DB override, falling back to the static gate). */
29
+ enabled: z.boolean(),
30
+ repositoryUrl: z.string().optional(),
31
+ /** True when installed via the admin UI (can be uninstalled). */
32
+ installed: z.boolean().optional(),
33
+ });
34
+
35
+ export type AdminPluginInfo = z.infer<typeof adminPluginInfoSchema>;
36
+
37
+ const npmPluginInstallAuthSchema = z.object({
38
+ token: z.string().min(1),
39
+ registry: z
40
+ .string()
41
+ .url()
42
+ .refine(
43
+ (value) => {
44
+ const url = new URL(value);
45
+ return url.protocol === 'https:' && !url.username && !url.password;
46
+ },
47
+ {
48
+ message: 'Registry URL must use HTTPS and must not contain credentials',
49
+ },
50
+ )
51
+ .optional(),
52
+ });
53
+
54
+ const gitPluginInstallAuthSchema = z.discriminatedUnion('type', [
55
+ z.object({
56
+ type: z.literal('token'),
57
+ username: z.string().min(1),
58
+ token: z.string().min(1),
59
+ }),
60
+ z.object({
61
+ type: z.literal('ssh'),
62
+ privateKey: z.string().min(1),
63
+ }),
64
+ ]);
65
+
66
+ export const pluginInstallSourceSchema = z.discriminatedUnion('type', [
67
+ z.object({
68
+ type: z.literal('npm'),
69
+ package: z
70
+ .string()
71
+ .regex(
72
+ /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/i,
73
+ 'Enter an npm package name',
74
+ ),
75
+ version: z.string().optional(),
76
+ auth: npmPluginInstallAuthSchema.optional(),
77
+ }),
78
+ z
79
+ .object({
80
+ type: z.literal('git'),
81
+ url: z.string().url(),
82
+ ref: z.string().optional(),
83
+ auth: gitPluginInstallAuthSchema.optional(),
84
+ })
85
+ .superRefine(({ auth, url }, context) => {
86
+ const parsedUrl = new URL(url);
87
+ if (
88
+ parsedUrl.password ||
89
+ (parsedUrl.username && parsedUrl.protocol !== 'ssh:')
90
+ ) {
91
+ context.addIssue({
92
+ code: 'custom',
93
+ message: 'Repository URLs must not contain credentials',
94
+ path: ['url'],
95
+ });
96
+ }
97
+ if (auth?.type === 'token' && parsedUrl.protocol !== 'https:') {
98
+ context.addIssue({
99
+ code: 'custom',
100
+ message: 'Token authentication requires an HTTPS repository URL',
101
+ path: ['url'],
102
+ });
103
+ }
104
+ if (auth?.type === 'ssh' && parsedUrl.protocol !== 'ssh:') {
105
+ context.addIssue({
106
+ code: 'custom',
107
+ message: 'SSH authentication requires an ssh:// repository URL',
108
+ path: ['url'],
109
+ });
110
+ }
111
+ }),
112
+ ]);
113
+
114
+ export type PluginInstallSource = z.infer<typeof pluginInstallSourceSchema>;
115
+
116
+ export const pluginManifestSchema = z.object({
117
+ components: z
118
+ .array(
119
+ z.object({
120
+ slot: z.string(),
121
+ asset: z.string(),
122
+ componentKey: z.string(),
123
+ }),
124
+ )
125
+ .default([]),
126
+ });
127
+
128
+ export type PluginManifest = z.infer<typeof pluginManifestSchema>;
129
+
130
+ export const pluginEntrySchema = pluginInfoSchema.extend({
131
+ manifest: pluginManifestSchema.optional(),
132
+ });
133
+
134
+ export type PluginEntry = z.infer<typeof pluginEntrySchema>;
135
+
136
+ export const pluginConfigItemSchema = z.object({
137
+ namespace: z.string(),
138
+ name: z.string(),
139
+ config: z.record(z.string(), z.unknown()),
140
+ defaults: z.record(z.string(), z.unknown()),
141
+ });
142
+
143
+ export type PluginConfigItem = z.infer<typeof pluginConfigItemSchema>;
144
+
145
+ export const pluginConfigResponseSchema = z.record(
146
+ z.string(),
147
+ z.record(z.string(), pluginConfigItemSchema),
148
+ );
149
+
150
+ export type PluginConfigResponse = z.infer<typeof pluginConfigResponseSchema>;
@@ -0,0 +1,132 @@
1
+ import type { RoleData } from './models';
2
+
3
+ /**
4
+ * One point in the history of the built-in role defaults. Entries are
5
+ * immutable: when the defaults change, append a new entry dated with the
6
+ * creation date. The last entry is always the current one — it is used for
7
+ * seeding on server start and as the rebase target for customized roles.
8
+ */
9
+ export interface RoleDefaultsVersion {
10
+ /** ISO date the version was created. */
11
+ version: string;
12
+ roles: RoleData[];
13
+ }
14
+
15
+ /** Stamps the version onto the roles so a stored role records its baseline. */
16
+ const versionedRoles = (version: string, roles: RoleData[]): RoleData[] =>
17
+ roles.map((role) => ({ ...role, baseVersion: version }));
18
+
19
+ export const roleDefaultsHistory: RoleDefaultsVersion[] = [
20
+ {
21
+ version: '2026-10-06',
22
+ roles: versionedRoles('2026-10-06', [
23
+ {
24
+ key: 'owner',
25
+ displayName: 'Owner',
26
+ capabilities: { add: ['*'], remove: [] },
27
+ default: true,
28
+ description: 'The owner of this community can do everything',
29
+ },
30
+ {
31
+ key: 'admin',
32
+ displayName: 'Admin',
33
+ capabilities: {
34
+ add: [
35
+ 'core-accounts-*',
36
+ 'core-reports-*',
37
+ 'core-groups-*',
38
+ 'core-posts-*',
39
+ 'core-profiles-*',
40
+ 'core-customization-*',
41
+ 'core-backups-*',
42
+ 'core-i18n-*',
43
+ 'core-logs-*',
44
+ 'core-roles-read',
45
+ 'core-maintenance-restart',
46
+ 'core-inviteLinks-*',
47
+ 'core-analytics-read',
48
+ 'core-plugins-*',
49
+ ],
50
+ remove: [],
51
+ },
52
+ default: true,
53
+ description: 'An admin of the community',
54
+ },
55
+ {
56
+ key: 'moderator',
57
+ displayName: 'Moderator',
58
+ capabilities: {
59
+ add: [
60
+ 'core-posts-delete',
61
+ 'core-posts-pin-globally',
62
+ 'core-posts-announce',
63
+ 'core-profiles-suspend',
64
+ 'core-accounts-read',
65
+ 'core-profiles-read',
66
+ 'core-groups-read',
67
+ 'core-inviteLinks-read',
68
+ 'core-reports-read',
69
+ 'core-reports-update',
70
+ 'core-analytics-read',
71
+ 'core-local',
72
+ 'core-posts-create-*',
73
+ 'core-groups-create',
74
+ 'core-reports-create',
75
+ ],
76
+ remove: [],
77
+ },
78
+ default: true,
79
+ description: 'A moderator of the community',
80
+ },
81
+ {
82
+ key: 'member',
83
+ displayName: 'Member',
84
+ capabilities: {
85
+ add: [
86
+ 'core-local',
87
+ 'core-posts-create-*',
88
+ 'core-groups-create',
89
+ 'core-reports-create',
90
+ ],
91
+ remove: [],
92
+ },
93
+ default: true,
94
+ description: 'A member of the community',
95
+ },
96
+ {
97
+ key: 'pendingmember',
98
+ displayName: 'Pending Member',
99
+ capabilities: {
100
+ add: ['core-local'],
101
+ remove: [],
102
+ },
103
+ default: true,
104
+ description: 'A member of the community that has not been approved yet',
105
+ },
106
+ {
107
+ key: 'limitedmember',
108
+ displayName: 'Limited Member',
109
+ capabilities: {
110
+ add: [],
111
+ remove: [],
112
+ },
113
+ default: true,
114
+ description:
115
+ 'A member of the community that can only partcipate in group they are added to',
116
+ },
117
+ ]),
118
+ },
119
+ ];
120
+
121
+ /** The current (last) version — the one in use. */
122
+ export const currentRoleDefaults =
123
+ roleDefaultsHistory[roleDefaultsHistory.length - 1];
124
+
125
+ /**
126
+ * Built-in instance roles of the current version, seeded on server start.
127
+ * Also the reference for "restore defaults" in the admin capability matrix.
128
+ */
129
+ export const defaultRoles = currentRoleDefaults.roles;
130
+
131
+ export const findRoleDefaultsVersion = (version: string) =>
132
+ roleDefaultsHistory.find((entry) => entry.version === version);
@@ -0,0 +1,195 @@
1
+ import { z, ZodObject } from 'zod';
2
+ import { publicPostSchema, publicProfileSchema } from './api';
3
+
4
+ const objectStatsSchema = z.object({
5
+ day: z.object({
6
+ currentPeriod: z.number(),
7
+ lastPeriod: z.number(),
8
+ }),
9
+ week: z.object({
10
+ currentPeriod: z.number(),
11
+ lastPeriod: z.number(),
12
+ }),
13
+ month: z.object({
14
+ currentPeriod: z.number(),
15
+ lastPeriod: z.number(),
16
+ }),
17
+ quarter: z.object({
18
+ currentPeriod: z.number(),
19
+ lastPeriod: z.number(),
20
+ }),
21
+ year: z.object({
22
+ currentPeriod: z.number(),
23
+ lastPeriod: z.number(),
24
+ }),
25
+ });
26
+
27
+ const objectStatsWithAllSchema = objectStatsSchema.extend({
28
+ all: z.number(),
29
+ });
30
+
31
+ export type ObjectStats = z.infer<typeof objectStatsSchema>;
32
+ export type ObjectStatsWithAll = z.infer<typeof objectStatsWithAllSchema>;
33
+
34
+ export const publicPostWithActivityScoreSchema = publicPostSchema.extend({
35
+ activityScore: z.number(),
36
+ });
37
+
38
+ export type PublicPostWithActivityScore = z.infer<
39
+ typeof publicPostWithActivityScoreSchema
40
+ >;
41
+
42
+ export const publicProfileWithActivityScoreSchema = publicProfileSchema.extend({
43
+ activityScore: z.number(),
44
+ });
45
+ export type PublicProfileWithActivityScore = z.infer<
46
+ typeof publicProfileWithActivityScoreSchema
47
+ >;
48
+
49
+ export type TopListKey = 'day' | 'week' | 'month' | 'quarter' | 'year';
50
+ const topPostsListSchema = publicPostWithActivityScoreSchema.array().max(5);
51
+ const _topProfilesListSchema = publicProfileWithActivityScoreSchema
52
+ .array()
53
+ .max(5);
54
+
55
+ export const topPostsSchema: ZodObject<
56
+ Record<TopListKey, typeof topPostsListSchema>
57
+ > = z.object({
58
+ day: topPostsListSchema,
59
+ week: topPostsListSchema,
60
+ month: topPostsListSchema,
61
+ quarter: topPostsListSchema,
62
+ year: topPostsListSchema,
63
+ });
64
+
65
+ export const topProfilesSchema: ZodObject<
66
+ Record<TopListKey, typeof _topProfilesListSchema>
67
+ > = z.object({
68
+ day: publicProfileWithActivityScoreSchema.array().max(5),
69
+ week: publicProfileWithActivityScoreSchema.array().max(5),
70
+ month: publicProfileWithActivityScoreSchema.array().max(5),
71
+ quarter: publicProfileWithActivityScoreSchema.array().max(5),
72
+ year: publicProfileWithActivityScoreSchema.array().max(5),
73
+ });
74
+
75
+ export const profilesStatsSchema = z.object({
76
+ all: objectStatsWithAllSchema,
77
+ active: objectStatsWithAllSchema,
78
+ });
79
+
80
+ export const postsStatsSchema = z.object({
81
+ all: objectStatsWithAllSchema,
82
+ withoutReply: objectStatsWithAllSchema,
83
+ withReplies: objectStatsWithAllSchema,
84
+ replies: objectStatsWithAllSchema,
85
+ });
86
+
87
+ export const interactionsStatsSchema = z.object({
88
+ all: objectStatsWithAllSchema,
89
+ });
90
+
91
+ export const jamsStatsSchema = z.object({
92
+ sessions: objectStatsWithAllSchema,
93
+ participants: objectStatsWithAllSchema,
94
+ });
95
+
96
+ export const topListsStatsSchema: ZodObject<{
97
+ posts: typeof topPostsSchema;
98
+ profiles: typeof topProfilesSchema;
99
+ }> = z.object({
100
+ posts: topPostsSchema,
101
+ profiles: topProfilesSchema,
102
+ });
103
+
104
+ export const timelinesStatsSchema = z.object({
105
+ signups: z.object({
106
+ week: z
107
+ .object({
108
+ name: z.string(),
109
+ count: z.number(),
110
+ })
111
+ .array(),
112
+ fourWeeks: z
113
+ .object({
114
+ name: z.string(),
115
+ count: z.number(),
116
+ })
117
+ .array(),
118
+ fourMonths: z
119
+ .object({
120
+ name: z.string(),
121
+ count: z.number(),
122
+ })
123
+ .array(),
124
+ }),
125
+ });
126
+
127
+ export const serverCountsSchema = z.object({
128
+ profiles: z.number(),
129
+ posts: z.number(),
130
+ events: z.number(),
131
+ reactions: z.number(),
132
+ rsvps: z.number(),
133
+ });
134
+
135
+ export type ServerCounts = z.infer<typeof serverCountsSchema>;
136
+
137
+ export const hostResourceStatsSchema = z.object({
138
+ memoryUsedBytes: z.number().nonnegative(),
139
+ memoryTotalBytes: z.number().nonnegative(),
140
+ cpuUsedPercent: z.number().min(0).max(100),
141
+ });
142
+
143
+ export type HostResourceStats = z.infer<typeof hostResourceStatsSchema>;
144
+
145
+ export const adminServerStatsSchema: ZodObject<{
146
+ profiles: typeof profilesStatsSchema;
147
+ posts: typeof postsStatsSchema;
148
+ interactions: typeof interactionsStatsSchema;
149
+ jams: typeof jamsStatsSchema;
150
+ topLists: typeof topListsStatsSchema;
151
+ timelines: typeof timelinesStatsSchema;
152
+ host: typeof hostResourceStatsSchema;
153
+ }> = z.object({
154
+ profiles: profilesStatsSchema,
155
+ posts: postsStatsSchema,
156
+ interactions: interactionsStatsSchema,
157
+ jams: jamsStatsSchema,
158
+ topLists: topListsStatsSchema,
159
+ timelines: timelinesStatsSchema,
160
+ host: hostResourceStatsSchema,
161
+ });
162
+
163
+ export type AdminServerStats = z.infer<typeof adminServerStatsSchema>;
164
+
165
+ export const profileActivitySummarySchema = z.object({
166
+ postsCount: z.number().int().nonnegative(),
167
+ repliesCount: z.number().int().nonnegative(),
168
+ eventsCount: z.number().int().nonnegative(),
169
+ reactionsGiven: z.number().int().nonnegative(),
170
+ reactionsReceived: z.number().int().nonnegative(),
171
+ repostsCount: z.number().int().nonnegative(),
172
+ repostsReceived: z.number().int().nonnegative(),
173
+ repliesReceived: z.number().int().nonnegative(),
174
+ rsvpsCount: z.number().int().nonnegative(),
175
+ bookmarksCount: z.number().int().nonnegative(),
176
+ groupsCount: z.number().int().nonnegative(),
177
+ topPosts: publicPostWithActivityScoreSchema.array().max(5),
178
+ });
179
+
180
+ export type ProfileActivitySummary = z.infer<
181
+ typeof profileActivitySummarySchema
182
+ >;
183
+
184
+ export const adminProfileSummarySchema = z.object({
185
+ profile: publicProfileSchema,
186
+ activity: profileActivitySummarySchema,
187
+ createdAt: z.string().datetime(),
188
+ email: z.string().optional(),
189
+ followersCount: z.number().int().nonnegative(),
190
+ followingCount: z.number().int().nonnegative(),
191
+ reportsCount: z.number().int().nonnegative(),
192
+ blockedByCount: z.number().int().nonnegative(),
193
+ });
194
+
195
+ export type AdminProfileSummary = z.infer<typeof adminProfileSummarySchema>;
@@ -0,0 +1,45 @@
1
+ import { z } from 'zod';
2
+ import { successFailureResponseSchema } from './api';
3
+
4
+ export const stripeSubscriptionStatusSchema = z.enum([
5
+ 'incomplete',
6
+ 'incomplete_expired',
7
+ 'trialing',
8
+ 'active',
9
+ 'past_due',
10
+ 'canceled',
11
+ 'unpaid',
12
+ 'paused',
13
+ ]);
14
+
15
+ const paymentMethodSchema = z
16
+ .object({
17
+ brand: z.string().nullable(),
18
+ last4: z.string().nullable(),
19
+ })
20
+ .nullable();
21
+
22
+ export const stripeSubscriptionDataSchema = z.discriminatedUnion('status', [
23
+ z.object({
24
+ subscriptionId: z.string().nullable(),
25
+ status: stripeSubscriptionStatusSchema,
26
+ priceId: z.string().nullable(),
27
+ currentPeriodStart: z.number().nullable(),
28
+ currentPeriodEnd: z.number().nullable(),
29
+ cancelAtPeriodEnd: z.boolean(),
30
+ paymentMethod: paymentMethodSchema,
31
+ }),
32
+ z.object({
33
+ status: z.literal('none'),
34
+ }),
35
+ ]);
36
+
37
+ export const stripeCustomerPortalResponseSchema =
38
+ successFailureResponseSchema.extend({
39
+ url: z.string().optional(),
40
+ });
41
+
42
+ export type StripeSubscriptionData = z.infer<typeof stripeSubscriptionDataSchema>;
43
+ export type StripeCustomerPortalResponseSchema = z.infer<
44
+ typeof stripeCustomerPortalResponseSchema
45
+ >;