@openpeepshq/core 0.6.0 → 0.7.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.
- package/dist/analytics/report.d.ts +7 -1
- package/dist/analytics/report.js +14 -11
- package/dist/jams/cache.d.ts +1 -0
- package/dist/jams/finders.d.ts +1 -0
- package/dist/jams/livekit.d.ts +10 -0
- package/dist/jams/livekit.js +35 -5
- package/dist/posts/eventAgenda.d.ts +166 -1
- package/dist/posts/eventAgenda.js +81 -0
- package/dist/posts/index.d.ts +2 -1
- package/dist/posts/index.js +2 -1
- package/package.json +6 -6
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import type { AnalyticsDateQuery } from '@openpeepshq/common/types';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Board-ready report: plain-text email body + visual multi-page PDF.
|
|
4
|
+
*
|
|
5
|
+
* The `text` body is intentionally header-free — it carries no report title or
|
|
6
|
+
* `Period:` line. The email template renders the title and period itself, so
|
|
7
|
+
* duplicating them here is what #1887 removed.
|
|
8
|
+
*/
|
|
3
9
|
export declare const buildAnalyticsBoardReport: (query?: AnalyticsDateQuery) => Promise<{
|
|
4
10
|
text: string;
|
|
5
11
|
pdf: Buffer<ArrayBufferLike>;
|
package/dist/analytics/report.js
CHANGED
|
@@ -24,7 +24,13 @@ const narrativeSentence = (label, value, deltaPct) => {
|
|
|
24
24
|
}
|
|
25
25
|
return `${label} held steady at ${value} versus the prior period.`;
|
|
26
26
|
};
|
|
27
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Board-ready report: plain-text email body + visual multi-page PDF.
|
|
29
|
+
*
|
|
30
|
+
* The `text` body is intentionally header-free — it carries no report title or
|
|
31
|
+
* `Period:` line. The email template renders the title and period itself, so
|
|
32
|
+
* duplicating them here is what #1887 removed.
|
|
33
|
+
*/
|
|
28
34
|
export const buildAnalyticsBoardReport = async (query = {}) => {
|
|
29
35
|
const [overview, growth, engagement, community] = await Promise.all([
|
|
30
36
|
getAnalyticsOverview(query),
|
|
@@ -32,13 +38,13 @@ export const buildAnalyticsBoardReport = async (query = {}) => {
|
|
|
32
38
|
getAnalyticsEngagement(query),
|
|
33
39
|
communityConfig(),
|
|
34
40
|
]);
|
|
35
|
-
const from = overview.range.from;
|
|
36
|
-
const to = overview.range.to;
|
|
37
41
|
const total = overview.metrics.totalMembers.value;
|
|
38
42
|
const active = overview.metrics.activeMembers.value;
|
|
39
43
|
const activeShare = total > 0 ? Math.round((active / total) * 1000) / 10 : 0;
|
|
40
|
-
|
|
41
|
-
|
|
44
|
+
// The email template renders the report title and period range itself;
|
|
45
|
+
// repeating them in the body would show the period three times (#1887).
|
|
46
|
+
const text = [
|
|
47
|
+
'Executive summary',
|
|
42
48
|
'',
|
|
43
49
|
narrativeSentence('Total membership', overview.metrics.totalMembers.value, overview.metrics.totalMembers.deltaPct),
|
|
44
50
|
narrativeSentence('Active members', overview.metrics.activeMembers.value, overview.metrics.activeMembers.deltaPct),
|
|
@@ -46,12 +52,6 @@ export const buildAnalyticsBoardReport = async (query = {}) => {
|
|
|
46
52
|
narrativeSentence('Posts published', overview.metrics.totalPosts.value, overview.metrics.totalPosts.deltaPct),
|
|
47
53
|
narrativeSentence('Groups', overview.metrics.totalGroups.value, overview.metrics.totalGroups.deltaPct),
|
|
48
54
|
narrativeSentence('Content impressions', engagement.metrics.impressions.value, engagement.metrics.impressions.deltaPct),
|
|
49
|
-
];
|
|
50
|
-
const text = [
|
|
51
|
-
`Community analytics report`,
|
|
52
|
-
`Period: ${from} → ${to}`,
|
|
53
|
-
'',
|
|
54
|
-
...summary,
|
|
55
55
|
].join('\n');
|
|
56
56
|
const pdf = await buildAnalyticsPdf({
|
|
57
57
|
communityName: community.info.name,
|
|
@@ -124,6 +124,9 @@ export const sendMonthlyAnalyticsReport = async (overridePeriod) => {
|
|
|
124
124
|
const filename = `analytics-${from}-${to}.pdf`;
|
|
125
125
|
const db = await database();
|
|
126
126
|
const deliveryId = uuidv7();
|
|
127
|
+
// `body.text` is intentionally header-free (no title/`Period:`); those are
|
|
128
|
+
// rendered by the email template and stored here only as `periodStart/End`,
|
|
129
|
+
// so don't re-add them here or #1887 regresses.
|
|
127
130
|
await db.insert(analyticsReportDeliveries).values({
|
|
128
131
|
id: deliveryId,
|
|
129
132
|
periodStart: from,
|
package/dist/jams/cache.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export declare const jamStateCache: import("cache-manager").Cache;
|
|
|
3
3
|
export declare const getJamState: (jam: PostWithMeta, recurrenceId?: string) => Promise<{
|
|
4
4
|
active: boolean;
|
|
5
5
|
participants: string[];
|
|
6
|
+
observers?: number | undefined;
|
|
6
7
|
}>;
|
|
7
8
|
/** Caches the LiveKit scan for live jam posts (before auth filtering). */
|
|
8
9
|
export declare const LIVE_JAMS_CACHE_KEY = "live-jams";
|
package/dist/jams/finders.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export declare const listAttendance: (jamId: string, { start, limit }?: {
|
|
|
18
18
|
export declare const findJamState: (jam: PostWithMeta, hideParticipants?: boolean, recurrenceId?: string) => Promise<{
|
|
19
19
|
participants: string[];
|
|
20
20
|
active: boolean;
|
|
21
|
+
observers?: number | undefined;
|
|
21
22
|
}>;
|
|
22
23
|
export declare const findJamRecording: (recordingId: string) => Promise<import("@openpeepshq/common").JamRecordingWithMeta | undefined>;
|
|
23
24
|
export declare const findActiveRecording: (jamPost: PostWithMeta) => Promise<import("@openpeepshq/common").JamRecordingWithMeta | undefined>;
|
package/dist/jams/livekit.d.ts
CHANGED
|
@@ -13,6 +13,16 @@ export declare const JAM_ROOM_DEPARTURE_TIMEOUT_SEC = 60;
|
|
|
13
13
|
*/
|
|
14
14
|
export declare const shouldReclaimJamRoom: (numParticipants: number, humanCount: number) => boolean;
|
|
15
15
|
export declare const roomService: () => Promise<RoomServiceClient | undefined>;
|
|
16
|
+
export declare const isEgressIdentity: (identity: string) => boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Split LiveKit participant identities into humans and hidden external
|
|
19
|
+
* sessions (observer links, recording/RTMP web egress), which share the
|
|
20
|
+
* `EG_` identity prefix minted by `createJamEgressToken()`.
|
|
21
|
+
*/
|
|
22
|
+
export declare const splitJamParticipants: (identities: string[]) => {
|
|
23
|
+
humans: string[];
|
|
24
|
+
observers: number;
|
|
25
|
+
};
|
|
16
26
|
export declare const listParticipantIds: (jamId: string) => Promise<string[]>;
|
|
17
27
|
/**
|
|
18
28
|
* Relative path for the observer view (full jam UI). Used for human
|
package/dist/jams/livekit.js
CHANGED
|
@@ -35,6 +35,34 @@ export const roomService = async () => {
|
|
|
35
35
|
}
|
|
36
36
|
return new RoomServiceClient(url, apiKey, apiSecret);
|
|
37
37
|
};
|
|
38
|
+
/** Egress identities are minted only by createJamEgressToken(). */
|
|
39
|
+
const EGRESS_IDENTITY_PREFIX = 'EG_';
|
|
40
|
+
export const isEgressIdentity = (identity) => identity.startsWith(EGRESS_IDENTITY_PREFIX);
|
|
41
|
+
/**
|
|
42
|
+
* Split LiveKit participant identities into humans and hidden external
|
|
43
|
+
* sessions (observer links, recording/RTMP web egress), which share the
|
|
44
|
+
* `EG_` identity prefix minted by `createJamEgressToken()`.
|
|
45
|
+
*/
|
|
46
|
+
export const splitJamParticipants = (identities) => {
|
|
47
|
+
const humans = [];
|
|
48
|
+
let observers = 0;
|
|
49
|
+
for (const identity of identities) {
|
|
50
|
+
if (isEgressIdentity(identity)) {
|
|
51
|
+
observers += 1;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
humans.push(identity);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return { humans, observers };
|
|
58
|
+
};
|
|
59
|
+
const listParticipantIdentities = async (jamId) => {
|
|
60
|
+
const rs = await roomService();
|
|
61
|
+
if (rs === undefined) {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
return (await rs.listParticipants(jamId)).map((p) => p.identity);
|
|
65
|
+
};
|
|
38
66
|
export const listParticipantIds = async (jamId) => {
|
|
39
67
|
const rs = await roomService();
|
|
40
68
|
if (rs === undefined) {
|
|
@@ -42,7 +70,7 @@ export const listParticipantIds = async (jamId) => {
|
|
|
42
70
|
}
|
|
43
71
|
return (await rs.listParticipants(jamId))
|
|
44
72
|
.map((p) => p.identity)
|
|
45
|
-
.filter((identity) => !identity
|
|
73
|
+
.filter((identity) => !isEgressIdentity(identity));
|
|
46
74
|
};
|
|
47
75
|
const getJamEgressToken = async (jamId) => createSignedServiceToken({
|
|
48
76
|
scopes: [
|
|
@@ -283,7 +311,7 @@ export const finishRecording = async (jamRecording) => {
|
|
|
283
311
|
await roomService().then(async (rs) => rs?.sendData(jamRoomName(jamRecording.post.id), encoder.encode(JSON.stringify(jamEvent)), DataPacket_Kind.LOSSY, {}));
|
|
284
312
|
};
|
|
285
313
|
export const jamState = async (jam, hideParticipants, recurrenceId) => {
|
|
286
|
-
const inactive = { participants: [], active: false };
|
|
314
|
+
const inactive = { participants: [], active: false, observers: 0 };
|
|
287
315
|
const rs = await roomService();
|
|
288
316
|
const roomName = jamRoomName(jam.id, recurrenceId);
|
|
289
317
|
if (rs === undefined) {
|
|
@@ -302,14 +330,16 @@ export const jamState = async (jam, hideParticipants, recurrenceId) => {
|
|
|
302
330
|
if (!room.numParticipants) {
|
|
303
331
|
return inactive;
|
|
304
332
|
}
|
|
305
|
-
const
|
|
306
|
-
|
|
333
|
+
const identities = await listParticipantIdentities(roomName);
|
|
334
|
+
const { humans, observers } = splitJamParticipants(identities);
|
|
335
|
+
if (shouldReclaimJamRoom(room.numParticipants, humans.length)) {
|
|
307
336
|
void reclaimOrphanJamRoom(jam, roomName);
|
|
308
337
|
return inactive;
|
|
309
338
|
}
|
|
310
339
|
return {
|
|
311
|
-
participants: hideParticipants ? [] :
|
|
340
|
+
participants: hideParticipants ? [] : humans,
|
|
312
341
|
active: true,
|
|
342
|
+
observers,
|
|
313
343
|
};
|
|
314
344
|
}
|
|
315
345
|
catch (e) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AuthorizationData, PostWithMeta } from '@openpeepshq/common/types';
|
|
1
|
+
import type { AuthorizationData, EventRangeQueryParams, PostWithMeta } from '@openpeepshq/common/types';
|
|
2
2
|
import { type PgDb } from '../db';
|
|
3
3
|
export type EventAgendaWindow = 'upcoming' | 'current' | 'past';
|
|
4
4
|
export type EventAgendaOptions = {
|
|
@@ -19,6 +19,170 @@ export type EventAgendaQueryArgs = {
|
|
|
19
19
|
profileId?: string;
|
|
20
20
|
excludeCreatorIds?: string[];
|
|
21
21
|
};
|
|
22
|
+
/** Query params of the date-range event feeds (calendar). */
|
|
23
|
+
export type EventRangeOptions = {
|
|
24
|
+
jamOnly?: boolean;
|
|
25
|
+
mine?: boolean;
|
|
26
|
+
groupId?: string;
|
|
27
|
+
};
|
|
28
|
+
export type EventRangeQueryArgs = {
|
|
29
|
+
from: string;
|
|
30
|
+
to: string;
|
|
31
|
+
offset: number;
|
|
32
|
+
limit: number;
|
|
33
|
+
jamOnly?: boolean;
|
|
34
|
+
mine?: boolean;
|
|
35
|
+
groupId?: string;
|
|
36
|
+
profileId?: string;
|
|
37
|
+
excludeCreatorIds?: string[];
|
|
38
|
+
};
|
|
39
|
+
/** One row per occurrence overlapping [from, to), ordered by start. */
|
|
40
|
+
export declare const eventRangeOccurrenceQuery: (db: Pick<PgDb, "select">, args: EventRangeQueryArgs) => Omit<import("drizzle-orm/pg-core").PgSelectBase<"event_occurrences", {
|
|
41
|
+
postId: import("drizzle-orm/pg-core").PgColumn<{
|
|
42
|
+
name: "post_id";
|
|
43
|
+
tableName: "event_occurrences";
|
|
44
|
+
dataType: "string";
|
|
45
|
+
columnType: "PgUUID";
|
|
46
|
+
data: string;
|
|
47
|
+
driverParam: string;
|
|
48
|
+
notNull: true;
|
|
49
|
+
hasDefault: false;
|
|
50
|
+
isPrimaryKey: false;
|
|
51
|
+
isAutoincrement: false;
|
|
52
|
+
hasRuntimeDefault: false;
|
|
53
|
+
enumValues: undefined;
|
|
54
|
+
baseColumn: never;
|
|
55
|
+
identity: undefined;
|
|
56
|
+
generated: undefined;
|
|
57
|
+
}, {}, {}>;
|
|
58
|
+
recurrenceId: import("drizzle-orm/pg-core").PgColumn<{
|
|
59
|
+
name: "recurrence_id";
|
|
60
|
+
tableName: "event_occurrences";
|
|
61
|
+
dataType: "string";
|
|
62
|
+
columnType: "PgTimestampString";
|
|
63
|
+
data: string;
|
|
64
|
+
driverParam: string;
|
|
65
|
+
notNull: true;
|
|
66
|
+
hasDefault: false;
|
|
67
|
+
isPrimaryKey: false;
|
|
68
|
+
isAutoincrement: false;
|
|
69
|
+
hasRuntimeDefault: false;
|
|
70
|
+
enumValues: undefined;
|
|
71
|
+
baseColumn: never;
|
|
72
|
+
identity: undefined;
|
|
73
|
+
generated: undefined;
|
|
74
|
+
}, {}, {}>;
|
|
75
|
+
start: import("drizzle-orm/pg-core").PgColumn<{
|
|
76
|
+
name: "start";
|
|
77
|
+
tableName: "event_occurrences";
|
|
78
|
+
dataType: "string";
|
|
79
|
+
columnType: "PgTimestampString";
|
|
80
|
+
data: string;
|
|
81
|
+
driverParam: string;
|
|
82
|
+
notNull: true;
|
|
83
|
+
hasDefault: false;
|
|
84
|
+
isPrimaryKey: false;
|
|
85
|
+
isAutoincrement: false;
|
|
86
|
+
hasRuntimeDefault: false;
|
|
87
|
+
enumValues: undefined;
|
|
88
|
+
baseColumn: never;
|
|
89
|
+
identity: undefined;
|
|
90
|
+
generated: undefined;
|
|
91
|
+
}, {}, {}>;
|
|
92
|
+
end: import("drizzle-orm/pg-core").PgColumn<{
|
|
93
|
+
name: "end";
|
|
94
|
+
tableName: "event_occurrences";
|
|
95
|
+
dataType: "string";
|
|
96
|
+
columnType: "PgTimestampString";
|
|
97
|
+
data: string;
|
|
98
|
+
driverParam: string;
|
|
99
|
+
notNull: false;
|
|
100
|
+
hasDefault: false;
|
|
101
|
+
isPrimaryKey: false;
|
|
102
|
+
isAutoincrement: false;
|
|
103
|
+
hasRuntimeDefault: false;
|
|
104
|
+
enumValues: undefined;
|
|
105
|
+
baseColumn: never;
|
|
106
|
+
identity: undefined;
|
|
107
|
+
generated: undefined;
|
|
108
|
+
}, {}, {}>;
|
|
109
|
+
}, "partial", Record<"event_occurrences", "not-null"> & {
|
|
110
|
+
posts: "not-null";
|
|
111
|
+
}, false, "limit" | "offset" | "where" | "orderBy", {
|
|
112
|
+
postId: string;
|
|
113
|
+
recurrenceId: string;
|
|
114
|
+
start: string;
|
|
115
|
+
end: string | null;
|
|
116
|
+
}[], {
|
|
117
|
+
postId: import("drizzle-orm/pg-core").PgColumn<{
|
|
118
|
+
name: "post_id";
|
|
119
|
+
tableName: "event_occurrences";
|
|
120
|
+
dataType: "string";
|
|
121
|
+
columnType: "PgUUID";
|
|
122
|
+
data: string;
|
|
123
|
+
driverParam: string;
|
|
124
|
+
notNull: true;
|
|
125
|
+
hasDefault: false;
|
|
126
|
+
isPrimaryKey: false;
|
|
127
|
+
isAutoincrement: false;
|
|
128
|
+
hasRuntimeDefault: false;
|
|
129
|
+
enumValues: undefined;
|
|
130
|
+
baseColumn: never;
|
|
131
|
+
identity: undefined;
|
|
132
|
+
generated: undefined;
|
|
133
|
+
}, {}, {}>;
|
|
134
|
+
recurrenceId: import("drizzle-orm/pg-core").PgColumn<{
|
|
135
|
+
name: "recurrence_id";
|
|
136
|
+
tableName: "event_occurrences";
|
|
137
|
+
dataType: "string";
|
|
138
|
+
columnType: "PgTimestampString";
|
|
139
|
+
data: string;
|
|
140
|
+
driverParam: string;
|
|
141
|
+
notNull: true;
|
|
142
|
+
hasDefault: false;
|
|
143
|
+
isPrimaryKey: false;
|
|
144
|
+
isAutoincrement: false;
|
|
145
|
+
hasRuntimeDefault: false;
|
|
146
|
+
enumValues: undefined;
|
|
147
|
+
baseColumn: never;
|
|
148
|
+
identity: undefined;
|
|
149
|
+
generated: undefined;
|
|
150
|
+
}, {}, {}>;
|
|
151
|
+
start: import("drizzle-orm/pg-core").PgColumn<{
|
|
152
|
+
name: "start";
|
|
153
|
+
tableName: "event_occurrences";
|
|
154
|
+
dataType: "string";
|
|
155
|
+
columnType: "PgTimestampString";
|
|
156
|
+
data: string;
|
|
157
|
+
driverParam: string;
|
|
158
|
+
notNull: true;
|
|
159
|
+
hasDefault: false;
|
|
160
|
+
isPrimaryKey: false;
|
|
161
|
+
isAutoincrement: false;
|
|
162
|
+
hasRuntimeDefault: false;
|
|
163
|
+
enumValues: undefined;
|
|
164
|
+
baseColumn: never;
|
|
165
|
+
identity: undefined;
|
|
166
|
+
generated: undefined;
|
|
167
|
+
}, {}, {}>;
|
|
168
|
+
end: import("drizzle-orm/pg-core").PgColumn<{
|
|
169
|
+
name: "end";
|
|
170
|
+
tableName: "event_occurrences";
|
|
171
|
+
dataType: "string";
|
|
172
|
+
columnType: "PgTimestampString";
|
|
173
|
+
data: string;
|
|
174
|
+
driverParam: string;
|
|
175
|
+
notNull: false;
|
|
176
|
+
hasDefault: false;
|
|
177
|
+
isPrimaryKey: false;
|
|
178
|
+
isAutoincrement: false;
|
|
179
|
+
hasRuntimeDefault: false;
|
|
180
|
+
enumValues: undefined;
|
|
181
|
+
baseColumn: never;
|
|
182
|
+
identity: undefined;
|
|
183
|
+
generated: undefined;
|
|
184
|
+
}, {}, {}>;
|
|
185
|
+
}>, "limit" | "offset" | "where" | "orderBy">;
|
|
22
186
|
export declare const eventAgendaOccurrenceQuery: (db: Pick<PgDb, "select" | "selectDistinctOn">, args: EventAgendaQueryArgs) => Omit<import("drizzle-orm/pg-core").PgSelectBase<"event_agenda", {
|
|
23
187
|
postId: import("drizzle-orm/pg-core").PgColumn<{
|
|
24
188
|
name: "post_id";
|
|
@@ -163,4 +327,5 @@ export declare const eventAgendaOccurrenceQuery: (db: Pick<PgDb, "select" | "sel
|
|
|
163
327
|
generated: undefined;
|
|
164
328
|
}, {}, {}>;
|
|
165
329
|
}>, "limit" | "offset" | "orderBy">;
|
|
330
|
+
export declare const listEventsInRange: (authData: AuthorizationData, params: EventRangeQueryParams, { jamOnly, mine, groupId }?: EventRangeOptions) => Promise<PostWithMeta[]>;
|
|
166
331
|
export declare const listEventAgenda: (authData: AuthorizationData, window: EventAgendaWindow, { offset, limit, jamOnly, mine, groupId, }?: EventAgendaOptions) => Promise<PostWithMeta[]>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { notInArray, and, asc, desc, eq, isNotNull, isNull, lte, or, sql, } from 'drizzle-orm';
|
|
2
|
+
import { EVENT_RANGE_DEFAULT_LIMIT, EVENT_RANGE_MAX_SPAN_MS, } from '@openpeepshq/common/types';
|
|
2
3
|
import { canReadPost } from './helpers/filters.js';
|
|
3
4
|
import { transformPost } from './helpers/index.js';
|
|
4
5
|
import { allpeepDb } from '../db/index.js';
|
|
@@ -25,6 +26,7 @@ const occurrenceTimeFilter = (window, now) => {
|
|
|
25
26
|
}
|
|
26
27
|
return sql `COALESCE(${end}, ${start} + interval '1 hour') < ${now}`;
|
|
27
28
|
};
|
|
29
|
+
const eventRangeTimeFilter = (from, to) => and(sql `${eventOccurrences.start} < ${to}`, sql `COALESCE(${eventOccurrences.end}, ${eventOccurrences.start} + interval '1 hour') >= ${from}`);
|
|
28
30
|
const eventAgendaConditions = ({ window, now, jamOnly, mine, groupId, profileId, excludeCreatorIds, }) => {
|
|
29
31
|
const conditions = [
|
|
30
32
|
isNull(posts.deletedAt),
|
|
@@ -46,6 +48,42 @@ const eventAgendaConditions = ({ window, now, jamOnly, mine, groupId, profileId,
|
|
|
46
48
|
}
|
|
47
49
|
return conditions;
|
|
48
50
|
};
|
|
51
|
+
const rangeAgendaConditions = ({ from, to, jamOnly, mine, groupId, profileId, excludeCreatorIds, }) => [
|
|
52
|
+
isNull(posts.deletedAt),
|
|
53
|
+
eq(posts.type, 'event'),
|
|
54
|
+
eq(eventOccurrences.cancelled, false),
|
|
55
|
+
eventRangeTimeFilter(from, to),
|
|
56
|
+
...(jamOnly ? [isNotNull(sql `${posts.body}->'jam'`)] : []),
|
|
57
|
+
...(mine && profileId
|
|
58
|
+
? [
|
|
59
|
+
or(eq(posts.creatorId, profileId), postFilters.isJamModerator(profileId).where, postHasYesOrMaybeRsvpExpr(posts, profileId)),
|
|
60
|
+
]
|
|
61
|
+
: []),
|
|
62
|
+
...(groupId
|
|
63
|
+
? [
|
|
64
|
+
sql `EXISTS (SELECT 1 FROM ${postGroups} WHERE ${postGroups.fromId} = ${posts.id}::text AND ${postGroups.toId} = ${groupId})`,
|
|
65
|
+
]
|
|
66
|
+
: []),
|
|
67
|
+
...(excludeCreatorIds?.length
|
|
68
|
+
? [notInArray(posts.creatorId, excludeCreatorIds)]
|
|
69
|
+
: []),
|
|
70
|
+
];
|
|
71
|
+
/** One row per occurrence overlapping [from, to), ordered by start. */
|
|
72
|
+
export const eventRangeOccurrenceQuery = (db, args) => db
|
|
73
|
+
.select({
|
|
74
|
+
postId: eventOccurrences.postId,
|
|
75
|
+
recurrenceId: eventOccurrences.recurrenceId,
|
|
76
|
+
start: eventOccurrences.start,
|
|
77
|
+
end: eventOccurrences.end,
|
|
78
|
+
})
|
|
79
|
+
.from(eventOccurrences)
|
|
80
|
+
.innerJoin(posts, eq(posts.id, eventOccurrences.postId))
|
|
81
|
+
.where(and(...rangeAgendaConditions(args)))
|
|
82
|
+
// Ties on start (two series at the same instant) need a stable
|
|
83
|
+
// tiebreaker or LIMIT/OFFSET pages would shuffle between requests.
|
|
84
|
+
.orderBy(asc(eventOccurrences.start), asc(eventOccurrences.postId), asc(eventOccurrences.recurrenceId))
|
|
85
|
+
.limit(args.limit)
|
|
86
|
+
.offset(args.offset);
|
|
49
87
|
// One row per event: a daily series would otherwise fill the first page.
|
|
50
88
|
export const eventAgendaOccurrenceQuery = (db, args) => {
|
|
51
89
|
const pickOrder = args.window === 'past'
|
|
@@ -95,6 +133,49 @@ const loadPostsByIds = async (ids, authData) => {
|
|
|
95
133
|
.filter((post) => !!post)
|
|
96
134
|
.map((post) => [post.id, post]));
|
|
97
135
|
};
|
|
136
|
+
export const listEventsInRange = async (authData, params, { jamOnly = false, mine = false, groupId } = {}) => {
|
|
137
|
+
const fromMs = new Date(params.from).getTime();
|
|
138
|
+
const toMs = new Date(params.to).getTime();
|
|
139
|
+
if (Number.isNaN(fromMs) ||
|
|
140
|
+
Number.isNaN(toMs) ||
|
|
141
|
+
fromMs >= toMs ||
|
|
142
|
+
toMs - fromMs > EVENT_RANGE_MAX_SPAN_MS) {
|
|
143
|
+
throw new Error('listEventsInRange requires from < to with a span of at most 62 days');
|
|
144
|
+
}
|
|
145
|
+
const offset = params.offset ?? 0;
|
|
146
|
+
const limit = params.limit ?? EVENT_RANGE_DEFAULT_LIMIT;
|
|
147
|
+
const { db } = await allpeepDb();
|
|
148
|
+
const rows = await eventRangeOccurrenceQuery(db, {
|
|
149
|
+
from: params.from,
|
|
150
|
+
to: params.to,
|
|
151
|
+
offset,
|
|
152
|
+
limit,
|
|
153
|
+
jamOnly,
|
|
154
|
+
mine,
|
|
155
|
+
groupId,
|
|
156
|
+
profileId: authData.profile?.id,
|
|
157
|
+
excludeCreatorIds: blockedPairIds(authData.profile),
|
|
158
|
+
});
|
|
159
|
+
const postsById = await loadPostsByIds([...new Set(rows.map((row) => row.postId))], authData);
|
|
160
|
+
return rows.flatMap((row) => {
|
|
161
|
+
const post = postsById.get(row.postId);
|
|
162
|
+
if (!post)
|
|
163
|
+
return [];
|
|
164
|
+
const occurrenceRecurrenceId = normalizeComputedDatetime(row.recurrenceId);
|
|
165
|
+
const occurrenceStart = normalizeComputedDatetime(row.start);
|
|
166
|
+
const occurrenceEnd = normalizeComputedDatetime(row.end);
|
|
167
|
+
if (!occurrenceRecurrenceId || !occurrenceStart)
|
|
168
|
+
return [];
|
|
169
|
+
return [
|
|
170
|
+
{
|
|
171
|
+
...post,
|
|
172
|
+
occurrenceRecurrenceId,
|
|
173
|
+
occurrenceStart,
|
|
174
|
+
...(occurrenceEnd ? { occurrenceEnd } : {}),
|
|
175
|
+
},
|
|
176
|
+
];
|
|
177
|
+
});
|
|
178
|
+
};
|
|
98
179
|
export const listEventAgenda = async (authData, window, { offset = 0, limit = 100, jamOnly = false, mine = false, groupId, } = {}) => {
|
|
99
180
|
const { db } = await allpeepDb();
|
|
100
181
|
const now = new Date().toISOString();
|
package/dist/posts/index.d.ts
CHANGED
|
@@ -9,7 +9,8 @@ export { bumpConversationActivity, findReplyRootId } from './activity';
|
|
|
9
9
|
export { registerRsvpConfirmationEmail } from './rsvpConfirmationEmail';
|
|
10
10
|
export { exportEventRsvpsCsv } from './rsvpExport';
|
|
11
11
|
export { rebuildEventOccurrences, clearEventOccurrences, backfillMissingEventOccurrences, rebuildRecurringEventOccurrences, } from './eventOccurrences';
|
|
12
|
-
export {
|
|
12
|
+
export { eventRangeQueryParamsSchema, type EventRangeQueryParams, } from '@openpeepshq/common/types';
|
|
13
|
+
export { eventRangeOccurrenceQuery, listEventsInRange, listEventAgenda, } from './eventAgenda';
|
|
13
14
|
export { eventOccurrenceQueue, eventOccurrenceWorker, ensureEventOccurrenceSchedule, } from './eventOccurrenceJobs';
|
|
14
15
|
export { pollEndQueue, pollEndWorker, schedulePollEnd, cancelPollEnd, } from './pollEndJobs';
|
|
15
16
|
export { waitlistOfferQueue, waitlistOfferWorker } from './waitlistOfferJobs';
|
package/dist/posts/index.js
CHANGED
|
@@ -9,7 +9,8 @@ export { bumpConversationActivity, findReplyRootId } from './activity.js';
|
|
|
9
9
|
export { registerRsvpConfirmationEmail } from './rsvpConfirmationEmail.js';
|
|
10
10
|
export { exportEventRsvpsCsv } from './rsvpExport.js';
|
|
11
11
|
export { rebuildEventOccurrences, clearEventOccurrences, backfillMissingEventOccurrences, rebuildRecurringEventOccurrences, } from './eventOccurrences.js';
|
|
12
|
-
export {
|
|
12
|
+
export { eventRangeQueryParamsSchema, } from '@openpeepshq/common/types';
|
|
13
|
+
export { eventRangeOccurrenceQuery, listEventsInRange, listEventAgenda, } from './eventAgenda.js';
|
|
13
14
|
export { eventOccurrenceQueue, eventOccurrenceWorker, ensureEventOccurrenceSchedule, } from './eventOccurrenceJobs.js';
|
|
14
15
|
export { pollEndQueue, pollEndWorker, schedulePollEnd, cancelPollEnd, } from './pollEndJobs.js';
|
|
15
16
|
export { waitlistOfferQueue, waitlistOfferWorker } from './waitlistOfferJobs.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpeepshq/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"dependencies": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"dotenv": "^16.4.7",
|
|
20
20
|
"drizzle-orm": "^0.45.2",
|
|
21
21
|
"extract-zip": "^2.0.1",
|
|
22
|
-
"firebase-admin": "^13.
|
|
22
|
+
"firebase-admin": "^13.10.0",
|
|
23
23
|
"fluent-ffmpeg": "^2.1.3",
|
|
24
24
|
"fs-extra": "^11.3.0",
|
|
25
25
|
"html-to-text": "^9.0.5",
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"type-fest": "^4.31.0",
|
|
38
38
|
"uuidv7": "^1.0.2",
|
|
39
39
|
"web-push": "^3.6.7",
|
|
40
|
-
"@openpeepshq/common": "0.
|
|
41
|
-
"@openpeepshq/
|
|
42
|
-
"@openpeepshq/i18n": "^0.
|
|
43
|
-
"@openpeepshq/
|
|
40
|
+
"@openpeepshq/common": "0.9.0",
|
|
41
|
+
"@openpeepshq/geocoder": "^0.1.2",
|
|
42
|
+
"@openpeepshq/i18n": "^0.10.0",
|
|
43
|
+
"@openpeepshq/fetch-client": "^0.2.1"
|
|
44
44
|
},
|
|
45
45
|
"main": "dist/index.js",
|
|
46
46
|
"types": "dist/index.d.ts",
|