@openpeepshq/core 0.2.0 → 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 (58) hide show
  1. package/LICENSE +674 -0
  2. package/dist/accounts/mutations.js +9 -0
  3. package/dist/config/index.d.ts +3 -336
  4. package/dist/db/explorer/index.d.ts +1 -1
  5. package/dist/db/explorer/index.js +1 -1
  6. package/dist/db/pg/map/registry.js +3 -2
  7. package/dist/jams/export.d.ts +2 -0
  8. package/dist/jams/export.js +5 -0
  9. package/dist/jams/finders.d.ts +1 -0
  10. package/dist/jams/finders.js +1 -0
  11. package/dist/jams/health.d.ts +23 -0
  12. package/dist/jams/health.js +79 -7
  13. package/dist/jams/index.d.ts +1 -1
  14. package/dist/jams/index.js +10 -3
  15. package/dist/jams/token.js +6 -2
  16. package/dist/jams/waitingRoom.js +3 -1
  17. package/dist/media/garbageCollection.d.ts +109 -0
  18. package/dist/media/garbageCollection.js +603 -0
  19. package/dist/media/garbageCollectionJobs.d.ts +14 -0
  20. package/dist/media/garbageCollectionJobs.js +55 -0
  21. package/dist/media/index.d.ts +2 -0
  22. package/dist/media/index.js +4 -2
  23. package/dist/media/streaming.d.ts +2 -0
  24. package/dist/media/streaming.js +8 -0
  25. package/dist/notifications/defaultNotifications/index.js +2 -0
  26. package/dist/notifications/defaultNotifications/jamStarted/index.d.ts +1 -0
  27. package/dist/notifications/defaultNotifications/jamStarted/index.js +61 -13
  28. package/dist/notifications/defaultNotifications/waitlistOffer/index.d.ts +24 -0
  29. package/dist/notifications/defaultNotifications/waitlistOffer/index.js +40 -0
  30. package/dist/notifications/index.d.ts +1 -1
  31. package/dist/notifications/index.js +1 -1
  32. package/dist/plugins/pluginAuth.js +1 -0
  33. package/dist/posts/conversationQueries.d.ts +31 -0
  34. package/dist/posts/conversationQueries.js +150 -24
  35. package/dist/posts/finders.d.ts +9 -0
  36. package/dist/posts/finders.js +23 -3
  37. package/dist/posts/helpers/index.d.ts +10 -2
  38. package/dist/posts/helpers/index.js +6 -0
  39. package/dist/posts/index.d.ts +3 -1
  40. package/dist/posts/index.js +3 -1
  41. package/dist/posts/mapping.d.ts +14 -0
  42. package/dist/posts/mutations.d.ts +12 -6
  43. package/dist/posts/mutations.js +220 -68
  44. package/dist/posts/rsvpExport.d.ts +47 -0
  45. package/dist/posts/rsvpExport.js +178 -0
  46. package/dist/posts/unseenCounts.d.ts +6 -0
  47. package/dist/posts/unseenCounts.js +51 -1
  48. package/dist/posts/waitlist.d.ts +13 -0
  49. package/dist/posts/waitlist.js +75 -0
  50. package/dist/posts/waitlistOfferJobs.d.ts +10 -0
  51. package/dist/posts/waitlistOfferJobs.js +91 -0
  52. package/dist/profiles/index.js +6 -1
  53. package/dist/reports/mapping.d.ts +1 -1
  54. package/dist/server/index.d.ts +1 -0
  55. package/dist/stats/mapping.d.ts +1 -0
  56. package/dist/stripe/connection.js +1 -1
  57. package/dist/stripe/helpers.js +7 -3
  58. package/package.json +10 -9
@@ -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 };
@@ -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,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?: "remove" | "warn" | "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: {
@@ -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?: {
@@ -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) => {
@@ -73,7 +73,7 @@ export const testStripeCredentials = async (data) => {
73
73
  }
74
74
  return { success: true, key: 'configuration.server.stripe.success.test' };
75
75
  }
76
- catch (e) {
76
+ catch {
77
77
  return { success: false, key: 'configuration.server.stripe.errors.failed' };
78
78
  }
79
79
  };
@@ -89,7 +89,9 @@ export const createStripeCustomerPortal = async (stripeId) => {
89
89
  }));
90
90
  return session.url;
91
91
  }
92
- catch { }
92
+ catch {
93
+ // swallowed: caller gets undefined
94
+ }
93
95
  };
94
96
  export const createStripeCustomer = async (profile, account) => {
95
97
  const profileSettings = await findProfileSettings(profile.id);
@@ -202,5 +204,7 @@ export const createStripeCheckoutUrl = async (profile, account) => {
202
204
  }))
203
205
  .then((session) => session.url ?? undefined);
204
206
  }
205
- catch { }
207
+ catch {
208
+ // swallowed: caller gets undefined
209
+ }
206
210
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpeepshq/core",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "dependencies": {
@@ -39,7 +39,7 @@
39
39
  "web-push": "^3.6.7",
40
40
  "@openpeepshq/common": "0.4.0",
41
41
  "@openpeepshq/fetch-client": "^0.2.1",
42
- "@openpeepshq/i18n": "^0.2.0",
42
+ "@openpeepshq/i18n": "^0.2.1",
43
43
  "@openpeepshq/geocoder": "^0.1.2"
44
44
  },
45
45
  "main": "dist/index.js",
@@ -64,22 +64,23 @@
64
64
  "@types/pg": "^8.15.4",
65
65
  "@types/safe-json-stringify": "^1.1.5",
66
66
  "@types/web-push": "^3.6.4",
67
- "@typescript-eslint/eslint-plugin": "^8.19.1",
68
- "@typescript-eslint/parser": "^8.19.1",
67
+ "@typescript-eslint/eslint-plugin": "^8.72.0",
68
+ "@typescript-eslint/parser": "^8.72.0",
69
69
  "concurrently": "^9.1.2",
70
70
  "drizzle-kit": "^0.31.1",
71
- "eslint": "^9.17.0",
71
+ "eslint": "^10.1.0",
72
72
  "eslint-config-prettier": "^9.1.0",
73
73
  "google-auth-library": "^10.7.0",
74
74
  "i18next": "^24.2.3",
75
75
  "prettier": "^3.4.2",
76
76
  "tsc-alias": "^1.8.10",
77
- "typescript": "^5.7.2",
78
- "vitest": "^2.1.8"
77
+ "typescript": "^6.0.2",
78
+ "vitest": "^2.1.8",
79
+ "@eslint/js": "^9.17.0"
79
80
  },
80
81
  "scripts": {
81
- "lint": "prettier --check . && ESLINT_USE_FLAT_CONFIG=false eslint .",
82
- "format": "prettier --write .",
82
+ "lint": "eslint .",
83
+ "format": "prettier --write --ignore-path ../../.prettierignore .",
83
84
  "test": "vitest run",
84
85
  "clean": "rm -rf tsconfig.tsbuildinfo dist",
85
86
  "build": "tsc && tsc-alias && rm -rf dist/db/pg/sql && cp -r src/db/pg/sql dist/db/pg/sql",