@openpeepshq/core 0.1.34 → 0.1.35

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 (165) hide show
  1. package/dist/accessTokens/finders.js +5 -6
  2. package/dist/accessTokens/mutations.js +1 -1
  3. package/dist/accessTokens/tokens.js +8 -11
  4. package/dist/accounts/helpers.js +6 -2
  5. package/dist/accounts/mutations.js +13 -8
  6. package/dist/analytics/cache.js +3 -3
  7. package/dist/analytics/clicks.js +14 -22
  8. package/dist/analytics/compile.js +1 -2
  9. package/dist/analytics/dateRange.js +3 -5
  10. package/dist/analytics/jobs.js +3 -4
  11. package/dist/analytics/pdfReport.js +45 -61
  12. package/dist/analytics/privacy.js +1 -1
  13. package/dist/analytics/read.js +116 -135
  14. package/dist/analytics/report.d.ts +2 -1
  15. package/dist/analytics/report.js +2 -3
  16. package/dist/analytics/settings.js +3 -4
  17. package/dist/backups/index.js +13 -16
  18. package/dist/backups/metadata.js +1 -1
  19. package/dist/config/db.js +2 -4
  20. package/dist/config/defaults/community.js +1 -0
  21. package/dist/config/defaults/core.js +13 -8
  22. package/dist/config/index.d.ts +1 -0
  23. package/dist/config/index.js +9 -11
  24. package/dist/db/explorer/query.js +9 -8
  25. package/dist/db/explorer/sql.js +8 -8
  26. package/dist/db/helpers.js +15 -5
  27. package/dist/db/migration/importCollections.js +15 -18
  28. package/dist/db/migration/shared.js +15 -35
  29. package/dist/db/pg/client.js +4 -7
  30. package/dist/db/pg/filters/index.js +1 -1
  31. package/dist/db/pg/filters/posts.d.ts +2 -0
  32. package/dist/db/pg/filters/posts.js +2 -0
  33. package/dist/db/pg/helpers.js +2 -14
  34. package/dist/db/pg/map/filters.js +8 -8
  35. package/dist/db/pg/map/helpers.js +5 -1
  36. package/dist/db/pg/map/index.js +46 -51
  37. package/dist/db/pg/map/mutations.js +56 -21
  38. package/dist/db/pg/map/registry.js +87 -50
  39. package/dist/db/pg/map/relations.js +67 -63
  40. package/dist/db/pg/map/search.js +15 -37
  41. package/dist/db/pg/mappers.js +13 -7
  42. package/dist/db/pg/migrate.js +2 -3
  43. package/dist/db/pg/queries/activity.js +2 -2
  44. package/dist/db/pg/queries/derived.js +8 -12
  45. package/dist/db/pg/schema/documents.js +119 -18
  46. package/dist/db/pg/schema/edges.js +7 -1
  47. package/dist/db/pg/schema/index.js +5 -1
  48. package/dist/db/pg/sql/0016_posts_search_vector_title_tags_path.sql +54 -0
  49. package/dist/db/pg/sql/meta/_journal.json +8 -1
  50. package/dist/db/replaceOrigin.js +1 -1
  51. package/dist/email/queueStats.js +8 -11
  52. package/dist/email/render.js +7 -4
  53. package/dist/email/send.js +19 -17
  54. package/dist/email/smtpTest.js +10 -6
  55. package/dist/errors/index.js +1 -1
  56. package/dist/events/once.js +2 -4
  57. package/dist/federation/activities.js +1 -2
  58. package/dist/groups/helpers.js +1 -2
  59. package/dist/groups/mutations.js +1 -1
  60. package/dist/hashtags/finders.js +2 -2
  61. package/dist/inviteLinks/mutations.js +2 -3
  62. package/dist/jams/export.js +5 -7
  63. package/dist/jams/finders.js +4 -1
  64. package/dist/jams/health.d.ts +6 -4
  65. package/dist/jams/health.js +15 -11
  66. package/dist/jams/helpers.js +6 -2
  67. package/dist/jams/index.js +2 -2
  68. package/dist/jams/jobs.js +1 -2
  69. package/dist/jams/livekit.js +8 -8
  70. package/dist/jams/recording.js +1 -1
  71. package/dist/jams/token.js +13 -17
  72. package/dist/jobs/index.js +7 -6
  73. package/dist/jobs/jobDetail.js +5 -6
  74. package/dist/jobs/jobLog.js +2 -3
  75. package/dist/lib/streams.js +4 -39
  76. package/dist/lib/zodDeepPartial.d.ts +1 -1
  77. package/dist/lib/zodDeepPartial.js +1 -1
  78. package/dist/log/index.js +13 -29
  79. package/dist/media/index.js +50 -4
  80. package/dist/media/jobs.js +1 -2
  81. package/dist/media/openpeeps/index.js +11 -46
  82. package/dist/media/processing.js +7 -4
  83. package/dist/media/streaming.js +5 -5
  84. package/dist/media/streamingCleanupJobs.js +1 -2
  85. package/dist/media/streamingJobs.js +3 -4
  86. package/dist/media/streamingPrewarm.js +7 -11
  87. package/dist/mediaAttachments/index.js +6 -2
  88. package/dist/notifications/defaultNotifications/announcement/index.js +15 -18
  89. package/dist/notifications/defaultNotifications/directMessage/index.js +9 -8
  90. package/dist/notifications/defaultNotifications/follow/index.js +14 -17
  91. package/dist/notifications/defaultNotifications/groupAdded/index.js +14 -17
  92. package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +15 -18
  93. package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +15 -18
  94. package/dist/notifications/defaultNotifications/jamModerator/index.js +3 -5
  95. package/dist/notifications/defaultNotifications/jamSpeaker/index.js +14 -18
  96. package/dist/notifications/defaultNotifications/jamStarted/index.js +18 -22
  97. package/dist/notifications/defaultNotifications/mention/index.js +20 -24
  98. package/dist/notifications/defaultNotifications/newGroupPost/index.js +6 -7
  99. package/dist/notifications/defaultNotifications/newProfile/index.js +14 -17
  100. package/dist/notifications/defaultNotifications/pollEnded/index.js +21 -21
  101. package/dist/notifications/defaultNotifications/pollEnded/recipients.js +2 -3
  102. package/dist/notifications/defaultNotifications/pollVote/index.js +14 -17
  103. package/dist/notifications/defaultNotifications/reaction/index.js +18 -21
  104. package/dist/notifications/defaultNotifications/reply/index.js +21 -22
  105. package/dist/notifications/defaultNotifications/repost/index.js +16 -20
  106. package/dist/notifications/defaultNotifications/rsvp/index.js +24 -18
  107. package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +20 -13
  108. package/dist/notifications/fcmCredential.js +1 -1
  109. package/dist/notifications/finders.js +1 -1
  110. package/dist/notifications/helpers.js +13 -10
  111. package/dist/notifications/jobs.js +10 -7
  112. package/dist/notifications/mutations.js +4 -1
  113. package/dist/notifications/push.js +11 -16
  114. package/dist/performance/index.js +3 -3
  115. package/dist/plugins/helpers.js +3 -6
  116. package/dist/plugins/index.js +2 -3
  117. package/dist/plugins/install.js +31 -17
  118. package/dist/plugins/pluginAuth.js +3 -4
  119. package/dist/plugins/state.js +2 -3
  120. package/dist/posts/activity.js +1 -2
  121. package/dist/posts/contextClosure.js +1 -2
  122. package/dist/posts/conversationQueries.js +2 -4
  123. package/dist/posts/eventAgenda.js +8 -5
  124. package/dist/posts/eventOccurrences.js +2 -2
  125. package/dist/posts/finders.d.ts +42 -2
  126. package/dist/posts/finders.js +21 -9
  127. package/dist/posts/helpers/filters.js +2 -3
  128. package/dist/posts/helpers/index.d.ts +152 -0
  129. package/dist/posts/helpers/index.js +43 -27
  130. package/dist/posts/mapping.d.ts +546 -14
  131. package/dist/posts/mapping.js +60 -18
  132. package/dist/posts/mutations.d.ts +76 -0
  133. package/dist/posts/mutations.js +46 -31
  134. package/dist/posts/pollEnd.js +3 -6
  135. package/dist/posts/rsvpConfirmationEmail.js +18 -8
  136. package/dist/posts/threadPreview.js +1 -1
  137. package/dist/processingStats/queries.js +6 -7
  138. package/dist/profileSettings/cache.js +1 -2
  139. package/dist/profiles/activitySummary.js +23 -28
  140. package/dist/profiles/cache.js +15 -8
  141. package/dist/profiles/export.js +30 -39
  142. package/dist/profiles/finders.js +7 -5
  143. package/dist/profiles/mutations.js +3 -5
  144. package/dist/redis/connection.js +1 -1
  145. package/dist/reports/helpers.js +7 -3
  146. package/dist/roles/mutations.js +20 -21
  147. package/dist/search/finders.js +15 -3
  148. package/dist/search/helpers.js +1 -1
  149. package/dist/sentry/index.js +9 -11
  150. package/dist/seo/index.d.ts +50 -0
  151. package/dist/seo/index.js +145 -0
  152. package/dist/seo/route.d.ts +18 -0
  153. package/dist/seo/route.js +19 -0
  154. package/dist/server/index.d.ts +1 -0
  155. package/dist/server/index.js +16 -11
  156. package/dist/server/status.js +6 -7
  157. package/dist/session/index.js +2 -2
  158. package/dist/stats/finders.js +13 -4
  159. package/dist/stats/helpers.js +4 -1
  160. package/dist/stats/mapping.d.ts +39 -1
  161. package/dist/stats/mapping.js +9 -2
  162. package/dist/stripe/cache.js +5 -6
  163. package/dist/stripe/connection.js +3 -4
  164. package/dist/stripe/helpers.js +15 -20
  165. package/package.json +5 -6
@@ -3,7 +3,7 @@ import { postFilters } from '../db/pg/filters/index.js';
3
3
  import { postDerived } from '../db/pg/queries/index.js';
4
4
  import { collectionInfos } from '../db/index.js';
5
5
  import { groupsMapping } from '../groups/mapping.js';
6
- const seenBatchByCurrentProfileDerivedProperty = (profile) => postDerived.seenBatch(profile === null || profile === void 0 ? void 0 : profile.id);
6
+ const seenBatchByCurrentProfileDerivedProperty = (profile) => postDerived.seenBatch(profile?.id);
7
7
  export const entriesRelation = {
8
8
  alias: 'entries',
9
9
  edgeCollection: 'entries',
@@ -114,7 +114,10 @@ const preFilterMapData = {
114
114
  collection: 'posts',
115
115
  softDelete: true,
116
116
  };
117
- const basePostMapData = Object.assign(Object.assign({}, preFilterMapData), { postFilterRelations: basePostFilterRelations, postFilterDerivedProperties: [
117
+ const basePostMapData = {
118
+ ...preFilterMapData,
119
+ postFilterRelations: basePostFilterRelations,
120
+ postFilterDerivedProperties: [
118
121
  {
119
122
  alias: 'inReplyToId',
120
123
  resolve: postDerived.inReplyToId,
@@ -123,11 +126,15 @@ const basePostMapData = Object.assign(Object.assign({}, preFilterMapData), { pos
123
126
  alias: 'groupId',
124
127
  resolve: postDerived.groupId,
125
128
  },
126
- ] });
127
- const basePostMapDataForProfile = (profile) => (Object.assign(Object.assign({}, basePostMapData), { postFilterDerivedProperties: [
129
+ ],
130
+ };
131
+ const basePostMapDataForProfile = (profile) => ({
132
+ ...basePostMapData,
133
+ postFilterDerivedProperties: [
128
134
  ...(basePostMapData.postFilterDerivedProperties || []),
129
135
  seenBatchByCurrentProfileDerivedProperty(profile),
130
- ] }));
136
+ ],
137
+ });
131
138
  // Keep soft-deleted parents so replies can render a tombstone / deleted post.
132
139
  const replyPostMapData = {
133
140
  collection: 'posts',
@@ -160,26 +167,44 @@ export const repostRelation = {
160
167
  direction: 'OUTBOUND',
161
168
  skipEdge: true,
162
169
  cardinality: 'one',
163
- mapping: Object.assign(Object.assign({}, basePostMapData), { postFilterRelations: [...basePostFilterRelations, replyToRelation] }),
170
+ mapping: {
171
+ ...basePostMapData,
172
+ postFilterRelations: [...basePostFilterRelations, replyToRelation],
173
+ },
164
174
  };
165
- export const repostRelationForProfile = (profile) => (Object.assign(Object.assign({}, repostRelation), { mapping: Object.assign(Object.assign({}, basePostMapDataForProfile(profile)), { postFilterRelations: [...basePostFilterRelations, replyToRelation] }) }));
175
+ export const repostRelationForProfile = (profile) => ({
176
+ ...repostRelation,
177
+ mapping: {
178
+ ...basePostMapDataForProfile(profile),
179
+ postFilterRelations: [...basePostFilterRelations, replyToRelation],
180
+ },
181
+ });
166
182
  export const repostsOfPostRelation = {
167
183
  alias: 'reposts',
168
184
  edgeCollection: 'repost',
169
185
  direction: 'INBOUND',
170
186
  skipEdge: true,
171
187
  cardinality: 'many',
172
- mapping: Object.assign(Object.assign({}, basePostMapData), { postFilterRelations: [
188
+ mapping: {
189
+ ...basePostMapData,
190
+ postFilterRelations: [
173
191
  ...basePostFilterRelations,
174
192
  repostRelation,
175
193
  replyToRelation,
176
- ] }),
194
+ ],
195
+ },
177
196
  };
178
- export const repostsOfPostRelationForProfile = (profile) => (Object.assign(Object.assign({}, repostsOfPostRelation), { mapping: Object.assign(Object.assign({}, basePostMapDataForProfile(profile)), { postFilterRelations: [
197
+ export const repostsOfPostRelationForProfile = (profile) => ({
198
+ ...repostsOfPostRelation,
199
+ mapping: {
200
+ ...basePostMapDataForProfile(profile),
201
+ postFilterRelations: [
179
202
  ...basePostFilterRelations,
180
203
  repostRelationForProfile(profile),
181
204
  replyToRelation,
182
- ] }) }));
205
+ ],
206
+ },
207
+ });
183
208
  export const postsWithReplyCountMapping = map({
184
209
  collection: 'posts',
185
210
  relations: [replyCountRelation],
@@ -197,18 +222,27 @@ export const postsWithReplyToCountMapping = map({
197
222
  },
198
223
  ],
199
224
  });
200
- export const postsMapping = map(Object.assign(Object.assign({}, basePostMapData), { postFilterRelations: [
225
+ export const postsMapping = map({
226
+ ...basePostMapData,
227
+ postFilterRelations: [
201
228
  ...basePostFilterRelations,
202
229
  repostRelation,
203
230
  replyToRelation,
204
- ] }));
231
+ ],
232
+ });
205
233
  /** Auth / mark-seen: post graph without nested replyTo/repost hydrate. */
206
- export const postsAuthMapping = map(Object.assign(Object.assign({}, basePostMapData), { postFilterRelations: basePostFilterRelations }));
207
- export const postsMappingForProfile = (profile) => map(Object.assign(Object.assign({}, basePostMapDataForProfile(profile)), { postFilterRelations: [
234
+ export const postsAuthMapping = map({
235
+ ...basePostMapData,
236
+ postFilterRelations: basePostFilterRelations,
237
+ });
238
+ export const postsMappingForProfile = (profile) => map({
239
+ ...basePostMapDataForProfile(profile),
240
+ postFilterRelations: [
208
241
  ...basePostFilterRelations,
209
242
  repostRelationForProfile(profile),
210
243
  replyToRelation,
211
- ] }));
244
+ ],
245
+ });
212
246
  /** Lean mapping for post detail context — skips nested repost. Audience is
213
247
  * required so direct replies stay readable to the thread's recipients. */
214
248
  const contextPostFilterRelations = [
@@ -252,6 +286,14 @@ const conversationLeafFilters = [
252
286
  postFilters.replyCountZero(),
253
287
  postFilters.isDirect(),
254
288
  ];
255
- export const conversationLeavesMapping = map(Object.assign(Object.assign({}, basePostMapData), { relations: [replyCountRelation], filters: conversationLeafFilters }));
256
- export const conversationLeavesMappingForProfile = (profile) => map(Object.assign(Object.assign({}, basePostMapDataForProfile(profile)), { relations: [replyCountRelation], filters: conversationLeafFilters }));
289
+ export const conversationLeavesMapping = map({
290
+ ...basePostMapData,
291
+ relations: [replyCountRelation],
292
+ filters: conversationLeafFilters,
293
+ });
294
+ export const conversationLeavesMappingForProfile = (profile) => map({
295
+ ...basePostMapDataForProfile(profile),
296
+ relations: [replyCountRelation],
297
+ filters: conversationLeafFilters,
298
+ });
257
299
  export const postIdsMapping = map(preFilterMapData);
@@ -202,6 +202,44 @@ export declare const retractReaction: (post: PostWithMeta, profile: Profile) =>
202
202
  language?: string | undefined;
203
203
  image?: string | undefined;
204
204
  title?: string | undefined;
205
+ } | {
206
+ type: "resource";
207
+ title: string;
208
+ resourceKind: "link" | "file" | "video" | "gallery" | "audio";
209
+ content?: string | undefined;
210
+ sensitive?: boolean | undefined;
211
+ spoilerText?: string | undefined;
212
+ attachments?: {
213
+ type: string;
214
+ url: string;
215
+ previewUrl: string | null;
216
+ textUrl: null;
217
+ filename: string;
218
+ meta: {
219
+ usage?: string | undefined;
220
+ focus?: {
221
+ x: number;
222
+ y: number;
223
+ } | undefined;
224
+ mimetype?: string | undefined;
225
+ size?: number | undefined;
226
+ };
227
+ description?: string | undefined;
228
+ blurhash?: string | undefined;
229
+ status?: "failed" | "processing" | "ready" | undefined;
230
+ error?: string | undefined;
231
+ }[] | undefined;
232
+ customEmojis?: {
233
+ shortcode: string;
234
+ url: string;
235
+ staticUrl: string;
236
+ visibleInPicker: boolean;
237
+ category: string;
238
+ }[] | undefined;
239
+ language?: string | undefined;
240
+ tags?: string[] | undefined;
241
+ categoryPath?: string[] | undefined;
242
+ url?: string | undefined;
205
243
  };
206
244
  } | {
207
245
  type: "edit";
@@ -397,6 +435,44 @@ export declare const retractReaction: (post: PostWithMeta, profile: Profile) =>
397
435
  language?: string | undefined;
398
436
  image?: string | undefined;
399
437
  title?: string | undefined;
438
+ } | {
439
+ type: "resource";
440
+ title: string;
441
+ resourceKind: "link" | "file" | "video" | "gallery" | "audio";
442
+ content?: string | undefined;
443
+ sensitive?: boolean | undefined;
444
+ spoilerText?: string | undefined;
445
+ attachments?: {
446
+ type: string;
447
+ url: string;
448
+ previewUrl: string | null;
449
+ textUrl: null;
450
+ filename: string;
451
+ meta: {
452
+ usage?: string | undefined;
453
+ focus?: {
454
+ x: number;
455
+ y: number;
456
+ } | undefined;
457
+ mimetype?: string | undefined;
458
+ size?: number | undefined;
459
+ };
460
+ description?: string | undefined;
461
+ blurhash?: string | undefined;
462
+ status?: "failed" | "processing" | "ready" | undefined;
463
+ error?: string | undefined;
464
+ }[] | undefined;
465
+ customEmojis?: {
466
+ shortcode: string;
467
+ url: string;
468
+ staticUrl: string;
469
+ visibleInPicker: boolean;
470
+ category: string;
471
+ }[] | undefined;
472
+ language?: string | undefined;
473
+ tags?: string[] | undefined;
474
+ categoryPath?: string[] | undefined;
475
+ url?: string | undefined;
400
476
  };
401
477
  } | {
402
478
  type: "delete";
@@ -21,7 +21,6 @@ import { cancelPollEnd, schedulePollEnd } from './pollEndJobs.js';
21
21
  import { config } from '../config/index.js';
22
22
  import { localObjectScalars } from '../federation/identity.js';
23
23
  export const createPost = async (data, profile, postData, relations = {}) => {
24
- var _a, _b;
25
24
  if (data.type === 'event') {
26
25
  data = normalizeEventDataForSave(data);
27
26
  }
@@ -41,23 +40,30 @@ export const createPost = async (data, profile, postData, relations = {}) => {
41
40
  }
42
41
  const audienceIds = [
43
42
  profile.id,
44
- ...((_a = relations.audience) !== null && _a !== void 0 ? _a : []).map((member) => member.id),
43
+ ...(relations.audience ?? []).map((member) => member.id),
45
44
  ];
46
45
  if (await hasBlockAmong(db, audienceIds)) {
47
46
  throw forbidden({ errorKey: 'error.cannotInteractBlocked' });
48
47
  }
49
- const group = await ((repliedToPost === null || repliedToPost === void 0 ? void 0 : repliedToPost.group) ||
48
+ const group = await (repliedToPost?.group ||
50
49
  (relations.groupId ? findGroup(relations.groupId) : undefined));
51
50
  // Group-linked posts always use visibility=group so community/local feeds
52
51
  // (which only include public/local) never surface them incorrectly.
53
52
  if (group) {
54
- postData = Object.assign(Object.assign({}, postData), { visibility: 'group' });
53
+ postData = { ...postData, visibility: 'group' };
55
54
  }
56
55
  const hashtags = extractHashtags(data);
57
56
  const id = uuidv7();
58
57
  const domain = (await config()).activityPub.defaultDomain;
59
58
  const object = localObjectScalars(id, domain, relations.inReplyToId);
60
- const post = await postsMapping.removeDefaultFilter().create(db, Object.assign(Object.assign(Object.assign({ id }, postData), object), { data, type: data.type, creatorId: profile.id }));
59
+ const post = await postsMapping.removeDefaultFilter().create(db, {
60
+ id,
61
+ ...postData,
62
+ ...object,
63
+ data,
64
+ type: data.type,
65
+ creatorId: profile.id,
66
+ });
61
67
  await entryConnector(db, profile, post, {
62
68
  type: 'create',
63
69
  data,
@@ -80,10 +86,10 @@ export const createPost = async (data, profile, postData, relations = {}) => {
80
86
  if (mentions.length) {
81
87
  await Promise.all(mentions.map(async (mention) => mentionConnector(db, post, mention.profile, { text: mention.text })));
82
88
  }
83
- const audienceToLink = ((_b = relations.audience) === null || _b === void 0 ? void 0 : _b.length)
89
+ const audienceToLink = relations.audience?.length
84
90
  ? relations.audience
85
- : repliedToPost === null || repliedToPost === void 0 ? void 0 : repliedToPost.audience;
86
- if (audienceToLink === null || audienceToLink === void 0 ? void 0 : audienceToLink.length) {
91
+ : repliedToPost?.audience;
92
+ if (audienceToLink?.length) {
87
93
  await Promise.all(audienceToLink.map(async (member) => {
88
94
  await audienceConnector(db, post, member);
89
95
  }));
@@ -100,8 +106,7 @@ export const createPost = async (data, profile, postData, relations = {}) => {
100
106
  return transformedPost;
101
107
  };
102
108
  export const updatePost = async (post, profile, data) => {
103
- var _a;
104
- const previousEvent = ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' ? post.data : undefined;
109
+ const previousEvent = post.data?.type === 'event' ? post.data : undefined;
105
110
  const normalized = data.type === 'event' ? normalizeEventDataForSave(data) : data;
106
111
  const dataForDb = normalized.type === 'event'
107
112
  ? eventDataForDbUpdate(previousEvent, normalized)
@@ -140,7 +145,10 @@ export const reactToPost = async (post, profile, data) => allpeepDb().then(({ db
140
145
  data: { reaction: data.reaction },
141
146
  })
142
147
  .then(() => bumpConversationActivity(db, post.id))
143
- .then(() => hub.emit('reactionCreated', profile, post, Object.assign({ type: 'reaction' }, data))));
148
+ .then(() => hub.emit('reactionCreated', profile, post, {
149
+ type: 'reaction',
150
+ ...data,
151
+ })));
144
152
  export const retractReaction = async (post, profile) => allpeepDb().then(({ db }) => entryConnector(db, profile, post, {
145
153
  type: 'unreaction',
146
154
  data: { reaction: AP_LIKE_REACTION },
@@ -178,7 +186,10 @@ export const deletePost = async (post, profile) => {
178
186
  type: 'tombstone',
179
187
  },
180
188
  });
181
- await postsMapping.deleteRelations(db, post.id, Object.assign(Object.assign({}, repostRelation), { direction: 'INBOUND' }));
189
+ await postsMapping.deleteRelations(db, post.id, {
190
+ ...repostRelation,
191
+ direction: 'INBOUND',
192
+ });
182
193
  await postsMapping.delete(db, post.id);
183
194
  if (post.type === 'event') {
184
195
  await clearEventOccurrences(post.id);
@@ -194,19 +205,17 @@ export const vote = (profile, post, data) => allpeepDb().then(({ db }) => entryC
194
205
  }).then(() => hub.emit('entryCreated', profile, post, { type: 'answer', data })));
195
206
  const attendingRsvp = (response) => response === 'yes' || response === 'tentative';
196
207
  const rsvpOccurrenceIds = (data) => {
197
- var _a;
198
- if ((_a = data.recurrenceIds) === null || _a === void 0 ? void 0 : _a.length)
208
+ if (data.recurrenceIds?.length)
199
209
  return data.recurrenceIds;
200
210
  if (data.recurrenceId)
201
211
  return [data.recurrenceId];
202
212
  return undefined;
203
213
  };
204
214
  export const rsvpRespond = async (profile, post, data) => {
205
- var _a, _b, _c, _d;
206
215
  if (profile.id === post.profile.id) {
207
216
  return;
208
217
  }
209
- if (post.type !== 'event' || ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) !== 'event') {
218
+ if (post.type !== 'event' || post.data?.type !== 'event') {
210
219
  throw unprocessableRequest({ errorKey: 'error.unprocessableRequest' });
211
220
  }
212
221
  // `removed` is an organizer-only status; users cannot set it on themselves,
@@ -215,7 +224,7 @@ export const rsvpRespond = async (profile, post, data) => {
215
224
  if (data.response === 'removed') {
216
225
  throw forbidden({ errorKey: 'error.rsvpRemovedForbidden' });
217
226
  }
218
- if (((_b = getEffectiveRsvp(post, profile.id)) === null || _b === void 0 ? void 0 : _b.response) === 'removed') {
227
+ if (getEffectiveRsvp(post, profile.id)?.response === 'removed') {
219
228
  throw forbidden({ errorKey: 'error.rsvpRemoved' });
220
229
  }
221
230
  const occurrenceIds = rsvpOccurrenceIds(data);
@@ -233,10 +242,10 @@ export const rsvpRespond = async (profile, post, data) => {
233
242
  }
234
243
  }
235
244
  else {
236
- const ids = occurrenceIds !== null && occurrenceIds !== void 0 ? occurrenceIds : [undefined];
245
+ const ids = occurrenceIds ?? [undefined];
237
246
  for (const recurrenceId of ids) {
238
247
  const currentRsvp = getEffectiveRsvp(post, profile.id, recurrenceId);
239
- if ((currentRsvp === null || currentRsvp === void 0 ? void 0 : currentRsvp.response) !== 'yes' &&
248
+ if (currentRsvp?.response !== 'yes' &&
240
249
  countYesRsvps(post, recurrenceId) >= maxAttendees) {
241
250
  throw unprocessableRequest({ errorKey: 'error.eventAtCapacity' });
242
251
  }
@@ -246,16 +255,16 @@ export const rsvpRespond = async (profile, post, data) => {
246
255
  }
247
256
  const { db } = await allpeepDb();
248
257
  const previousResponses = occurrenceIds
249
- ? occurrenceIds.map((id) => { var _a; return (_a = getEffectiveRsvp(post, profile.id, id)) === null || _a === void 0 ? void 0 : _a.response; })
258
+ ? occurrenceIds.map((id) => getEffectiveRsvp(post, profile.id, id)?.response)
250
259
  : undefined;
251
260
  const previousResponse = previousResponses
252
261
  ? previousResponses.every(attendingRsvp)
253
262
  ? previousResponses[0]
254
263
  : previousResponses.find((response) => !attendingRsvp(response))
255
- : (_d = [...((_c = post.rsvps) !== null && _c !== void 0 ? _c : [])]
264
+ : [...(post.rsvps ?? [])]
256
265
  .filter((rsvp) => rsvp.profile.id === profile.id)
257
266
  .filter((rsvp) => !rsvp.recurrenceId)
258
- .sort((a, b) => (a.createdAt < b.createdAt ? 1 : -1))[0]) === null || _d === void 0 ? void 0 : _d.response;
267
+ .sort((a, b) => (a.createdAt < b.createdAt ? 1 : -1))[0]?.response;
259
268
  const writes = occurrenceIds
260
269
  ? occurrenceIds.map((recurrenceId) => ({
261
270
  response: data.response,
@@ -269,13 +278,20 @@ export const rsvpRespond = async (profile, post, data) => {
269
278
  });
270
279
  }
271
280
  const cancel = rsvpCancelNotice(post, profile.id, data.response, occurrenceIds);
272
- hub.emit('rsvpCreated', profile, post, Object.assign({ type: 'rsvp', data: Object.assign({ response: data.response }, ((occurrenceIds === null || occurrenceIds === void 0 ? void 0 : occurrenceIds.length) === 1
273
- ? { recurrenceId: occurrenceIds[0] }
274
- : {})), occurrenceIds,
275
- previousResponse }, (cancel ? { cancel } : {})));
281
+ hub.emit('rsvpCreated', profile, post, {
282
+ type: 'rsvp',
283
+ data: {
284
+ response: data.response,
285
+ ...(occurrenceIds?.length === 1
286
+ ? { recurrenceId: occurrenceIds[0] }
287
+ : {}),
288
+ },
289
+ occurrenceIds,
290
+ previousResponse,
291
+ ...(cancel ? { cancel } : {}),
292
+ });
276
293
  };
277
294
  export const rsvpManageByOrganizer = async (actingProfile, targetProfile, post, response, recurrenceId) => {
278
- var _a, _b;
279
295
  if (!canManageEventRsvps(actingProfile, post)) {
280
296
  throw forbidden({ errorKey: 'forbidden' });
281
297
  }
@@ -287,13 +303,13 @@ export const rsvpManageByOrganizer = async (actingProfile, targetProfile, post,
287
303
  }
288
304
  const data = { response, recurrenceId };
289
305
  const { db } = await allpeepDb();
290
- const previousResponse = (_b = [...((_a = post.rsvps) !== null && _a !== void 0 ? _a : [])]
306
+ const previousResponse = [...(post.rsvps ?? [])]
291
307
  .filter((rsvp) => rsvp.profile.id === targetProfile.id)
292
308
  .filter((rsvp) => recurrenceId
293
309
  ? sameRecurrenceId(rsvp.recurrenceId, recurrenceId) ||
294
310
  !rsvp.recurrenceId
295
311
  : !rsvp.recurrenceId)
296
- .sort((a, b) => (a.createdAt < b.createdAt ? 1 : -1))[0]) === null || _b === void 0 ? void 0 : _b.response;
312
+ .sort((a, b) => (a.createdAt < b.createdAt ? 1 : -1))[0]?.response;
297
313
  await entryConnector(db, targetProfile, post, {
298
314
  type: 'rsvp',
299
315
  data,
@@ -322,7 +338,6 @@ export const rsvpManageByOrganizer = async (actingProfile, targetProfile, post,
322
338
  * tab, detected by posts they authored but are not in.
323
339
  */
324
340
  export const leaveConversation = async (rootPost, profile) => {
325
- var _a, _b;
326
341
  const { db } = await allpeepDb();
327
342
  const lastPostId = await findLatestThreadPostId(rootPost.id);
328
343
  const [lastPost] = lastPostId === rootPost.id
@@ -330,7 +345,7 @@ export const leaveConversation = async (rootPost, profile) => {
330
345
  : await findPostsForAuth([lastPostId]);
331
346
  if (!lastPost)
332
347
  return;
333
- const remainingAudience = (_b = (_a = lastPost.audience) === null || _a === void 0 ? void 0 : _a.filter((p) => p.id !== profile.id)) !== null && _b !== void 0 ? _b : [];
348
+ const remainingAudience = lastPost.audience?.filter((p) => p.id !== profile.id) ?? [];
334
349
  if (remainingAudience.length > 0) {
335
350
  await createPost({ type: 'note', content: '' }, profile, { type: 'note', visibility: 'direct', creatorId: profile.id }, {
336
351
  inReplyToId: lastPost.id,
@@ -1,7 +1,4 @@
1
1
  export const pollEndDelayMs = (expiresAt, now = Date.now()) => new Date(expiresAt).getTime() - now;
2
- export const shouldEmitPollEnded = (post, scheduledExpiresAt) => {
3
- var _a;
4
- return !!post &&
5
- ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'question' &&
6
- post.data.expiresAt === scheduledExpiresAt;
7
- };
2
+ export const shouldEmitPollEnded = (post, scheduledExpiresAt) => !!post &&
3
+ post.data?.type === 'question' &&
4
+ post.data.expiresAt === scheduledExpiresAt;
@@ -14,14 +14,13 @@ const attendingResponses = ['yes', 'tentative'];
14
14
  * avoid re-sending when someone toggles between yes/maybe.
15
15
  */
16
16
  const handleRsvpCreated = async (profileArg, postArg, payloadArg) => {
17
- var _a, _b, _c;
18
17
  const profile = profileArg;
19
18
  const post = postArg;
20
19
  const payload = payloadArg;
21
- if ((payload === null || payload === void 0 ? void 0 : payload.type) !== 'rsvp') {
20
+ if (payload?.type !== 'rsvp') {
22
21
  return;
23
22
  }
24
- const response = (_a = payload.data) === null || _a === void 0 ? void 0 : _a.response;
23
+ const response = payload.data?.response;
25
24
  if (!response || !attendingResponses.includes(response)) {
26
25
  return;
27
26
  }
@@ -29,12 +28,13 @@ const handleRsvpCreated = async (profileArg, postArg, payloadArg) => {
29
28
  attendingResponses.includes(payload.previousResponse)) {
30
29
  return;
31
30
  }
32
- if (post.type !== 'event' || ((_b = post.data) === null || _b === void 0 ? void 0 : _b.type) !== 'event') {
31
+ if (post.type !== 'event' || post.data?.type !== 'event') {
33
32
  return;
34
33
  }
35
34
  const rootUrl = await serverRootUrl();
36
35
  const postUrl = `${rootUrl}/posts/${post.id}`;
37
- const occurrenceIds = (_c = payload.occurrenceIds) !== null && _c !== void 0 ? _c : (payload.data.recurrenceId ? [payload.data.recurrenceId] : undefined);
36
+ const occurrenceIds = payload.occurrenceIds ??
37
+ (payload.data.recurrenceId ? [payload.data.recurrenceId] : undefined);
38
38
  const confirmation = rsvpConfirmationContent(post, {
39
39
  postUrl,
40
40
  occurrenceIds,
@@ -56,9 +56,19 @@ const handleRsvpCreated = async (profileArg, postArg, payloadArg) => {
56
56
  .send({
57
57
  to: account.email,
58
58
  template: 'eventRsvpConfirmation',
59
- locals: Object.assign({ eventName: confirmation.eventName, eventUrl: postUrl, response, start: confirmation.start, end: confirmation.end, location: confirmation.location, allDay: confirmation.allDay, occurrenceCount: confirmation.occurrenceCount }, ((profileSettings === null || profileSettings === void 0 ? void 0 : profileSettings.timeZone)
60
- ? { timeZone: profileSettings.timeZone }
61
- : {})),
59
+ locals: {
60
+ eventName: confirmation.eventName,
61
+ eventUrl: postUrl,
62
+ response,
63
+ start: confirmation.start,
64
+ end: confirmation.end,
65
+ location: confirmation.location,
66
+ allDay: confirmation.allDay,
67
+ occurrenceCount: confirmation.occurrenceCount,
68
+ ...(profileSettings?.timeZone
69
+ ? { timeZone: profileSettings.timeZone }
70
+ : {}),
71
+ },
62
72
  attachments: [
63
73
  {
64
74
  filename: 'event.ics',
@@ -38,7 +38,7 @@ export const loadThreadPreviewReplies = async (rootId, currentProfile) => {
38
38
  if (!parentId || parentId === rootId)
39
39
  return post;
40
40
  const parent = byId.get(parentId);
41
- return parent ? Object.assign(Object.assign({}, post), { replyTo: parent }) : post;
41
+ return parent ? { ...post, replyTo: parent } : post;
42
42
  });
43
43
  return { replies, hasMore };
44
44
  };
@@ -3,12 +3,12 @@ import { allpeepDb } from '../db/index.js';
3
3
  import { sorts } from '../db/pg/queries/index.js';
4
4
  const HISTORY_SAMPLE_SIZE = 50;
5
5
  const FILETYPE_DEFAULTS_MS = {
6
- image: 2000,
7
- audio: 8000,
8
- video: 30000,
9
- document: 1500,
6
+ image: 2_000,
7
+ audio: 8_000,
8
+ video: 30_000,
9
+ document: 1_500,
10
10
  };
11
- const GENERIC_DEFAULT_MS = 5000;
11
+ const GENERIC_DEFAULT_MS = 5_000;
12
12
  const median = (values) => {
13
13
  if (!values.length)
14
14
  return 0;
@@ -27,7 +27,6 @@ const findRecent = async (filter) => {
27
27
  .all(db);
28
28
  };
29
29
  export const estimateProcessingDuration = async ({ filetype, filesize, }) => {
30
- var _a;
31
30
  const lower = filesize * 0.5;
32
31
  const upper = filesize * 2;
33
32
  const sized = await findRecent({ filetype })
@@ -42,5 +41,5 @@ export const estimateProcessingDuration = async ({ filetype, filesize, }) => {
42
41
  if (scaledMedian > 0)
43
42
  return scaledMedian;
44
43
  }
45
- return (_a = FILETYPE_DEFAULTS_MS[filetype]) !== null && _a !== void 0 ? _a : GENERIC_DEFAULT_MS;
44
+ return FILETYPE_DEFAULTS_MS[filetype] ?? GENERIC_DEFAULT_MS;
46
45
  };
@@ -12,9 +12,8 @@ hub.on('profileSettingsUpdated', (profileId) => {
12
12
  void profileSettingsCache.del(profileId);
13
13
  });
14
14
  const uniqueViolation = (error) => {
15
- var _a;
16
15
  const current = error;
17
- return current.code === '23505' || ((_a = current.cause) === null || _a === void 0 ? void 0 : _a.code) === '23505';
16
+ return current.code === '23505' || current.cause?.code === '23505';
18
17
  };
19
18
  const readProfileSettings = async (db, id) =>
20
19
  // Include soft-deleted rows: the profile_id unique index still covers them,
@@ -8,7 +8,7 @@ import { listBlockedByIds } from './blocks.js';
8
8
  import { findProfile } from './finders.js';
9
9
  import { listReportsByReportedProfile } from '../reports/finders.js';
10
10
  import { profileActivityCountsSql, profileTopPostScoresSql, takeTopReadablePosts, } from './activityQueries.js';
11
- const sqlRows = (result) => { var _a; return (_a = result.rows) !== null && _a !== void 0 ? _a : []; };
11
+ const sqlRows = (result) => result.rows ?? [];
12
12
  const loadPostsByIds = async (db, ids, authData) => {
13
13
  if (ids.length === 0)
14
14
  return [];
@@ -24,46 +24,41 @@ const loadPostsByIds = async (db, ids, authData) => {
24
24
  .filter((post) => !!post);
25
25
  };
26
26
  export const getProfileActivitySummary = async (authData, profileId) => {
27
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
28
27
  const { db } = await allpeepDb();
29
28
  const [countRow] = sqlRows(await db.execute(profileActivityCountsSql(profileId)));
30
29
  const scored = sqlRows(await db.execute(profileTopPostScoresSql(profileId)))
31
- .map((row) => {
32
- var _a, _b;
33
- return ({
34
- id: String((_a = row.id) !== null && _a !== void 0 ? _a : ''),
35
- activityScore: Number((_b = row.activity_score) !== null && _b !== void 0 ? _b : 0),
36
- });
37
- })
30
+ .map((row) => ({
31
+ id: String(row.id ?? ''),
32
+ activityScore: Number(row.activity_score ?? 0),
33
+ }))
38
34
  .filter((row) => row.id);
39
35
  const scoreById = new Map(scored.map((row) => [row.id, row.activityScore]));
40
36
  const loaded = await loadPostsByIds(db, scored.map((row) => row.id), authData);
41
37
  const config = await capabilitiesConfig();
42
38
  const readable = canReadPost(config, authData);
43
39
  const topPosts = takeTopReadablePosts(loaded, readable)
44
- .map((post) => {
45
- var _a;
46
- return publicPostWithActivityScoreSchema.safeParse(Object.assign(Object.assign({}, post), { activityScore: (_a = scoreById.get(post.id)) !== null && _a !== void 0 ? _a : 0 }));
47
- })
40
+ .map((post) => publicPostWithActivityScoreSchema.safeParse({
41
+ ...post,
42
+ activityScore: scoreById.get(post.id) ?? 0,
43
+ }))
48
44
  .filter((result) => result.success)
49
45
  .map((result) => result.data);
50
46
  return profileActivitySummarySchema.parse({
51
- postsCount: Number((_a = countRow === null || countRow === void 0 ? void 0 : countRow.posts_count) !== null && _a !== void 0 ? _a : 0),
52
- repliesCount: Number((_b = countRow === null || countRow === void 0 ? void 0 : countRow.replies_count) !== null && _b !== void 0 ? _b : 0),
53
- eventsCount: Number((_c = countRow === null || countRow === void 0 ? void 0 : countRow.events_count) !== null && _c !== void 0 ? _c : 0),
54
- reactionsGiven: Number((_d = countRow === null || countRow === void 0 ? void 0 : countRow.reactions_given) !== null && _d !== void 0 ? _d : 0),
55
- reactionsReceived: Number((_e = countRow === null || countRow === void 0 ? void 0 : countRow.reactions_received) !== null && _e !== void 0 ? _e : 0),
56
- repostsCount: Number((_f = countRow === null || countRow === void 0 ? void 0 : countRow.reposts_count) !== null && _f !== void 0 ? _f : 0),
57
- repostsReceived: Number((_g = countRow === null || countRow === void 0 ? void 0 : countRow.reposts_received) !== null && _g !== void 0 ? _g : 0),
58
- repliesReceived: Number((_h = countRow === null || countRow === void 0 ? void 0 : countRow.replies_received) !== null && _h !== void 0 ? _h : 0),
59
- rsvpsCount: Number((_j = countRow === null || countRow === void 0 ? void 0 : countRow.rsvps_count) !== null && _j !== void 0 ? _j : 0),
60
- bookmarksCount: Number((_k = countRow === null || countRow === void 0 ? void 0 : countRow.bookmarks_count) !== null && _k !== void 0 ? _k : 0),
61
- groupsCount: Number((_l = countRow === null || countRow === void 0 ? void 0 : countRow.groups_count) !== null && _l !== void 0 ? _l : 0),
47
+ postsCount: Number(countRow?.posts_count ?? 0),
48
+ repliesCount: Number(countRow?.replies_count ?? 0),
49
+ eventsCount: Number(countRow?.events_count ?? 0),
50
+ reactionsGiven: Number(countRow?.reactions_given ?? 0),
51
+ reactionsReceived: Number(countRow?.reactions_received ?? 0),
52
+ repostsCount: Number(countRow?.reposts_count ?? 0),
53
+ repostsReceived: Number(countRow?.reposts_received ?? 0),
54
+ repliesReceived: Number(countRow?.replies_received ?? 0),
55
+ rsvpsCount: Number(countRow?.rsvps_count ?? 0),
56
+ bookmarksCount: Number(countRow?.bookmarks_count ?? 0),
57
+ groupsCount: Number(countRow?.groups_count ?? 0),
62
58
  topPosts,
63
59
  });
64
60
  };
65
61
  export const getAdminProfileSummary = async (authData, profileId) => {
66
- var _a, _b, _c, _d, _e, _f;
67
62
  const profile = await findProfile(profileId);
68
63
  if (!profile) {
69
64
  throw new Error(`Profile with id ${profileId} not found`);
@@ -78,9 +73,9 @@ export const getAdminProfileSummary = async (authData, profileId) => {
78
73
  profile: publicProfileSchema.parse(profile),
79
74
  activity,
80
75
  createdAt: profile.createdAt,
81
- email: (_b = (_a = profile.controllers) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.email,
82
- followersCount: (_d = (_c = profile.profileStats) === null || _c === void 0 ? void 0 : _c.followersCount) !== null && _d !== void 0 ? _d : 0,
83
- followingCount: (_f = (_e = profile.profileStats) === null || _e === void 0 ? void 0 : _e.followingCount) !== null && _f !== void 0 ? _f : 0,
76
+ email: profile.controllers?.[0]?.email,
77
+ followersCount: profile.profileStats?.followersCount ?? 0,
78
+ followingCount: profile.profileStats?.followingCount ?? 0,
84
79
  reportsCount: reports.length,
85
80
  blockedByCount: blockedByIds.length,
86
81
  });