@openpeepshq/core 0.5.2 → 0.6.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.
@@ -1,5 +1,11 @@
1
1
  import type { AnalyticsDateQuery } from '@openpeepshq/common/types';
2
- /** Board-ready report: plain-text email body + visual multi-page PDF. */
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>;
@@ -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
- /** Board-ready report: plain-text email body + visual multi-page PDF. */
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
- const summary = [
41
- `Executive summary (${from} → ${to})`,
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,
@@ -5,6 +5,7 @@ export type LocalActor = {
5
5
  displayName?: string;
6
6
  bio?: string;
7
7
  avatar?: string | null;
8
+ discoverable?: boolean;
8
9
  createdAt: string;
9
10
  deleted: boolean;
10
11
  };
@@ -45,6 +45,8 @@ export const loadLocalActor = async (profileId) => {
45
45
  displayName: body.displayName,
46
46
  bio: body.bio,
47
47
  avatar: body.avatar,
48
+ // Only an explicit false survives; absent and true normalize to undefined.
49
+ discoverable: body.discoverable === false ? false : undefined,
48
50
  createdAt: row.createdAt,
49
51
  deleted: row.deletedAt != null,
50
52
  };
@@ -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();
@@ -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 { listEventAgenda } from './eventAgenda';
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';
@@ -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 { listEventAgenda } from './eventAgenda.js';
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.5.2",
3
+ "version": "0.6.1",
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.4.0",
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.8.0",
40
41
  "@openpeepshq/fetch-client": "^0.2.1",
41
- "@openpeepshq/common": "0.6.3",
42
- "@openpeepshq/geocoder": "^0.1.2",
43
- "@openpeepshq/i18n": "^0.7.0"
42
+ "@openpeepshq/i18n": "^0.9.1",
43
+ "@openpeepshq/geocoder": "^0.1.2"
44
44
  },
45
45
  "main": "dist/index.js",
46
46
  "types": "dist/index.d.ts",