@openpeepshq/common 0.10.0 → 0.12.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.
@@ -957,6 +957,12 @@ export type MentionWithProfile = z.infer<typeof mentionWithProfileSchema>;
957
957
  declare const reactionWithProfileSchema: z.ZodObject<{
958
958
  reaction: z.ZodEnum<{
959
959
  "\uD83D\uDC4D": "👍";
960
+ "\uD83D\uDC4E": "👎";
961
+ "\u2764\uFE0F": "❤️";
962
+ "\uD83D\uDE02": "😂";
963
+ "\uD83D\uDE2E": "😮";
964
+ "\uD83D\uDE22": "😢";
965
+ "\uD83C\uDF89": "🎉";
960
966
  }>;
961
967
  profile: z.ZodObject<{
962
968
  handle: z.ZodString;
@@ -9158,6 +9164,12 @@ declare const basePostSchema: z.ZodObject<{
9158
9164
  reactions: z.ZodArray<z.ZodObject<{
9159
9165
  reaction: z.ZodEnum<{
9160
9166
  "\uD83D\uDC4D": "👍";
9167
+ "\uD83D\uDC4E": "👎";
9168
+ "\u2764\uFE0F": "❤️";
9169
+ "\uD83D\uDE02": "😂";
9170
+ "\uD83D\uDE2E": "😮";
9171
+ "\uD83D\uDE22": "😢";
9172
+ "\uD83C\uDF89": "🎉";
9161
9173
  }>;
9162
9174
  profile: z.ZodObject<{
9163
9175
  handle: z.ZodString;
@@ -12876,6 +12888,12 @@ export declare const postWithMetaSchema: z.ZodObject<{
12876
12888
  reactions: z.ZodArray<z.ZodObject<{
12877
12889
  reaction: z.ZodEnum<{
12878
12890
  "\uD83D\uDC4D": "👍";
12891
+ "\uD83D\uDC4E": "👎";
12892
+ "\u2764\uFE0F": "❤️";
12893
+ "\uD83D\uDE02": "😂";
12894
+ "\uD83D\uDE2E": "😮";
12895
+ "\uD83D\uDE22": "😢";
12896
+ "\uD83C\uDF89": "🎉";
12879
12897
  }>;
12880
12898
  profile: z.ZodObject<{
12881
12899
  handle: z.ZodString;
@@ -19256,6 +19274,12 @@ export declare const postWithMetaSchema: z.ZodObject<{
19256
19274
  reactions: z.ZodArray<z.ZodObject<{
19257
19275
  reaction: z.ZodEnum<{
19258
19276
  "\uD83D\uDC4D": "👍";
19277
+ "\uD83D\uDC4E": "👎";
19278
+ "\u2764\uFE0F": "❤️";
19279
+ "\uD83D\uDE02": "😂";
19280
+ "\uD83D\uDE2E": "😮";
19281
+ "\uD83D\uDE22": "😢";
19282
+ "\uD83C\uDF89": "🎉";
19259
19283
  }>;
19260
19284
  profile: z.ZodObject<{
19261
19285
  handle: z.ZodString;
@@ -23523,6 +23547,12 @@ export declare const expandedNotificationSchema: z.ZodObject<{
23523
23547
  reactions: z.ZodArray<z.ZodObject<{
23524
23548
  reaction: z.ZodEnum<{
23525
23549
  "\uD83D\uDC4D": "👍";
23550
+ "\uD83D\uDC4E": "👎";
23551
+ "\u2764\uFE0F": "❤️";
23552
+ "\uD83D\uDE02": "😂";
23553
+ "\uD83D\uDE2E": "😮";
23554
+ "\uD83D\uDE22": "😢";
23555
+ "\uD83C\uDF89": "🎉";
23526
23556
  }>;
23527
23557
  profile: z.ZodObject<{
23528
23558
  handle: z.ZodString;
@@ -29903,6 +29933,12 @@ export declare const expandedNotificationSchema: z.ZodObject<{
29903
29933
  reactions: z.ZodArray<z.ZodObject<{
29904
29934
  reaction: z.ZodEnum<{
29905
29935
  "\uD83D\uDC4D": "👍";
29936
+ "\uD83D\uDC4E": "👎";
29937
+ "\u2764\uFE0F": "❤️";
29938
+ "\uD83D\uDE02": "😂";
29939
+ "\uD83D\uDE2E": "😮";
29940
+ "\uD83D\uDE22": "😢";
29941
+ "\uD83C\uDF89": "🎉";
29906
29942
  }>;
29907
29943
  profile: z.ZodObject<{
29908
29944
  handle: z.ZodString;
@@ -34942,6 +34978,12 @@ export declare const reportWithMetaSchema: z.ZodObject<{
34942
34978
  reactions: z.ZodArray<z.ZodObject<{
34943
34979
  reaction: z.ZodEnum<{
34944
34980
  "\uD83D\uDC4D": "👍";
34981
+ "\uD83D\uDC4E": "👎";
34982
+ "\u2764\uFE0F": "❤️";
34983
+ "\uD83D\uDE02": "😂";
34984
+ "\uD83D\uDE2E": "😮";
34985
+ "\uD83D\uDE22": "😢";
34986
+ "\uD83C\uDF89": "🎉";
34945
34987
  }>;
34946
34988
  profile: z.ZodObject<{
34947
34989
  handle: z.ZodString;
@@ -41322,6 +41364,12 @@ export declare const reportWithMetaSchema: z.ZodObject<{
41322
41364
  reactions: z.ZodArray<z.ZodObject<{
41323
41365
  reaction: z.ZodEnum<{
41324
41366
  "\uD83D\uDC4D": "👍";
41367
+ "\uD83D\uDC4E": "👎";
41368
+ "\u2764\uFE0F": "❤️";
41369
+ "\uD83D\uDE02": "😂";
41370
+ "\uD83D\uDE2E": "😮";
41371
+ "\uD83D\uDE22": "😢";
41372
+ "\uD83C\uDF89": "🎉";
41325
41373
  }>;
41326
41374
  profile: z.ZodObject<{
41327
41375
  handle: z.ZodString;
@@ -45338,6 +45386,12 @@ export declare const jamRecordingWithMetaSchema: z.ZodObject<{
45338
45386
  reactions: z.ZodArray<z.ZodObject<{
45339
45387
  reaction: z.ZodEnum<{
45340
45388
  "\uD83D\uDC4D": "👍";
45389
+ "\uD83D\uDC4E": "👎";
45390
+ "\u2764\uFE0F": "❤️";
45391
+ "\uD83D\uDE02": "😂";
45392
+ "\uD83D\uDE2E": "😮";
45393
+ "\uD83D\uDE22": "😢";
45394
+ "\uD83C\uDF89": "🎉";
45341
45395
  }>;
45342
45396
  profile: z.ZodObject<{
45343
45397
  handle: z.ZodString;
@@ -51718,6 +51772,12 @@ export declare const jamRecordingWithMetaSchema: z.ZodObject<{
51718
51772
  reactions: z.ZodArray<z.ZodObject<{
51719
51773
  reaction: z.ZodEnum<{
51720
51774
  "\uD83D\uDC4D": "👍";
51775
+ "\uD83D\uDC4E": "👎";
51776
+ "\u2764\uFE0F": "❤️";
51777
+ "\uD83D\uDE02": "😂";
51778
+ "\uD83D\uDE2E": "😮";
51779
+ "\uD83D\uDE22": "😢";
51780
+ "\uD83C\uDF89": "🎉";
51721
51781
  }>;
51722
51782
  profile: z.ZodObject<{
51723
51783
  handle: z.ZodString;
@@ -161,6 +161,7 @@ export declare const profileSettingsDataSchema: z.ZodObject<{
161
161
  push: z.ZodBoolean;
162
162
  email: z.ZodBoolean;
163
163
  }, z.core.$strip>>>;
164
+ hiddenNotificationTypes: z.ZodOptional<z.ZodArray<z.ZodString>>;
164
165
  groupNotificationLevels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodEnum<{
165
166
  all: "all";
166
167
  mostRelevant: "mostRelevant";
@@ -217,6 +218,7 @@ export declare const profileSettingsSchema: z.ZodObject<{
217
218
  push: z.ZodBoolean;
218
219
  email: z.ZodBoolean;
219
220
  }, z.core.$strip>>>;
221
+ hiddenNotificationTypes: z.ZodOptional<z.ZodArray<z.ZodString>>;
220
222
  groupNotificationLevels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodEnum<{
221
223
  all: "all";
222
224
  mostRelevant: "mostRelevant";
@@ -3390,12 +3392,29 @@ export declare const pushSubscriptionSchema: z.ZodDiscriminatedUnion<[z.ZodObjec
3390
3392
  deletedAt: z.ZodOptional<z.ZodNullable<z.ZodISODateTime>>;
3391
3393
  }, z.core.$strip>], "type">;
3392
3394
  export type PushSubscription = z.infer<typeof pushSubscriptionSchema>;
3395
+ /**
3396
+ * Reactions users can attach to a post. Single source of truth for the
3397
+ * picker UI and the API schema.
3398
+ */
3399
+ export declare const REACTION_TYPES: readonly ["👍", "👎", "❤️", "😂", "😮", "😢", "🎉"];
3393
3400
  export declare const reactionTypeSchema: z.ZodEnum<{
3394
3401
  "\uD83D\uDC4D": "👍";
3402
+ "\uD83D\uDC4E": "👎";
3403
+ "\u2764\uFE0F": "❤️";
3404
+ "\uD83D\uDE02": "😂";
3405
+ "\uD83D\uDE2E": "😮";
3406
+ "\uD83D\uDE22": "😢";
3407
+ "\uD83C\uDF89": "🎉";
3395
3408
  }>;
3396
3409
  export declare const reactionDataSchema: z.ZodObject<{
3397
3410
  reaction: z.ZodEnum<{
3398
3411
  "\uD83D\uDC4D": "👍";
3412
+ "\uD83D\uDC4E": "👎";
3413
+ "\u2764\uFE0F": "❤️";
3414
+ "\uD83D\uDE02": "😂";
3415
+ "\uD83D\uDE2E": "😮";
3416
+ "\uD83D\uDE22": "😢";
3417
+ "\uD83C\uDF89": "🎉";
3399
3418
  }>;
3400
3419
  }, z.core.$strip>;
3401
3420
  export type ReactionData = z.infer<typeof reactionDataSchema>;
@@ -3487,6 +3506,12 @@ export declare const jamEventDataSchema: z.ZodObject<{
3487
3506
  content: z.ZodOptional<z.ZodString>;
3488
3507
  reaction: z.ZodOptional<z.ZodEnum<{
3489
3508
  "\uD83D\uDC4D": "👍";
3509
+ "\uD83D\uDC4E": "👎";
3510
+ "\u2764\uFE0F": "❤️";
3511
+ "\uD83D\uDE02": "😂";
3512
+ "\uD83D\uDE2E": "😮";
3513
+ "\uD83D\uDE22": "😢";
3514
+ "\uD83C\uDF89": "🎉";
3490
3515
  }>>;
3491
3516
  recurrenceId: z.ZodOptional<z.ZodISODateTime>;
3492
3517
  }, z.core.$strip>;
@@ -3509,6 +3534,12 @@ export declare const jamEventSchema: z.ZodObject<{
3509
3534
  content: z.ZodOptional<z.ZodString>;
3510
3535
  reaction: z.ZodOptional<z.ZodEnum<{
3511
3536
  "\uD83D\uDC4D": "👍";
3537
+ "\uD83D\uDC4E": "👎";
3538
+ "\u2764\uFE0F": "❤️";
3539
+ "\uD83D\uDE02": "😂";
3540
+ "\uD83D\uDE2E": "😮";
3541
+ "\uD83D\uDE22": "😢";
3542
+ "\uD83C\uDF89": "🎉";
3512
3543
  }>>;
3513
3544
  recurrenceId: z.ZodOptional<z.ZodISODateTime>;
3514
3545
  id: z.ZodUUID;
@@ -109,6 +109,8 @@ export const profileSettingsDataSchema = z.object({
109
109
  theme: ThemeOptionsSchema.optional(),
110
110
  defaults: profileSettingsDefaultsSchema.optional(),
111
111
  notifications: z.record(z.string(), profileNotificationSettings).optional(),
112
+ /** Notification types hidden from the feed (display only; creation is unaffected). */
113
+ hiddenNotificationTypes: z.string().array().optional(),
112
114
  /** Per-group level. A missing group id means all activity for that group. */
113
115
  groupNotificationLevels: z
114
116
  .record(z.string(), groupNotificationLevelSchema)
@@ -662,7 +664,20 @@ export const pushSubscriptionSchema = z.discriminatedUnion('type', [
662
664
  modelSchema(pushSubscriptionFcmDataSchema),
663
665
  modelSchema(pushSubscriptionWebhookDataSchema),
664
666
  ]);
665
- export const reactionTypeSchema = z.enum(['👍']);
667
+ /**
668
+ * Reactions users can attach to a post. Single source of truth for the
669
+ * picker UI and the API schema.
670
+ */
671
+ export const REACTION_TYPES = [
672
+ '👍',
673
+ '👎',
674
+ '❤️',
675
+ '😂',
676
+ '😮',
677
+ '😢',
678
+ '🎉',
679
+ ];
680
+ export const reactionTypeSchema = z.enum(REACTION_TYPES);
666
681
  export const reactionDataSchema = z.object({
667
682
  reaction: reactionTypeSchema,
668
683
  });
@@ -1740,6 +1740,12 @@ export declare const publicPostWithActivityScoreSchema: z.ZodObject<{
1740
1740
  reactions: z.ZodArray<z.ZodObject<{
1741
1741
  reaction: z.ZodEnum<{
1742
1742
  "\uD83D\uDC4D": "👍";
1743
+ "\uD83D\uDC4E": "👎";
1744
+ "\u2764\uFE0F": "❤️";
1745
+ "\uD83D\uDE02": "😂";
1746
+ "\uD83D\uDE2E": "😮";
1747
+ "\uD83D\uDE22": "😢";
1748
+ "\uD83C\uDF89": "🎉";
1743
1749
  }>;
1744
1750
  profile: z.ZodObject<{
1745
1751
  id: z.ZodString;
@@ -12384,6 +12390,12 @@ export declare const publicPostWithActivityScoreSchema: z.ZodObject<{
12384
12390
  reactions: z.ZodArray<z.ZodObject<{
12385
12391
  reaction: z.ZodEnum<{
12386
12392
  "\uD83D\uDC4D": "👍";
12393
+ "\uD83D\uDC4E": "👎";
12394
+ "\u2764\uFE0F": "❤️";
12395
+ "\uD83D\uDE02": "😂";
12396
+ "\uD83D\uDE2E": "😮";
12397
+ "\uD83D\uDE22": "😢";
12398
+ "\uD83C\uDF89": "🎉";
12387
12399
  }>;
12388
12400
  profile: z.ZodObject<{
12389
12401
  id: z.ZodString;
@@ -18067,6 +18079,12 @@ declare const topPostsListSchema: z.ZodArray<z.ZodObject<{
18067
18079
  reactions: z.ZodArray<z.ZodObject<{
18068
18080
  reaction: z.ZodEnum<{
18069
18081
  "\uD83D\uDC4D": "👍";
18082
+ "\uD83D\uDC4E": "👎";
18083
+ "\u2764\uFE0F": "❤️";
18084
+ "\uD83D\uDE02": "😂";
18085
+ "\uD83D\uDE2E": "😮";
18086
+ "\uD83D\uDE22": "😢";
18087
+ "\uD83C\uDF89": "🎉";
18070
18088
  }>;
18071
18089
  profile: z.ZodObject<{
18072
18090
  id: z.ZodString;
@@ -28711,6 +28729,12 @@ declare const topPostsListSchema: z.ZodArray<z.ZodObject<{
28711
28729
  reactions: z.ZodArray<z.ZodObject<{
28712
28730
  reaction: z.ZodEnum<{
28713
28731
  "\uD83D\uDC4D": "👍";
28732
+ "\uD83D\uDC4E": "👎";
28733
+ "\u2764\uFE0F": "❤️";
28734
+ "\uD83D\uDE02": "😂";
28735
+ "\uD83D\uDE2E": "😮";
28736
+ "\uD83D\uDE22": "😢";
28737
+ "\uD83C\uDF89": "🎉";
28714
28738
  }>;
28715
28739
  profile: z.ZodObject<{
28716
28740
  id: z.ZodString;
@@ -34664,6 +34688,12 @@ export declare const profileActivitySummarySchema: z.ZodObject<{
34664
34688
  reactions: z.ZodArray<z.ZodObject<{
34665
34689
  reaction: z.ZodEnum<{
34666
34690
  "\uD83D\uDC4D": "👍";
34691
+ "\uD83D\uDC4E": "👎";
34692
+ "\u2764\uFE0F": "❤️";
34693
+ "\uD83D\uDE02": "😂";
34694
+ "\uD83D\uDE2E": "😮";
34695
+ "\uD83D\uDE22": "😢";
34696
+ "\uD83C\uDF89": "🎉";
34667
34697
  }>;
34668
34698
  profile: z.ZodObject<{
34669
34699
  id: z.ZodString;
@@ -45308,6 +45338,12 @@ export declare const profileActivitySummarySchema: z.ZodObject<{
45308
45338
  reactions: z.ZodArray<z.ZodObject<{
45309
45339
  reaction: z.ZodEnum<{
45310
45340
  "\uD83D\uDC4D": "👍";
45341
+ "\uD83D\uDC4E": "👎";
45342
+ "\u2764\uFE0F": "❤️";
45343
+ "\uD83D\uDE02": "😂";
45344
+ "\uD83D\uDE2E": "😮";
45345
+ "\uD83D\uDE22": "😢";
45346
+ "\uD83C\uDF89": "🎉";
45311
45347
  }>;
45312
45348
  profile: z.ZodObject<{
45313
45349
  id: z.ZodString;
@@ -51002,6 +51038,12 @@ export declare const adminProfileSummarySchema: z.ZodObject<{
51002
51038
  reactions: z.ZodArray<z.ZodObject<{
51003
51039
  reaction: z.ZodEnum<{
51004
51040
  "\uD83D\uDC4D": "👍";
51041
+ "\uD83D\uDC4E": "👎";
51042
+ "\u2764\uFE0F": "❤️";
51043
+ "\uD83D\uDE02": "😂";
51044
+ "\uD83D\uDE2E": "😮";
51045
+ "\uD83D\uDE22": "😢";
51046
+ "\uD83C\uDF89": "🎉";
51005
51047
  }>;
51006
51048
  profile: z.ZodObject<{
51007
51049
  id: z.ZodString;
@@ -61646,6 +61688,12 @@ export declare const adminProfileSummarySchema: z.ZodObject<{
61646
61688
  reactions: z.ZodArray<z.ZodObject<{
61647
61689
  reaction: z.ZodEnum<{
61648
61690
  "\uD83D\uDC4D": "👍";
61691
+ "\uD83D\uDC4E": "👎";
61692
+ "\u2764\uFE0F": "❤️";
61693
+ "\uD83D\uDE02": "😂";
61694
+ "\uD83D\uDE2E": "😮";
61695
+ "\uD83D\uDE22": "😢";
61696
+ "\uD83C\uDF89": "🎉";
61649
61697
  }>;
61650
61698
  profile: z.ZodObject<{
61651
61699
  id: z.ZodString;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpeepshq/common",
3
- "version": "0.10.0",
3
+ "version": "0.12.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -10,6 +10,12 @@ import { effectiveEventTimes } from './eventRecurrence';
10
10
  import { getJamUrl } from './jamHelpers';
11
11
  import { isIanaTimeZone } from './timeZone';
12
12
 
13
+ /**
14
+ * Feed cache TTL in seconds. Single source of truth for the HTTP `max-age`
15
+ * and the ICS `REFRESH-INTERVAL`/`X-PUBLISHED-TTL` so they cannot drift.
16
+ */
17
+ export const EVENTS_ICS_FEED_TTL_SECONDS = 3600;
18
+
13
19
  const utcDateFromYmd = (yyyyMmDd: string): Date => {
14
20
  const [y, m, d] = yyyyMmDd.split('-').map(Number);
15
21
  return new Date(Date.UTC(y, m - 1, d));
@@ -60,6 +66,30 @@ const withVtimezone = (calendarText: string, timeZone: string): string => {
60
66
  );
61
67
  };
62
68
 
69
+ /**
70
+ * ical-generator writes an all-day `recurrenceId` as a UTC instant
71
+ * (`RECURRENCE-ID:20260713T000000Z`), but RFC 5545 §3.8.4.4 requires the
72
+ * RECURRENCE-ID value type to match the series DTSTART — DATE for all-day
73
+ * events. Rewrite each RECURRENCE-ID line to DATE form.
74
+ */
75
+ const withDateRecurrenceId = (calendarText: string): string =>
76
+ // Split on any line ending so a trailing `\r` is never carried into the
77
+ // re-joined CRLF text (splitting on `\n` alone would leave `\r\r\n`).
78
+ calendarText
79
+ .split(/\r\n|\r|\n/)
80
+ .map((line) => {
81
+ if (!line.startsWith('RECURRENCE-ID')) return line;
82
+ if (line.includes(';VALUE=DATE')) return line;
83
+ const colonIdx = line.indexOf(':');
84
+ if (colonIdx === -1) return line;
85
+ const ymd = line
86
+ .slice(colonIdx + 1)
87
+ .replace(/[^0-9]/g, '')
88
+ .slice(0, 8);
89
+ return `RECURRENCE-ID;VALUE=DATE:${ymd}`;
90
+ })
91
+ .join('\r\n');
92
+
63
93
  const originFromUrl = (url?: string): string | undefined => {
64
94
  if (!url) {
65
95
  return undefined;
@@ -73,7 +103,7 @@ const originFromUrl = (url?: string): string | undefined => {
73
103
 
74
104
  /** Prefer a joinable place: physical address, jam URL, then external event URL. */
75
105
  const eventLocation = (
76
- post: PublicPost,
106
+ post: IcsEventPost,
77
107
  event: Event,
78
108
  postUrl?: string,
79
109
  ): string | undefined => {
@@ -127,9 +157,20 @@ const repeatingOptions = (event: Event, timeZone?: string) => {
127
157
  };
128
158
  };
129
159
 
160
+ /**
161
+ * Minimal structural shape of an event post that the feed builder reads.
162
+ * `PostWithMeta` satisfies it, so callers can pass rich post objects
163
+ * without a cast.
164
+ */
165
+ export type IcsEventPost = {
166
+ id: string;
167
+ type: string;
168
+ data?: { type?: string } & Record<string, unknown>;
169
+ updatedAt: string;
170
+ };
130
171
  export const buildEventIcs = (
131
- post: PublicPost,
132
- options?: { postUrl?: string },
172
+ post: IcsEventPost,
173
+ options?: { postUrl?: string; lastModified?: string; sequence?: number },
133
174
  ): string | null => {
134
175
  if (post.type !== 'event' || post.data?.type !== 'event') {
135
176
  return null;
@@ -142,6 +183,15 @@ export const buildEventIcs = (
142
183
  scale: 'GREGORIAN',
143
184
  });
144
185
 
186
+ // Optional per-post edit stamp (used by the feed so clients update an
187
+ // existing UID instead of re-adding); omitted for single-event exports.
188
+ const stamp = options?.lastModified
189
+ ? {
190
+ lastModified: new Date(options.lastModified),
191
+ sequence: options.sequence ?? 0,
192
+ }
193
+ : {};
194
+
145
195
  const link = event.url ?? options?.postUrl;
146
196
  const summary = event.name?.trim() || 'Event';
147
197
  const description = event.content?.trim();
@@ -163,6 +213,7 @@ export const buildEventIcs = (
163
213
  ...(description ? { description } : {}),
164
214
  ...(location ? { location } : {}),
165
215
  ...(link ? { url: link } : {}),
216
+ ...stamp,
166
217
  ...(repeating ? { repeating } : {}),
167
218
  });
168
219
  } else {
@@ -179,33 +230,58 @@ export const buildEventIcs = (
179
230
  ...(description ? { description } : {}),
180
231
  ...(location ? { location } : {}),
181
232
  ...(link ? { url: link } : {}),
233
+ ...stamp,
182
234
  ...(repeating ? { repeating } : {}),
183
235
  });
184
236
  }
185
237
 
186
238
  for (const exception of event.exceptions ?? []) {
187
239
  if (exception.cancelled || !exception.start) continue;
188
- const start = instantInZone(exception.start, timeZone);
189
- const end = exception.end
190
- ? instantInZone(exception.end, timeZone)
191
- : defaultEnd(start, timeZone);
192
- calendar.createEvent({
193
- id: `openpeeps-event-${post.id}-${exception.recurrenceId}@openpeepshq`,
194
- start,
195
- end,
196
- ...(timeZone ? { timezone: timeZone } : {}),
197
- summary,
198
- ...(description ? { description } : {}),
199
- ...(location ? { location } : {}),
200
- ...(link ? { url: link } : {}),
201
- recurrenceId: instantInZone(exception.recurrenceId, timeZone),
202
- });
240
+ if (event.wholeDay) {
241
+ // Rescheduled all-day occurrence: an all-day override whose day range
242
+ // is the exception's new start day through its end day (inclusive).
243
+ // RECURRENCE-ID identifies the *original* occurrence (RFC 5545 3.8.4.4),
244
+ // while DTSTART/DTEND stay on the new days. The DATE-form RECURRENCE-ID
245
+ // is normalized after serialization.
246
+ const excStartYmd = exception.start.slice(0, 10);
247
+ const excLastInclusiveYmd = exception.end?.slice(0, 10) ?? excStartYmd;
248
+ calendar.createEvent({
249
+ id: `openpeeps-event-${post.id}-${exception.recurrenceId}@openpeepshq`,
250
+ allDay: true,
251
+ start: utcDateFromYmd(excStartYmd),
252
+ end: exclusiveEndAfterInclusiveDay(excLastInclusiveYmd),
253
+ summary,
254
+ ...(description ? { description } : {}),
255
+ ...(location ? { location } : {}),
256
+ ...(link ? { url: link } : {}),
257
+ ...stamp,
258
+ recurrenceId: utcDateFromYmd(exception.recurrenceId.slice(0, 10)),
259
+ });
260
+ } else {
261
+ const start = instantInZone(exception.start, timeZone);
262
+ const end = exception.end
263
+ ? instantInZone(exception.end, timeZone)
264
+ : defaultEnd(start, timeZone);
265
+ calendar.createEvent({
266
+ id: `openpeeps-event-${post.id}-${exception.recurrenceId}@openpeepshq`,
267
+ start,
268
+ end,
269
+ ...(timeZone ? { timezone: timeZone } : {}),
270
+ summary,
271
+ ...(description ? { description } : {}),
272
+ ...(location ? { location } : {}),
273
+ ...(link ? { url: link } : {}),
274
+ ...stamp,
275
+ recurrenceId: instantInZone(exception.recurrenceId, timeZone),
276
+ });
277
+ }
203
278
  }
204
279
 
205
280
  const calendarText = calendar.toString();
206
- return (
207
- (timeZone ? withVtimezone(calendarText, timeZone) : calendarText) + '\r\n'
208
- );
281
+ const processed = event.wholeDay
282
+ ? withDateRecurrenceId(calendarText)
283
+ : calendarText;
284
+ return (timeZone ? withVtimezone(processed, timeZone) : processed) + '\r\n';
209
285
  };
210
286
 
211
287
  const addOccurrenceEvent = (
@@ -319,3 +395,98 @@ export const rsvpConfirmationContent = (
319
395
  occurrenceCount: occurrenceIds.length,
320
396
  };
321
397
  };
398
+
399
+ /** Collect the VEVENT blocks from a full ICS document. */
400
+ const extractVevents = (ics: string): string[] => {
401
+ const blocks: string[] = [];
402
+ let depth = 0;
403
+ let current: string[] = [];
404
+ for (const line of ics.split(/\r?\n/)) {
405
+ if (line.startsWith('BEGIN:VEVENT')) {
406
+ depth += 1;
407
+ current = [line];
408
+ } else if (line.startsWith('END:VEVENT')) {
409
+ depth -= 1;
410
+ current.push(line);
411
+ if (depth === 0) blocks.push(current.join('\r\n'));
412
+ } else if (depth > 0) {
413
+ current.push(line);
414
+ }
415
+ }
416
+ return blocks;
417
+ };
418
+
419
+ /**
420
+ * The zone list referenced by a set of VEVENTs, in first-seen order. Each
421
+ * per-post export splices in the VTIMEZONEs its events use; a feed of several
422
+ * zone-aware events must keep one block per zone (ical-generator emits
423
+ * `TZID=` references without any VTIMEZONE of its own).
424
+ */
425
+ const referencedZones = (vevents: string[]): string[] => {
426
+ const zones: string[] = [];
427
+ for (const vevent of vevents) {
428
+ for (const line of vevent.split('\r\n')) {
429
+ const match = line.match(/;TZID=([^:;]+)/);
430
+ if (match && !zones.includes(match[1])) {
431
+ zones.push(match[1]);
432
+ }
433
+ }
434
+ }
435
+ return zones;
436
+ };
437
+
438
+ /**
439
+ * Build a multi-event ICS feed string. Composes the single-event exports so
440
+ * the feed stays byte-identical to what the per-event download produces, and
441
+ * carries one deduped VTIMEZONE block per zone so zone-aware events survive.
442
+ *
443
+ * `postUrl` is the community base (origin); each event's joinable-URL fallback
444
+ * is derived as `${postUrl}/posts/{id}`, mirroring the single-event export.
445
+ * Passing a bare origin (never the request URL) keeps the feed's `?token=`
446
+ * secret out of the ICS body.
447
+ *
448
+ * With no events the feed is still a valid calendar (PRODID, `X-WR-CALNAME`,
449
+ * `REFRESH-INTERVAL`, `X-PUBLISHED-TTL`, no VEVENTs) — the same shape the
450
+ * feed endpoint's 401 `emptyCalendar` fallback mirrors. An empty feed is 200,
451
+ * not 404: calendar clients expect a parseable document they can re-poll.
452
+ */
453
+ export const buildEventsFeedIcs = (
454
+ posts: IcsEventPost[],
455
+ options: { postUrl?: string; name: string; ttl?: number },
456
+ ): string => {
457
+ const { name, ttl = EVENTS_ICS_FEED_TTL_SECONDS } = options;
458
+ const calendar = ical({
459
+ prodId: '//OpenPeeps//Feed//EN',
460
+ method: ICalCalendarMethod.PUBLISH,
461
+ scale: 'GREGORIAN',
462
+ name,
463
+ ttl,
464
+ });
465
+
466
+ const base = options.postUrl?.replace(/\/+$/, '');
467
+ const vevents: string[] = [];
468
+ for (const post of posts) {
469
+ if (post.type !== 'event' || post.data?.type !== 'event') continue;
470
+ const single = buildEventIcs(post, {
471
+ postUrl: base ? `${base}/posts/${post.id}` : undefined,
472
+ lastModified: post.updatedAt,
473
+ // Minutes since epoch: stable across processes, grows only on edits.
474
+ sequence: Math.floor(new Date(post.updatedAt).getTime() / 60000),
475
+ });
476
+ if (single) vevents.push(...extractVevents(single));
477
+ }
478
+
479
+ const zoneBlocks = referencedZones(vevents)
480
+ .map((zone) => {
481
+ const [block] = tzlib_get_ical_block(zone) as [string, string];
482
+ return block.replace(/\r?\n/g, '\r\n').trim();
483
+ })
484
+ .join('\r\n');
485
+
486
+ const body =
487
+ (zoneBlocks ? zoneBlocks + '\r\n' : '') +
488
+ (vevents.length ? vevents.join('\r\n') + '\r\n' : '');
489
+ return calendar
490
+ .toString()
491
+ .replace(/END:VCALENDAR\r?\n?$/, body + 'END:VCALENDAR\r\n');
492
+ };
@@ -771,10 +771,10 @@ export type PostActionAvailability = {
771
771
  };
772
772
 
773
773
  /**
774
- * Whether Reply / Repost / Like should look live. Non-members of a group
774
+ * Whether Reply / Repost / React should look live. Non-members of a group
775
775
  * post stay fully disabled (existing feed rule). Each action also follows
776
776
  * the capability the matching write endpoint actually checks: feed replies
777
- * and reposts need create-*, likes need core-posts-react.
777
+ * and reposts need create-*, reactions need core-posts-react.
778
778
  */
779
779
  export const getPostActionAvailability = (
780
780
  authData: AuthorizationData,
@@ -1,13 +1,13 @@
1
- export const AP_LIKE_REACTION = '👍';
2
- export const AP_DISLIKE_REACTION = '👎';
1
+ import { REACTION_TYPES, type ReactionData } from '../types';
3
2
 
4
- export const activityPubActivityForReaction = (
3
+ /** The legacy plain like a bodyless DELETE retracts for pre-picker clients. */
4
+ export const AP_LIKE_REACTION = REACTION_TYPES[0];
5
+
6
+ /** Whether a logged reaction value is one of the curated post reactions. */
7
+ export const isReactionType = (
5
8
  reaction: string,
6
- ): 'Like' | 'Dislike' | null => {
7
- if (reaction === AP_LIKE_REACTION) return 'Like';
8
- if (reaction === AP_DISLIKE_REACTION) return 'Dislike';
9
- return null;
10
- };
9
+ ): reaction is ReactionData['reaction'] =>
10
+ (REACTION_TYPES as readonly string[]).includes(reaction);
11
11
 
12
12
  export type ReactionLogEntry = {
13
13
  type: string;