@openpeepshq/core 0.1.35 → 0.2.1

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 (92) hide show
  1. package/dist/accounts/mutations.js +9 -0
  2. package/dist/analytics/report.d.ts +1 -1
  3. package/dist/config/defaults/logs.d.ts +4 -0
  4. package/dist/config/defaults/logs.js +5 -0
  5. package/dist/config/index.d.ts +3 -328
  6. package/dist/db/explorer/index.d.ts +1 -1
  7. package/dist/db/explorer/index.js +1 -1
  8. package/dist/db/pg/filters/posts.js +1 -1
  9. package/dist/db/pg/map/registry.js +3 -2
  10. package/dist/groups/finders.d.ts +2 -2
  11. package/dist/groups/helpers.d.ts +6 -6
  12. package/dist/groups/mapping.d.ts +4 -4
  13. package/dist/jams/export.d.ts +2 -0
  14. package/dist/jams/export.js +5 -0
  15. package/dist/jams/finders.d.ts +1 -0
  16. package/dist/jams/finders.js +1 -0
  17. package/dist/jams/health.d.ts +23 -0
  18. package/dist/jams/health.js +79 -7
  19. package/dist/jams/helpers.d.ts +2 -2
  20. package/dist/jams/index.d.ts +1 -1
  21. package/dist/jams/index.js +10 -3
  22. package/dist/jams/livekit.d.ts +2 -2
  23. package/dist/jams/mapping.d.ts +10 -10
  24. package/dist/jams/mutations.d.ts +2 -2
  25. package/dist/jams/token.js +6 -2
  26. package/dist/jams/waitingRoom.js +3 -1
  27. package/dist/log/index.d.ts +1 -0
  28. package/dist/log/index.js +1 -0
  29. package/dist/log/retention.d.ts +9 -0
  30. package/dist/log/retention.js +83 -0
  31. package/dist/log/retentionJobs.d.ts +17 -0
  32. package/dist/log/retentionJobs.js +50 -0
  33. package/dist/media/garbageCollection.d.ts +109 -0
  34. package/dist/media/garbageCollection.js +603 -0
  35. package/dist/media/garbageCollectionJobs.d.ts +14 -0
  36. package/dist/media/garbageCollectionJobs.js +55 -0
  37. package/dist/media/index.d.ts +2 -0
  38. package/dist/media/index.js +91 -12
  39. package/dist/media/streaming.d.ts +2 -0
  40. package/dist/media/streaming.js +8 -0
  41. package/dist/mediaAttachments/mapping.d.ts +1 -1
  42. package/dist/notifications/defaultNotifications/index.js +2 -0
  43. package/dist/notifications/defaultNotifications/jamModerator/index.js +25 -16
  44. package/dist/notifications/defaultNotifications/jamModerator/recipients.d.ts +2 -0
  45. package/dist/notifications/defaultNotifications/jamModerator/recipients.js +5 -0
  46. package/dist/notifications/defaultNotifications/jamStarted/index.d.ts +1 -0
  47. package/dist/notifications/defaultNotifications/jamStarted/index.js +61 -13
  48. package/dist/notifications/defaultNotifications/newGroupPost/index.js +3 -3
  49. package/dist/notifications/defaultNotifications/newGroupPost/recipients.d.ts +5 -0
  50. package/dist/notifications/defaultNotifications/newGroupPost/recipients.js +23 -0
  51. package/dist/notifications/defaultNotifications/waitlistOffer/index.d.ts +24 -0
  52. package/dist/notifications/defaultNotifications/waitlistOffer/index.js +40 -0
  53. package/dist/notifications/eventIcsAttachment.d.ts +6 -0
  54. package/dist/notifications/eventIcsAttachment.js +32 -0
  55. package/dist/notifications/helpers.d.ts +11 -1
  56. package/dist/notifications/helpers.js +26 -0
  57. package/dist/notifications/index.d.ts +1 -1
  58. package/dist/notifications/index.js +1 -1
  59. package/dist/notifications/jobs.js +6 -0
  60. package/dist/notifications/mutations.js +9 -1
  61. package/dist/plugins/pluginAuth.js +1 -0
  62. package/dist/posts/activity.d.ts +1 -1
  63. package/dist/posts/activity.js +1 -1
  64. package/dist/posts/conversationQueries.d.ts +31 -0
  65. package/dist/posts/conversationQueries.js +150 -24
  66. package/dist/posts/eventAgenda.js +4 -2
  67. package/dist/posts/finders.d.ts +15 -6
  68. package/dist/posts/finders.js +23 -3
  69. package/dist/posts/helpers/index.d.ts +34 -26
  70. package/dist/posts/helpers/index.js +6 -0
  71. package/dist/posts/index.d.ts +3 -1
  72. package/dist/posts/index.js +3 -1
  73. package/dist/posts/mapping.d.ts +112 -98
  74. package/dist/posts/mutations.d.ts +24 -18
  75. package/dist/posts/mutations.js +222 -72
  76. package/dist/posts/rsvpExport.d.ts +47 -0
  77. package/dist/posts/rsvpExport.js +178 -0
  78. package/dist/posts/unseenCounts.d.ts +6 -0
  79. package/dist/posts/unseenCounts.js +51 -1
  80. package/dist/posts/waitlist.d.ts +13 -0
  81. package/dist/posts/waitlist.js +75 -0
  82. package/dist/posts/waitlistOfferJobs.d.ts +10 -0
  83. package/dist/posts/waitlistOfferJobs.js +91 -0
  84. package/dist/profileSettings/mapping.d.ts +1 -0
  85. package/dist/profiles/index.js +6 -1
  86. package/dist/profiles/mapping.d.ts +10 -10
  87. package/dist/reports/mapping.d.ts +1 -1
  88. package/dist/server/index.d.ts +1 -0
  89. package/dist/stats/mapping.d.ts +7 -6
  90. package/dist/stripe/connection.js +1 -1
  91. package/dist/stripe/helpers.js +7 -3
  92. package/package.json +11 -10
@@ -0,0 +1,178 @@
1
+ import { and, eq, inArray, isNull, sql } from 'drizzle-orm';
2
+ import { calculateEffectiveRsvps, effectiveEventTimes, eventRsvpOpen, occurrenceHasEnded, profileName, toCsvRow, } from '@openpeepshq/common/lib';
3
+ import { database } from '../db/index.js';
4
+ import { accounts, controls, profiles } from '../db/pg/schema/index.js';
5
+ import { listJamAttendeeProfileIds } from '../jams/export.js';
6
+ const attending = (response) => response === 'yes' || response === 'tentative';
7
+ /**
8
+ * Join records are the attendance log. Until someone has joined, the column
9
+ * stays off so a jam that has not started is not full of invented no-shows.
10
+ */
11
+ export const rsvpAttendanceLabel = (input) => {
12
+ if (!attending(input.response))
13
+ return '';
14
+ if (input.attended)
15
+ return 'attended';
16
+ return input.eventEnded ? 'no-show' : 'registered';
17
+ };
18
+ /**
19
+ * Member email lives on the controlling account, and more than one account
20
+ * can control a profile. Guests store the address they typed on the profile.
21
+ */
22
+ export const rsvpContactEmail = (input) => {
23
+ const accountsJoined = [
24
+ ...new Set(input.accountEmails.filter((email) => email.length > 0)),
25
+ ]
26
+ .sort()
27
+ .join('; ');
28
+ if (input.profileType === 'guest') {
29
+ return input.guestEmail || accountsJoined;
30
+ }
31
+ return accountsJoined;
32
+ };
33
+ export const rsvpExportEventEnded = (event, occurrenceId, now) => {
34
+ if (occurrenceId) {
35
+ const times = effectiveEventTimes(event, occurrenceId);
36
+ return occurrenceHasEnded(times.start, times.end, now);
37
+ }
38
+ if (event.recurrence)
39
+ return !eventRsvpOpen(event, { now });
40
+ return occurrenceHasEnded(event.start, event.end, now);
41
+ };
42
+ const rsvpExportHeaders = (columns) => [
43
+ 'Name',
44
+ 'Email',
45
+ 'RSVP Status',
46
+ 'RSVP At',
47
+ 'Member ID',
48
+ ...(columns.includeOccurrence ? ['Occurrence'] : []),
49
+ ...(columns.includeAttendance ? ['Attendance'] : []),
50
+ ];
51
+ export const rsvpExportCsv = (rows, columns) => [
52
+ toCsvRow(rsvpExportHeaders(columns)),
53
+ ...rows.map((row) => toCsvRow([
54
+ row.name,
55
+ row.email,
56
+ row.status,
57
+ row.rsvpAt,
58
+ row.memberId,
59
+ ...(columns.includeOccurrence ? [row.occurrence] : []),
60
+ ...(columns.includeAttendance ? [row.attendance] : []),
61
+ ])),
62
+ ].join('\n');
63
+ const compareRows = (a, b) => {
64
+ const byOccurrence = a.occurrence.localeCompare(b.occurrence);
65
+ if (byOccurrence !== 0)
66
+ return byOccurrence;
67
+ const byName = a.name.localeCompare(b.name);
68
+ if (byName !== 0)
69
+ return byName;
70
+ return a.rsvpAt.localeCompare(b.rsvpAt);
71
+ };
72
+ export const assembleRsvpExportCsv = (input) => {
73
+ const event = input.post.data?.type === 'event' ? input.post.data : undefined;
74
+ if (!event) {
75
+ return rsvpExportCsv([], {
76
+ includeOccurrence: false,
77
+ includeAttendance: false,
78
+ });
79
+ }
80
+ const now = input.now ?? new Date();
81
+ const includeAttendance = (input.attendeeIds?.size ?? 0) > 0;
82
+ const eventEnded = rsvpExportEventEnded(event, input.occurrenceId, now);
83
+ const rows = calculateEffectiveRsvps(input.post, input.occurrenceId)
84
+ .map((rsvp) => rowFromRsvp(rsvp, input, includeAttendance, eventEnded))
85
+ .sort(compareRows);
86
+ return rsvpExportCsv(rows, {
87
+ includeOccurrence: !!event.recurrence,
88
+ includeAttendance,
89
+ });
90
+ };
91
+ const rowFromRsvp = (rsvp, input, includeAttendance, eventEnded) => ({
92
+ name: profileName(rsvp.profile) ?? '',
93
+ email: input.emailsByProfileId.get(rsvp.profile.id) ?? '',
94
+ status: rsvp.response,
95
+ rsvpAt: rsvp.createdAt,
96
+ memberId: rsvp.profile.id,
97
+ occurrence: input.occurrenceId ?? rsvp.recurrenceId ?? '',
98
+ attendance: includeAttendance && input.attendeeIds
99
+ ? rsvpAttendanceLabel({
100
+ response: rsvp.response,
101
+ attended: input.attendeeIds.has(rsvp.profile.id),
102
+ eventEnded,
103
+ })
104
+ : '',
105
+ });
106
+ const guestEmailFromBody = (body) => {
107
+ if (!body || typeof body !== 'object')
108
+ return '';
109
+ const email = body.guestData?.email;
110
+ return typeof email === 'string' ? email : '';
111
+ };
112
+ const listRsvpContactEmails = async (profileIds) => {
113
+ const emails = new Map();
114
+ if (!profileIds.length)
115
+ return emails;
116
+ const db = await database();
117
+ const [profileRows, accountRows] = await Promise.all([
118
+ db
119
+ .select({
120
+ id: profiles.id,
121
+ type: profiles.type,
122
+ body: profiles.body,
123
+ })
124
+ .from(profiles)
125
+ .where(inArray(profiles.id, profileIds)),
126
+ db
127
+ .select({
128
+ profileId: controls.toId,
129
+ email: accounts.email,
130
+ })
131
+ .from(controls)
132
+ .innerJoin(accounts, eq(controls.fromId, sql `${accounts.id}::text`))
133
+ .where(and(inArray(controls.toId, profileIds), isNull(accounts.deletedAt))),
134
+ ]);
135
+ const accountsByProfile = new Map();
136
+ for (const row of accountRows) {
137
+ const current = accountsByProfile.get(row.profileId) ?? [];
138
+ accountsByProfile.set(row.profileId, [...current, row.email]);
139
+ }
140
+ const seen = new Set();
141
+ for (const row of profileRows) {
142
+ seen.add(row.id);
143
+ emails.set(row.id, rsvpContactEmail({
144
+ profileType: row.type,
145
+ guestEmail: guestEmailFromBody(row.body),
146
+ accountEmails: accountsByProfile.get(row.id) ?? [],
147
+ }));
148
+ }
149
+ for (const profileId of profileIds) {
150
+ if (seen.has(profileId))
151
+ continue;
152
+ emails.set(profileId, rsvpContactEmail({
153
+ profileType: undefined,
154
+ guestEmail: '',
155
+ accountEmails: accountsByProfile.get(profileId) ?? [],
156
+ }));
157
+ }
158
+ return emails;
159
+ };
160
+ export const exportEventRsvpsCsv = async (post, options) => {
161
+ const event = post.data?.type === 'event' ? post.data : undefined;
162
+ const profileIds = [
163
+ ...new Set(calculateEffectiveRsvps(post, options?.occurrenceId).map((rsvp) => rsvp.profile.id)),
164
+ ];
165
+ const [emailsByProfileId, attendeeIds] = await Promise.all([
166
+ listRsvpContactEmails(profileIds),
167
+ event?.jam
168
+ ? listJamAttendeeProfileIds(post.id)
169
+ : Promise.resolve([]),
170
+ ]);
171
+ return assembleRsvpExportCsv({
172
+ post,
173
+ occurrenceId: options?.occurrenceId,
174
+ emailsByProfileId,
175
+ attendeeIds: attendeeIds.length ? new Set(attendeeIds) : undefined,
176
+ now: options?.now,
177
+ });
178
+ };
@@ -9,4 +9,10 @@ export declare const listUnseenGroupPostIds: (db: PgDb, profileId: string, group
9
9
  * Walks reply_to to roots without hydrating posts.
10
10
  */
11
11
  export declare const countUnseenDirectPosts: (db: PgDb, profileId: string) => Promise<Record<string, number>>;
12
+ /**
13
+ * Merge 1:1 direct counts into the pair's oldest root key so a conversation
14
+ * with several roots keeps one badge. The key must match the inbox preview's
15
+ * canonical id (min uuidv7 root); non-1:1 roots keep their own key.
16
+ */
17
+ export declare const mergeOneToOneDirectCounts: (db: PgDb, counts: Record<string, number>) => Promise<Record<string, number>>;
12
18
  export declare const queryUnseenPostCounts: (db: PgDb, profileId: string, groupIds: string[]) => Promise<UnseenPostCounts>;
@@ -92,10 +92,60 @@ export const countUnseenDirectPosts = async (db, profileId) => {
92
92
  `));
93
93
  return Object.fromEntries(result.rows.map((row) => [row.root_id, Number(row.cnt) || 0]));
94
94
  };
95
+ /**
96
+ * Merge 1:1 direct counts into the pair's oldest root key so a conversation
97
+ * with several roots keeps one badge. The key must match the inbox preview's
98
+ * canonical id (min uuidv7 root); non-1:1 roots keep their own key.
99
+ */
100
+ export const mergeOneToOneDirectCounts = async (db, counts) => {
101
+ const countedRootIds = Object.keys(counts);
102
+ if (countedRootIds.length === 0)
103
+ return counts;
104
+ const result = (await db.execute(sql `
105
+ WITH counted AS (
106
+ SELECT p.id::text AS root_id,
107
+ string_agg(a.to_id, ',' ORDER BY a.to_id) AS pair
108
+ FROM posts p
109
+ INNER JOIN audience a ON a.from_id = p.id::text
110
+ WHERE p.id::text IN (${sql.join(countedRootIds.map((id) => sql `${id}`), sql `, `)})
111
+ GROUP BY p.id
112
+ HAVING count(*) = 2
113
+ ),
114
+ pair_roots AS (
115
+ SELECT p2.id::text AS root_id,
116
+ string_agg(a2.to_id, ',' ORDER BY a2.to_id) AS pair
117
+ FROM posts p2
118
+ INNER JOIN audience a2 ON a2.from_id = p2.id::text
119
+ WHERE p2.visibility = 'direct'
120
+ AND p2.deleted_at IS NULL
121
+ AND NOT EXISTS (
122
+ SELECT 1 FROM reply_to rt
123
+ WHERE rt.from_id = p2.id::text
124
+ )
125
+ GROUP BY p2.id
126
+ HAVING count(*) = 2
127
+ ),
128
+ canonical AS (
129
+ SELECT pair, min(root_id)::text AS canonical_root_id
130
+ FROM pair_roots
131
+ GROUP BY pair
132
+ )
133
+ SELECT c.root_id, canonical.canonical_root_id
134
+ FROM counted c
135
+ INNER JOIN canonical ON canonical.pair = c.pair
136
+ `));
137
+ const canonicalByRoot = new Map(result.rows.map((row) => [row.root_id, row.canonical_root_id]));
138
+ const merged = {};
139
+ for (const [rootId, count] of Object.entries(counts)) {
140
+ const key = canonicalByRoot.get(rootId) ?? rootId;
141
+ merged[key] = (merged[key] ?? 0) + count;
142
+ }
143
+ return merged;
144
+ };
95
145
  export const queryUnseenPostCounts = async (db, profileId, groupIds) => {
96
146
  const [groups, direct] = await Promise.all([
97
147
  countUnseenGroupPosts(db, profileId, groupIds),
98
148
  countUnseenDirectPosts(db, profileId),
99
149
  ]);
100
- return { groups, direct };
150
+ return { groups, direct: await mergeOneToOneDirectCounts(db, direct) };
101
151
  };
@@ -0,0 +1,13 @@
1
+ import type { PostWithMeta } from '@openpeepshq/common/types';
2
+ import { type WaitlistSyncPlan } from '@openpeepshq/common/lib';
3
+ export declare const rsvpCapacityLockKeys: (postId: string) => {
4
+ key1: number;
5
+ key2: number;
6
+ };
7
+ export declare const withRsvpCapacityLock: <T>(postId: string, fn: () => Promise<T>) => Promise<T>;
8
+ export declare const capacitySyncTargets: (post: PostWithMeta, occurrenceIds?: string[]) => Array<string | undefined>;
9
+ export declare const applyWaitlistSync: (post: PostWithMeta, recurrenceId: string | undefined, now?: number) => Promise<WaitlistSyncPlan>;
10
+ export declare const syncCapacityOccurrences: (postId: string, occurrenceIds: Array<string | undefined>, now?: number) => Promise<{
11
+ post: PostWithMeta | undefined;
12
+ plans: WaitlistSyncPlan[];
13
+ }>;
@@ -0,0 +1,75 @@
1
+ import { planWaitlistSync, } from '@openpeepshq/common/lib';
2
+ import { listRsvpOccurrences } from '@openpeepshq/common/lib';
3
+ import { logger } from '../log/index.js';
4
+ import { allpeepDb } from '../db/index.js';
5
+ import { withPostgresAdvisoryLock } from '../db/pg/client.js';
6
+ import { findProfile } from '../profiles/index.js';
7
+ import { findPost } from './finders.js';
8
+ import { entryConnector } from './helpers/index.js';
9
+ const log = logger('app:posts:waitlist');
10
+ // key2 = 42 is deliberately distinct from SCHEMA_MIGRATE_LOCK.key2 (1) so
11
+ // per-post capacity locks can never collide with schema migration locks.
12
+ const WAITLIST_LOCK_KEY2 = 42;
13
+ const hashPostId = (postId) => {
14
+ let h = 0;
15
+ for (let i = 0; i < postId.length; i += 1) {
16
+ h = Math.imul(h, 31) + postId.charCodeAt(i);
17
+ }
18
+ // Ensure a non-zero key1 to avoid the default-key1 path in withPostgresAdvisoryLock.
19
+ return h | 0 || 1;
20
+ };
21
+ export const rsvpCapacityLockKeys = (postId) => ({
22
+ key1: hashPostId(postId),
23
+ key2: WAITLIST_LOCK_KEY2,
24
+ });
25
+ export const withRsvpCapacityLock = (postId, fn) => {
26
+ const keys = rsvpCapacityLockKeys(postId);
27
+ return withPostgresAdvisoryLock(keys.key1, keys.key2, fn);
28
+ };
29
+ export const capacitySyncTargets = (post, occurrenceIds) => {
30
+ const event = post.data?.type === 'event' ? post.data : undefined;
31
+ if (!event?.maxAttendees)
32
+ return [];
33
+ if (!event.recurrence)
34
+ return [undefined];
35
+ if (occurrenceIds?.length)
36
+ return occurrenceIds;
37
+ const upcoming = listRsvpOccurrences(event).map((occurrence) => occurrence.recurrenceId);
38
+ return upcoming.length ? upcoming : [undefined];
39
+ };
40
+ export const applyWaitlistSync = async (post, recurrenceId, now = Date.now()) => {
41
+ const plan = planWaitlistSync(post, recurrenceId, now);
42
+ const writes = [...plan.requeues, ...plan.withdraws, ...plan.offers];
43
+ if (!writes.length)
44
+ return plan;
45
+ const { db } = await allpeepDb();
46
+ const profileIds = [...new Set(writes.map((w) => w.profileId))];
47
+ const profiles = new Map(await Promise.all(profileIds.map(async (id) => [id, await findProfile(id)])));
48
+ for (const write of writes) {
49
+ const profile = profiles.get(write.profileId);
50
+ if (!profile) {
51
+ log.error({ profileId: write.profileId }, 'waitlist profile missing');
52
+ continue;
53
+ }
54
+ const data = {
55
+ response: 'waitlist',
56
+ ...(write.recurrenceId ? { recurrenceId: write.recurrenceId } : {}),
57
+ waitlistJoinedAt: write.waitlistJoinedAt,
58
+ ...(write.offerExpiresAt ? { offerExpiresAt: write.offerExpiresAt } : {}),
59
+ };
60
+ await entryConnector(db, profile, post, { type: 'rsvp', data });
61
+ }
62
+ return plan;
63
+ };
64
+ export const syncCapacityOccurrences = async (postId, occurrenceIds, now = Date.now()) => {
65
+ const plans = [];
66
+ let post = await findPost(postId);
67
+ for (const recurrenceId of occurrenceIds) {
68
+ if (!post || post.data?.type !== 'event' || !post.data.maxAttendees) {
69
+ break;
70
+ }
71
+ plans.push(await applyWaitlistSync(post, recurrenceId, now));
72
+ post = await findPost(postId);
73
+ }
74
+ return { post, plans };
75
+ };
@@ -0,0 +1,10 @@
1
+ import type { WaitlistEntryWrite, WaitlistSyncPlan } from '@openpeepshq/common/lib';
2
+ export interface WaitlistOfferJobData {
3
+ postId: string;
4
+ recurrenceId?: string;
5
+ }
6
+ declare const waitlistOfferQueue: () => import("bullmq").Queue, waitlistOfferWorker: () => import("bullmq").Worker;
7
+ export declare const scheduleWaitlistOffer: (postId: string, offer: WaitlistEntryWrite) => Promise<void>;
8
+ export declare const cancelWaitlistOfferJob: (postId: string, recurrenceId: string | undefined, profileId: string) => Promise<void>;
9
+ export declare const publishWaitlistPlans: (postId: string, fromProfileId: string | undefined, plans: WaitlistSyncPlan[]) => Promise<void>;
10
+ export { waitlistOfferQueue, waitlistOfferWorker };
@@ -0,0 +1,91 @@
1
+ import { queueAndWorker } from '../jobs/index.js';
2
+ import { logger } from '../log/index.js';
3
+ import { maybeCreateNotification } from '../notifications/mutations.js';
4
+ import { findProfile } from '../profiles/index.js';
5
+ import { applyWaitlistSync, capacitySyncTargets, withRsvpCapacityLock, } from './waitlist.js';
6
+ import { findPost } from './finders.js';
7
+ const log = logger('app:posts:waitlistOffer');
8
+ const offerJobId = (postId, recurrenceId, profileId) => `waitlist-offer-${postId}-${(recurrenceId ?? 'event').replace(/:/g, '_')}-${profileId}`;
9
+ const [waitlistOfferQueue, waitlistOfferWorker] = queueAndWorker('waitlist-offer', async (job) => {
10
+ const plans = [];
11
+ let fromProfileId;
12
+ await withRsvpCapacityLock(job.data.postId, async () => {
13
+ let post = await findPost(job.data.postId);
14
+ if (!post)
15
+ return;
16
+ fromProfileId = post.profile?.id;
17
+ const targets = job.data.recurrenceId
18
+ ? [job.data.recurrenceId]
19
+ : capacitySyncTargets(post);
20
+ for (const recurrenceId of targets) {
21
+ if (!post)
22
+ return;
23
+ plans.push(await applyWaitlistSync(post, recurrenceId));
24
+ post = await findPost(job.data.postId);
25
+ }
26
+ });
27
+ await publishWaitlistPlans(job.data.postId, fromProfileId, plans);
28
+ }, {
29
+ defaultJobOptions: {
30
+ removeOnComplete: { age: 86400 },
31
+ removeOnFail: { age: 86400 * 7, count: 50 },
32
+ },
33
+ });
34
+ export const scheduleWaitlistOffer = async (postId, offer) => {
35
+ if (!offer.offerExpiresAt)
36
+ return;
37
+ try {
38
+ const queue = waitlistOfferQueue();
39
+ const jobId = offerJobId(postId, offer.recurrenceId, offer.profileId);
40
+ await queue.remove(jobId).catch(() => undefined);
41
+ const delay = Date.parse(offer.offerExpiresAt) - Date.now();
42
+ if (delay <= 0)
43
+ return;
44
+ await queue.add('offer', {
45
+ postId,
46
+ recurrenceId: offer.recurrenceId,
47
+ }, { jobId, delay });
48
+ }
49
+ catch (err) {
50
+ log.error({ err, postId }, 'Failed to schedule waitlist offer');
51
+ }
52
+ };
53
+ export const cancelWaitlistOfferJob = async (postId, recurrenceId, profileId) => {
54
+ try {
55
+ const queue = waitlistOfferQueue();
56
+ await queue.remove(offerJobId(postId, recurrenceId, profileId));
57
+ }
58
+ catch (err) {
59
+ log.error({ err, postId, profileId }, 'Failed to cancel waitlist offer');
60
+ }
61
+ };
62
+ export const publishWaitlistPlans = async (postId, fromProfileId, plans) => {
63
+ for (const plan of plans) {
64
+ for (const cleared of plan.clearOffers) {
65
+ await cancelWaitlistOfferJob(postId, cleared.recurrenceId, cleared.profileId);
66
+ }
67
+ for (const offer of plan.offers) {
68
+ try {
69
+ await scheduleWaitlistOffer(postId, offer);
70
+ if (!offer.offerExpiresAt)
71
+ continue;
72
+ const profile = await findProfile(offer.profileId);
73
+ if (!profile)
74
+ continue;
75
+ await maybeCreateNotification(profile, {
76
+ type: 'waitlistOffer',
77
+ postId,
78
+ ...(fromProfileId ? { fromProfileId } : {}),
79
+ data: {
80
+ offerExpiresAt: offer.offerExpiresAt,
81
+ ...(offer.recurrenceId ? { recurrenceId: offer.recurrenceId } : {}),
82
+ },
83
+ });
84
+ }
85
+ catch (err) {
86
+ log.error({ err, postId, profileId: offer.profileId }, 'waitlist offer notify failed');
87
+ }
88
+ }
89
+ }
90
+ };
91
+ export { waitlistOfferQueue, waitlistOfferWorker };
@@ -14,6 +14,7 @@ export declare const profileSettingsMapping: import("../db/pg/map").Mapping<{
14
14
  push: boolean;
15
15
  email: boolean;
16
16
  }> | undefined;
17
+ groupNotificationLevels?: Record<string, "off" | "all" | "mostRelevant"> | undefined;
17
18
  jamSettings?: {
18
19
  backgroundObfuscation?: {
19
20
  type: "blur";
@@ -1,3 +1,5 @@
1
+ import { isForbiddenHandle } from '@openpeepshq/common/types';
2
+ import { communityConfig } from '../config/index.js';
1
3
  import { findProfileByHandle } from './finders.js';
2
4
  export * from './mapping.js';
3
5
  export * from './mutations.js';
@@ -10,8 +12,11 @@ const sanitizeHandle = (name) => name.replace(/[^a-zA-Z0-9]/g, '-');
10
12
  export const findNewFreeHandle = async (seed) => {
11
13
  let counter = 2;
12
14
  const sanitizedSeed = sanitizeHandle(seed).substring(0, 16);
15
+ const community = await communityConfig();
16
+ const additional = community.settings.additionalForbiddenHandles;
13
17
  let candidate = sanitizedSeed;
14
- while (await findProfileByHandle(candidate)) {
18
+ while (isForbiddenHandle(candidate, additional) ||
19
+ (await findProfileByHandle(candidate))) {
15
20
  const counterString = String(counter);
16
21
  candidate =
17
22
  sanitizedSeed.substring(0, 16 - counterString.length) + counterString;
@@ -5,7 +5,7 @@ export declare const baseProfileRelations: Relation[];
5
5
  export declare const profileRelations: Relation[];
6
6
  export declare const baseProfilesMapping: import("../db/pg/map").Mapping<{
7
7
  handle: string;
8
- type: "guest" | "local" | "federated";
8
+ type: "local" | "guest" | "federated";
9
9
  deletedHandle?: string | undefined;
10
10
  avatar?: string | null | undefined;
11
11
  header?: string | null | undefined;
@@ -35,7 +35,7 @@ export declare const baseProfilesMapping: import("../db/pg/map").Mapping<{
35
35
  guestData?: {
36
36
  email?: string | undefined;
37
37
  resource?: {
38
- type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "*" | "jams" | "webhooks" | "analytics" | "render";
38
+ type: "db" | "jams" | "profiles" | "self" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
39
39
  id?: string | undefined;
40
40
  } | undefined;
41
41
  } | undefined;
@@ -44,7 +44,7 @@ export declare const baseProfilesMapping: import("../db/pg/map").Mapping<{
44
44
  /** Lean mapping for public search results (memberships only). */
45
45
  export declare const publicProfilesSearchMapping: import("../db/pg/map").Mapping<{
46
46
  handle: string;
47
- type: "guest" | "local" | "federated";
47
+ type: "local" | "guest" | "federated";
48
48
  deletedHandle?: string | undefined;
49
49
  avatar?: string | null | undefined;
50
50
  header?: string | null | undefined;
@@ -74,7 +74,7 @@ export declare const publicProfilesSearchMapping: import("../db/pg/map").Mapping
74
74
  guestData?: {
75
75
  email?: string | undefined;
76
76
  resource?: {
77
- type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "*" | "jams" | "webhooks" | "analytics" | "render";
77
+ type: "db" | "jams" | "profiles" | "self" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
78
78
  id?: string | undefined;
79
79
  } | undefined;
80
80
  } | undefined;
@@ -86,7 +86,7 @@ export declare const publicProfilesSearchMapping: import("../db/pg/map").Mapping
86
86
  */
87
87
  export declare const publicProfilesMapping: import("../db/pg/map").Mapping<{
88
88
  handle: string;
89
- type: "guest" | "local" | "federated";
89
+ type: "local" | "guest" | "federated";
90
90
  deletedHandle?: string | undefined;
91
91
  avatar?: string | null | undefined;
92
92
  header?: string | null | undefined;
@@ -116,7 +116,7 @@ export declare const publicProfilesMapping: import("../db/pg/map").Mapping<{
116
116
  guestData?: {
117
117
  email?: string | undefined;
118
118
  resource?: {
119
- type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "*" | "jams" | "webhooks" | "analytics" | "render";
119
+ type: "db" | "jams" | "profiles" | "self" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
120
120
  id?: string | undefined;
121
121
  } | undefined;
122
122
  } | undefined;
@@ -124,7 +124,7 @@ export declare const publicProfilesMapping: import("../db/pg/map").Mapping<{
124
124
  }, ProfileWithMeta, ProfileWithMeta>;
125
125
  export declare const profilesMapping: import("../db/pg/map").Mapping<{
126
126
  handle: string;
127
- type: "guest" | "local" | "federated";
127
+ type: "local" | "guest" | "federated";
128
128
  deletedHandle?: string | undefined;
129
129
  avatar?: string | null | undefined;
130
130
  header?: string | null | undefined;
@@ -154,7 +154,7 @@ export declare const profilesMapping: import("../db/pg/map").Mapping<{
154
154
  guestData?: {
155
155
  email?: string | undefined;
156
156
  resource?: {
157
- type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "*" | "jams" | "webhooks" | "analytics" | "render";
157
+ type: "db" | "jams" | "profiles" | "self" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
158
158
  id?: string | undefined;
159
159
  } | undefined;
160
160
  } | undefined;
@@ -162,7 +162,7 @@ export declare const profilesMapping: import("../db/pg/map").Mapping<{
162
162
  }, ProfileWithMeta, ProfileWithMeta>;
163
163
  export declare const membersExportMapping: import("../db/pg/map").Mapping<{
164
164
  handle: string;
165
- type: "guest" | "local" | "federated";
165
+ type: "local" | "guest" | "federated";
166
166
  deletedHandle?: string | undefined;
167
167
  avatar?: string | null | undefined;
168
168
  header?: string | null | undefined;
@@ -192,7 +192,7 @@ export declare const membersExportMapping: import("../db/pg/map").Mapping<{
192
192
  guestData?: {
193
193
  email?: string | undefined;
194
194
  resource?: {
195
- type: "profiles" | "groups" | "posts" | "notifications" | "reports" | "db" | "self" | "*" | "jams" | "webhooks" | "analytics" | "render";
195
+ type: "db" | "jams" | "profiles" | "self" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
196
196
  id?: string | undefined;
197
197
  } | undefined;
198
198
  } | undefined;
@@ -5,5 +5,5 @@ export declare const reportsMapping: import("../db/pg/map").Mapping<{
5
5
  uri?: string | undefined;
6
6
  forward?: boolean | undefined;
7
7
  ruleIds?: number[] | undefined;
8
- resolution?: "warn" | "remove" | "ignore" | "other" | "ban" | undefined;
8
+ resolution?: "remove" | "warn" | "other" | "ignore" | "ban" | undefined;
9
9
  }, ReportWithMeta, ReportWithMeta>;
@@ -73,6 +73,7 @@ export declare const serverInfo: () => Promise<{
73
73
  defaultTimeZone?: string | undefined;
74
74
  defaultFeedFormat?: "threaded" | "linear" | undefined;
75
75
  indexProfiles?: boolean | undefined;
76
+ additionalForbiddenHandles?: string[] | undefined;
76
77
  };
77
78
  roles: {
78
79
  onRegistration: {
@@ -27,7 +27,7 @@ export declare const postsWithActivityScoreMapping: import("../db/pg/map").Mappi
27
27
  };
28
28
  description?: string | undefined;
29
29
  blurhash?: string | undefined;
30
- status?: "failed" | "processing" | "ready" | undefined;
30
+ status?: "failed" | "ready" | "processing" | undefined;
31
31
  error?: string | undefined;
32
32
  }[] | undefined;
33
33
  customEmojis?: {
@@ -64,7 +64,7 @@ export declare const postsWithActivityScoreMapping: import("../db/pg/map").Mappi
64
64
  };
65
65
  description?: string | undefined;
66
66
  blurhash?: string | undefined;
67
- status?: "failed" | "processing" | "ready" | undefined;
67
+ status?: "failed" | "ready" | "processing" | undefined;
68
68
  error?: string | undefined;
69
69
  }[] | undefined;
70
70
  customEmojis?: {
@@ -102,7 +102,7 @@ export declare const postsWithActivityScoreMapping: import("../db/pg/map").Mappi
102
102
  };
103
103
  description?: string | undefined;
104
104
  blurhash?: string | undefined;
105
- status?: "failed" | "processing" | "ready" | undefined;
105
+ status?: "failed" | "ready" | "processing" | undefined;
106
106
  error?: string | undefined;
107
107
  }[] | undefined;
108
108
  customEmojis?: {
@@ -118,6 +118,7 @@ export declare const postsWithActivityScoreMapping: import("../db/pg/map").Mappi
118
118
  image?: string | undefined;
119
119
  end?: string | undefined;
120
120
  maxAttendees?: number | undefined;
121
+ waitlistOfferMinutes?: number | undefined;
121
122
  attendeeListPublic?: boolean | undefined;
122
123
  moderators?: string[] | undefined;
123
124
  jam?: {
@@ -184,7 +185,7 @@ export declare const postsWithActivityScoreMapping: import("../db/pg/map").Mappi
184
185
  };
185
186
  description?: string | undefined;
186
187
  blurhash?: string | undefined;
187
- status?: "failed" | "processing" | "ready" | undefined;
188
+ status?: "failed" | "ready" | "processing" | undefined;
188
189
  error?: string | undefined;
189
190
  }[] | undefined;
190
191
  customEmojis?: {
@@ -200,7 +201,7 @@ export declare const postsWithActivityScoreMapping: import("../db/pg/map").Mappi
200
201
  } | {
201
202
  type: "resource";
202
203
  title: string;
203
- resourceKind: "link" | "file" | "video" | "gallery" | "audio";
204
+ resourceKind: "file" | "link" | "video" | "gallery" | "audio";
204
205
  content?: string | undefined;
205
206
  sensitive?: boolean | undefined;
206
207
  spoilerText?: string | undefined;
@@ -221,7 +222,7 @@ export declare const postsWithActivityScoreMapping: import("../db/pg/map").Mappi
221
222
  };
222
223
  description?: string | undefined;
223
224
  blurhash?: string | undefined;
224
- status?: "failed" | "processing" | "ready" | undefined;
225
+ status?: "failed" | "ready" | "processing" | undefined;
225
226
  error?: string | undefined;
226
227
  }[] | undefined;
227
228
  customEmojis?: {
@@ -2,7 +2,7 @@ import Stripe from 'stripe';
2
2
  import { config } from '../config/index.js';
3
3
  import { hub } from '../events/index.js';
4
4
  export const initStripeWithCredentials = (data) => data?.publishableKey || data?.secretKey || data?.webhookSecret
5
- ? new Stripe(data?.secretKey, { apiVersion: '2025-07-30.basil' })
5
+ ? new Stripe(data.secretKey, { apiVersion: '2025-07-30.basil' })
6
6
  : undefined;
7
7
  export const initStripe = async () => {
8
8
  hub.on('configUpdated', (namespace, name) => {