@openpeepshq/common 0.1.46 → 0.3.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.
Files changed (83) hide show
  1. package/dist/lib/adminSections.js +1 -1
  2. package/dist/lib/capabilitiesHelpers.js +30 -40
  3. package/dist/lib/csvHelpers.js +1 -1
  4. package/dist/lib/eventIcs.js +26 -32
  5. package/dist/lib/eventRecurrence.d.ts +17 -0
  6. package/dist/lib/eventRecurrence.js +75 -18
  7. package/dist/lib/eventTime.js +9 -11
  8. package/dist/lib/groupHelpers.js +13 -34
  9. package/dist/lib/groupTemplateHelpers.js +6 -10
  10. package/dist/lib/jamHelpers.js +6 -9
  11. package/dist/lib/markdownHelpers.d.ts +37 -0
  12. package/dist/lib/markdownHelpers.js +151 -3
  13. package/dist/lib/postHelpers.js +70 -97
  14. package/dist/lib/profileHelpers.js +17 -24
  15. package/dist/lib/pushHelpers.js +3 -4
  16. package/dist/lib/scopeHelpers.js +6 -9
  17. package/dist/lib/ssoLoginUrl.js +4 -6
  18. package/dist/lib/ssoProviders.js +35 -39
  19. package/dist/lib/tokenHelpers.js +5 -5
  20. package/dist/lib/utils.js +6 -7
  21. package/dist/types/admin-db.js +1 -1
  22. package/dist/types/api.d.ts +1 -0
  23. package/dist/types/api.js +1 -1
  24. package/dist/types/config.d.ts +3 -0
  25. package/dist/types/config.js +3 -0
  26. package/dist/types/models.js +1 -1
  27. package/dist/types/plugins.js +2 -2
  28. package/dist/zod.d.ts +1 -0
  29. package/dist/zod.js +1 -0
  30. package/package.json +36 -6
  31. package/src/index.ts +4 -0
  32. package/src/lib/adminSections.ts +84 -0
  33. package/src/lib/attachmentHelpers.ts +14 -0
  34. package/src/lib/capabilitiesHelpers.ts +532 -0
  35. package/src/lib/colors.ts +20 -0
  36. package/src/lib/csvHelpers.ts +31 -0
  37. package/src/lib/eventIcs.ts +265 -0
  38. package/src/lib/eventRecurrence.ts +495 -0
  39. package/src/lib/eventTime.ts +206 -0
  40. package/src/lib/federationHosts.ts +22 -0
  41. package/src/lib/feedCursor.ts +27 -0
  42. package/src/lib/feedFormat.ts +24 -0
  43. package/src/lib/groupHelpers.ts +421 -0
  44. package/src/lib/groupTemplateHelpers.ts +83 -0
  45. package/src/lib/index.ts +29 -0
  46. package/src/lib/jamHelpers.ts +164 -0
  47. package/src/lib/legacyThemeRoot.ts +14 -0
  48. package/src/lib/markdownHelpers.ts +290 -0
  49. package/src/lib/mediaDimensions.ts +21 -0
  50. package/src/lib/postHelpers.ts +783 -0
  51. package/src/lib/profileHelpers.ts +220 -0
  52. package/src/lib/pushHelpers.ts +34 -0
  53. package/src/lib/reactions.ts +52 -0
  54. package/src/lib/reportHelpers.ts +7 -0
  55. package/src/lib/scopeHelpers.ts +176 -0
  56. package/src/lib/ssoLoginUrl.ts +93 -0
  57. package/src/lib/ssoProviders.ts +472 -0
  58. package/src/lib/text.ts +26 -0
  59. package/src/lib/timeZone.ts +52 -0
  60. package/src/lib/tokenHelpers.ts +119 -0
  61. package/src/lib/utils.ts +322 -0
  62. package/src/types/admin-db.ts +74 -0
  63. package/src/types/admin-email.ts +55 -0
  64. package/src/types/admin-jobs.ts +17 -0
  65. package/src/types/admin-performance.ts +20 -0
  66. package/src/types/analytics.ts +318 -0
  67. package/src/types/api.ts +871 -0
  68. package/src/types/apple-app-site-association.ts +54 -0
  69. package/src/types/auth.ts +22 -0
  70. package/src/types/capabilities.ts +280 -0
  71. package/src/types/config.ts +546 -0
  72. package/src/types/db.ts +138 -0
  73. package/src/types/export.ts +10 -0
  74. package/src/types/index.ts +20 -0
  75. package/src/types/internal.ts +338 -0
  76. package/src/types/models.ts +939 -0
  77. package/src/types/notifications.ts +92 -0
  78. package/src/types/plugins.ts +150 -0
  79. package/src/types/roleDefaults.ts +132 -0
  80. package/src/types/stats.ts +195 -0
  81. package/src/types/stripe.ts +45 -0
  82. package/src/types/utils.ts +100 -0
  83. package/src/zod.ts +1 -0
@@ -61,7 +61,7 @@ export const adminSections = [
61
61
  capabilities: ['core-db-access'],
62
62
  },
63
63
  ];
64
- export const canAccessAdminSection = (roles, section) => checkRoleCapabilities(roles !== null && roles !== void 0 ? roles : [], [...section.capabilities]).success;
64
+ export const canAccessAdminSection = (roles, section) => checkRoleCapabilities(roles ?? [], [...section.capabilities]).success;
65
65
  export const getVisibleAdminSections = (roles) => adminSections.filter((section) => canAccessAdminSection(roles, section));
66
66
  /** True when the profile may see at least one admin menu entry. */
67
67
  export const canAccessAdminMenu = (roles) => getVisibleAdminSections(roles).length > 0;
@@ -4,30 +4,26 @@ export const checkCapabilities = (neededCapabilities, presentCapabilities = {
4
4
  add: [],
5
5
  remove: [],
6
6
  }) => {
7
- const containsCapability = (c, clist) => !!(clist === null || clist === void 0 ? void 0 : clist.find((pc) => pc === c || (pc.includes('*') && c.startsWith(pc.split('*')[0]))));
8
- const missingCapabilities = neededCapabilities.filter((c) => {
9
- var _a, _b;
10
- return containsCapability(c, (_a = presentCapabilities.remove) !== null && _a !== void 0 ? _a : []) ||
11
- !containsCapability(c, (_b = presentCapabilities.add) !== null && _b !== void 0 ? _b : []);
12
- });
7
+ const containsCapability = (c, clist) => !!clist?.find((pc) => pc === c || (pc.includes('*') && c.startsWith(pc.split('*')[0])));
8
+ const missingCapabilities = neededCapabilities.filter((c) => containsCapability(c, presentCapabilities.remove ?? []) ||
9
+ !containsCapability(c, presentCapabilities.add ?? []));
13
10
  return {
14
11
  success: missingCapabilities.length === 0,
15
12
  missingCapabilities,
16
13
  };
17
14
  };
18
15
  export const mergeCapabilities = (capabilities) => {
19
- var _a, _b;
20
16
  return {
21
- add: [...new Set((_a = capabilities === null || capabilities === void 0 ? void 0 : capabilities.map((c) => (c === null || c === void 0 ? void 0 : c.add) || []).flat()) !== null && _a !== void 0 ? _a : [])],
17
+ add: [...new Set(capabilities?.map((c) => c?.add || []).flat() ?? [])],
22
18
  remove: [
23
- ...new Set((_b = capabilities === null || capabilities === void 0 ? void 0 : capabilities.map((c) => (c === null || c === void 0 ? void 0 : c.remove) || []).flat()) !== null && _b !== void 0 ? _b : []),
19
+ ...new Set(capabilities?.map((c) => c?.remove || []).flat() ?? []),
24
20
  ],
25
21
  };
26
22
  };
27
23
  /** Order-independent equality check for two capability add/remove lists. */
28
24
  export const capabilitySetsEqual = (a, b) => {
29
- const sa = new Set(a !== null && a !== void 0 ? a : []);
30
- const sb = new Set(b !== null && b !== void 0 ? b : []);
25
+ const sa = new Set(a ?? []);
26
+ const sb = new Set(b ?? []);
31
27
  if (sa.size !== sb.size)
32
28
  return false;
33
29
  return [...sa].every((value) => sb.has(value));
@@ -62,8 +58,8 @@ export const localOrNone = (authData) => {
62
58
  return ['none'];
63
59
  };
64
60
  export const getGroupRelationships = (authData, group) => {
65
- var _a, _b, _c;
66
- const membershipRoles = (_c = (_b = (_a = authData.profile) === null || _a === void 0 ? void 0 : _a.memberships.find((m) => m.group.id === group.id)) === null || _b === void 0 ? void 0 : _b.roles) !== null && _c !== void 0 ? _c : [];
61
+ const membershipRoles = authData.profile?.memberships.find((m) => m.group.id === group.id)?.roles ??
62
+ [];
67
63
  if (authData.profile || authData.service) {
68
64
  return [...localOrNone(authData), ...membershipRoles];
69
65
  }
@@ -71,41 +67,40 @@ export const getGroupRelationships = (authData, group) => {
71
67
  };
72
68
  export const getProfileRelationships = (authData, otherProfile) => {
73
69
  const { profile } = authData;
74
- if (profile && profile.id === (otherProfile === null || otherProfile === void 0 ? void 0 : otherProfile.id)) {
70
+ if (profile && profile.id === otherProfile?.id) {
75
71
  return ['self', ...localOrNone(authData)];
76
72
  }
77
73
  const relationships = localOrNone(authData);
78
- if (profile === null || profile === void 0 ? void 0 : profile.followers.map((f) => f.id).includes(otherProfile === null || otherProfile === void 0 ? void 0 : otherProfile.id)) {
74
+ if (profile?.followers.map((f) => f.id).includes(otherProfile?.id)) {
79
75
  relationships.push('followed-by');
80
76
  }
81
- if (profile === null || profile === void 0 ? void 0 : profile.following.map((f) => f.id).includes(otherProfile === null || otherProfile === void 0 ? void 0 : otherProfile.id)) {
77
+ if (profile?.following.map((f) => f.id).includes(otherProfile?.id)) {
82
78
  relationships.push('following');
83
79
  }
84
- if (viewerBlockedTarget(profile, otherProfile === null || otherProfile === void 0 ? void 0 : otherProfile.id)) {
80
+ if (viewerBlockedTarget(profile, otherProfile?.id)) {
85
81
  relationships.push('blocked');
86
82
  }
87
- if (targetBlockedViewer(profile, otherProfile === null || otherProfile === void 0 ? void 0 : otherProfile.id)) {
83
+ if (targetBlockedViewer(profile, otherProfile?.id)) {
88
84
  relationships.push('blocked-by');
89
85
  }
90
86
  return relationships;
91
87
  };
92
88
  export const getPostRelationships = (authData, post) => {
93
- var _a, _b, _c;
94
89
  const { profile } = authData;
95
90
  const relationships = [];
96
91
  if (['public', 'local'].includes(post.visibility)) {
97
92
  relationships.push(...localOrNone(authData));
98
93
  }
99
- if (profile && ((_a = post.audience) === null || _a === void 0 ? void 0 : _a.some((a) => a.id === profile.id))) {
94
+ if (profile && post.audience?.some((a) => a.id === profile.id)) {
100
95
  relationships.push('audience');
101
96
  }
102
- if (profile && ((_b = post.mentions) === null || _b === void 0 ? void 0 : _b.some((m) => m.profile.id === profile.id))) {
97
+ if (profile && post.mentions?.some((m) => m.profile.id === profile.id)) {
103
98
  relationships.push('mentioned');
104
99
  }
105
100
  if (profile &&
106
- ((_c = post.entries) === null || _c === void 0 ? void 0 : _c.some((e) => e.type === 'rsvp' &&
101
+ post.entries?.some((e) => e.type === 'rsvp' &&
107
102
  e.profile.id === profile.id &&
108
- ['yes', 'tentative'].includes(e.data.response)))) {
103
+ ['yes', 'tentative'].includes(e.data.response))) {
109
104
  relationships.push('attendee');
110
105
  }
111
106
  return relationships;
@@ -121,30 +116,28 @@ export const getReportRelationships = (authData, report) => {
121
116
  return localOrNone(authData);
122
117
  };
123
118
  export const getAccessTokenRelationships = (authData, accessToken) => {
124
- var _a;
125
119
  const { profile } = authData;
126
120
  const relationships = [...localOrNone(authData)];
127
- const ownerProfileId = (_a = accessToken.ownedBy) === null || _a === void 0 ? void 0 : _a.id;
128
- if (ownerProfileId && (profile === null || profile === void 0 ? void 0 : profile.id) === ownerProfileId) {
121
+ const ownerProfileId = accessToken.ownedBy?.id;
122
+ if (ownerProfileId && profile?.id === ownerProfileId) {
129
123
  relationships.push('owner');
130
124
  }
131
125
  return relationships;
132
126
  };
133
127
  const getConfigCapabilities = (object, relationships, config) => mergeCapabilities(relationships.map((r) => {
134
- var _a;
135
128
  const group = config[object];
136
- return (_a = group[r]) !== null && _a !== void 0 ? _a : { add: [], remove: [] };
129
+ return group[r] ?? { add: [], remove: [] };
137
130
  }));
138
131
  const getGroupRelationshipCapabilities = (authData, group) => mergeCapabilities(group
139
- ? getGroupRelationships(authData, group).map((r) => { var _a, _b; return (_b = (_a = group.capabilities) === null || _a === void 0 ? void 0 : _a[r]) !== null && _b !== void 0 ? _b : { add: [], remove: [] }; })
132
+ ? getGroupRelationships(authData, group).map((r) => group.capabilities?.[r] ?? { add: [], remove: [] })
140
133
  : []);
141
- export const getGroupCapabilitiesByRoles = (roles, group) => mergeCapabilities((roles !== null && roles !== void 0 ? roles : []).map((r) => { var _a, _b; return (_b = (_a = group === null || group === void 0 ? void 0 : group.capabilities) === null || _a === void 0 ? void 0 : _a[r]) !== null && _b !== void 0 ? _b : { add: [], remove: [] }; }));
134
+ export const getGroupCapabilitiesByRoles = (roles, group) => mergeCapabilities((roles ?? []).map((r) => group?.capabilities?.[r] ?? { add: [], remove: [] }));
142
135
  // Per-group powers (add member, post in group, moderate, …) come from the
143
136
  // caller's relationship to the group (edge roles plus none/local), never from
144
137
  // their instance role. Instance roles only gate group *creation*
145
138
  // (`core-groups-create`), checked separately at the creation entry points.
146
139
  export const getGroupCapabilities = (authData, group) => getGroupRelationshipCapabilities(authData, group);
147
- const getRoleCapabilities = (profile) => { var _a; return mergeCapabilities((_a = profile === null || profile === void 0 ? void 0 : profile.roles.map((r) => r.capabilities)) !== null && _a !== void 0 ? _a : []); };
140
+ const getRoleCapabilities = (profile) => mergeCapabilities(profile?.roles.map((r) => r.capabilities) ?? []);
148
141
  export const getProfileCapabilities = (authData, targetProfile, config) => getConfigCapabilities('profile', getProfileRelationships(authData, targetProfile), config);
149
142
  const getPostVisibilityCapabilities = (post, profile) => {
150
143
  switch (post.visibility) {
@@ -193,15 +186,12 @@ const getAccessTokenCapabilities = (authData, accessToken, config) => mergeCapab
193
186
  getConfigCapabilities('accessToken', getAccessTokenRelationships(authData, accessToken), config),
194
187
  getRoleCapabilities(authData.profile),
195
188
  ]);
196
- const getAccountCapabilities = (authData, targetAccount) => {
197
- var _a;
198
- return mergeCapabilities([
199
- ((_a = authData.account) === null || _a === void 0 ? void 0 : _a.id) === targetAccount.id
200
- ? { add: ['core-accounts-update'], remove: [] }
201
- : { add: [], remove: [] },
202
- getRoleCapabilities(authData.profile),
203
- ]);
204
- };
189
+ const getAccountCapabilities = (authData, targetAccount) => mergeCapabilities([
190
+ authData.account?.id === targetAccount.id
191
+ ? { add: ['core-accounts-update'], remove: [] }
192
+ : { add: [], remove: [] },
193
+ getRoleCapabilities(authData.profile),
194
+ ]);
205
195
  const checkCapabilitiesWithCalculatedScope = (capabilities, authData, neededCapabilities, resource) => {
206
196
  const requiredScope = calculateRequiredScope({
207
197
  resource,
@@ -10,7 +10,7 @@ export const escapeCsvCell = (value) => {
10
10
  };
11
11
  export const toCsvRow = (values) => values.map(escapeCsvCell).join(',');
12
12
  export const formatMemberExportCustomFields = (fields) => {
13
- if (!(fields === null || fields === void 0 ? void 0 : fields.length)) {
13
+ if (!fields?.length) {
14
14
  return '';
15
15
  }
16
16
  return JSON.stringify(fields.map(({ name, value }) => ({ name, value })));
@@ -23,8 +23,7 @@ const originFromUrl = (url) => {
23
23
  };
24
24
  /** Prefer a joinable place: physical address, jam URL, then external event URL. */
25
25
  const eventLocation = (post, event, postUrl) => {
26
- var _a, _b, _c;
27
- const physical = (_b = (_a = event.physicalLocation) === null || _a === void 0 ? void 0 : _a.text) === null || _b === void 0 ? void 0 : _b.trim();
26
+ const physical = event.physicalLocation?.text?.trim();
28
27
  if (physical) {
29
28
  return physical;
30
29
  }
@@ -34,7 +33,7 @@ const eventLocation = (post, event, postUrl) => {
34
33
  return jamUrl;
35
34
  }
36
35
  }
37
- return ((_c = event.url) === null || _c === void 0 ? void 0 : _c.trim()) || undefined;
36
+ return event.url?.trim() || undefined;
38
37
  };
39
38
  const repeatingFreq = {
40
39
  DAILY: ICalEventRepeatingFreq.DAILY,
@@ -51,17 +50,16 @@ const repeatingWeekday = {
51
50
  SU: ICalWeekday.SU,
52
51
  };
53
52
  const repeatingOptions = (event) => {
54
- var _a, _b, _c;
55
53
  const recurrence = event.recurrence;
56
54
  if (!recurrence)
57
55
  return undefined;
58
- const exclude = ((_a = event.exceptions) !== null && _a !== void 0 ? _a : [])
56
+ const exclude = (event.exceptions ?? [])
59
57
  .filter((exception) => exception.cancelled)
60
58
  .map((exception) => new Date(exception.recurrenceId));
61
59
  return {
62
60
  freq: repeatingFreq[recurrence.freq],
63
- interval: (_b = recurrence.interval) !== null && _b !== void 0 ? _b : 1,
64
- ...(((_c = recurrence.byDay) === null || _c === void 0 ? void 0 : _c.length)
61
+ interval: recurrence.interval ?? 1,
62
+ ...(recurrence.byDay?.length
65
63
  ? { byDay: recurrence.byDay.map((day) => repeatingWeekday[day]) }
66
64
  : {}),
67
65
  ...(recurrence.until ? { until: new Date(recurrence.until) } : {}),
@@ -70,8 +68,7 @@ const repeatingOptions = (event) => {
70
68
  };
71
69
  };
72
70
  export const buildEventIcs = (post, options) => {
73
- var _a, _b, _c, _d, _e, _f, _g;
74
- if (post.type !== 'event' || ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) !== 'event') {
71
+ if (post.type !== 'event' || post.data?.type !== 'event') {
75
72
  return null;
76
73
  }
77
74
  const event = post.data;
@@ -80,14 +77,14 @@ export const buildEventIcs = (post, options) => {
80
77
  method: ICalCalendarMethod.PUBLISH,
81
78
  scale: 'GREGORIAN',
82
79
  });
83
- const link = (_b = event.url) !== null && _b !== void 0 ? _b : options === null || options === void 0 ? void 0 : options.postUrl;
84
- const summary = ((_c = event.name) === null || _c === void 0 ? void 0 : _c.trim()) || 'Event';
85
- const description = (_d = event.content) === null || _d === void 0 ? void 0 : _d.trim();
86
- const location = eventLocation(post, event, options === null || options === void 0 ? void 0 : options.postUrl);
80
+ const link = event.url ?? options?.postUrl;
81
+ const summary = event.name?.trim() || 'Event';
82
+ const description = event.content?.trim();
83
+ const location = eventLocation(post, event, options?.postUrl);
87
84
  const repeating = repeatingOptions(event);
88
85
  if (event.wholeDay) {
89
86
  const startYmd = event.start.slice(0, 10);
90
- const lastInclusiveYmd = (_f = (_e = event.end) === null || _e === void 0 ? void 0 : _e.slice(0, 10)) !== null && _f !== void 0 ? _f : startYmd;
87
+ const lastInclusiveYmd = event.end?.slice(0, 10) ?? startYmd;
91
88
  calendar.createEvent({
92
89
  id: `openpeeps-event-${post.id}@openpeepshq`,
93
90
  allDay: true,
@@ -116,7 +113,7 @@ export const buildEventIcs = (post, options) => {
116
113
  ...(repeating ? { repeating } : {}),
117
114
  });
118
115
  }
119
- for (const exception of (_g = event.exceptions) !== null && _g !== void 0 ? _g : []) {
116
+ for (const exception of event.exceptions ?? []) {
120
117
  if (exception.cancelled || !exception.start)
121
118
  continue;
122
119
  const start = new Date(exception.start);
@@ -137,16 +134,15 @@ export const buildEventIcs = (post, options) => {
137
134
  return calendar.toString() + '\r\n';
138
135
  };
139
136
  const addOccurrenceEvent = (calendar, post, event, recurrenceId, options) => {
140
- var _a, _b, _c, _d, _e;
141
- const link = (_a = event.url) !== null && _a !== void 0 ? _a : options === null || options === void 0 ? void 0 : options.postUrl;
142
- const summary = ((_b = event.name) === null || _b === void 0 ? void 0 : _b.trim()) || 'Event';
143
- const description = (_c = event.content) === null || _c === void 0 ? void 0 : _c.trim();
144
- const location = eventLocation(post, event, options === null || options === void 0 ? void 0 : options.postUrl);
137
+ const link = event.url ?? options?.postUrl;
138
+ const summary = event.name?.trim() || 'Event';
139
+ const description = event.content?.trim();
140
+ const location = eventLocation(post, event, options?.postUrl);
145
141
  const times = effectiveEventTimes(event, recurrenceId);
146
142
  const id = `openpeeps-event-${post.id}-${recurrenceId}@openpeepshq`;
147
143
  if (event.wholeDay) {
148
144
  const startYmd = times.start.slice(0, 10);
149
- const lastInclusiveYmd = (_e = (_d = times.end) === null || _d === void 0 ? void 0 : _d.slice(0, 10)) !== null && _e !== void 0 ? _e : startYmd;
145
+ const lastInclusiveYmd = times.end?.slice(0, 10) ?? startYmd;
150
146
  calendar.createEvent({
151
147
  id,
152
148
  allDay: true,
@@ -175,12 +171,11 @@ const addOccurrenceEvent = (calendar, post, event, recurrenceId, options) => {
175
171
  };
176
172
  /** Attendance ICS: discrete booked dates, or the series definition when none. */
177
173
  export const buildRsvpIcs = (post, options) => {
178
- var _a, _b, _c;
179
- const occurrenceIds = (_b = (_a = options === null || options === void 0 ? void 0 : options.occurrenceIds) === null || _a === void 0 ? void 0 : _a.filter(Boolean)) !== null && _b !== void 0 ? _b : [];
174
+ const occurrenceIds = options?.occurrenceIds?.filter(Boolean) ?? [];
180
175
  if (!occurrenceIds.length) {
181
- return buildEventIcs(post, { postUrl: options === null || options === void 0 ? void 0 : options.postUrl });
176
+ return buildEventIcs(post, { postUrl: options?.postUrl });
182
177
  }
183
- if (post.type !== 'event' || ((_c = post.data) === null || _c === void 0 ? void 0 : _c.type) !== 'event') {
178
+ if (post.type !== 'event' || post.data?.type !== 'event') {
184
179
  return null;
185
180
  }
186
181
  const event = post.data;
@@ -195,25 +190,24 @@ export const buildRsvpIcs = (post, options) => {
195
190
  return calendar.toString() + '\r\n';
196
191
  };
197
192
  export const rsvpConfirmationContent = (post, options) => {
198
- var _a, _b, _c, _d, _e, _f, _g, _h;
199
- if (post.type !== 'event' || ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) !== 'event') {
193
+ if (post.type !== 'event' || post.data?.type !== 'event') {
200
194
  return null;
201
195
  }
202
196
  const ics = buildRsvpIcs(post, options);
203
197
  if (!ics)
204
198
  return null;
205
199
  const event = post.data;
206
- const occurrenceIds = (_c = (_b = options.occurrenceIds) === null || _b === void 0 ? void 0 : _b.filter(Boolean)) !== null && _c !== void 0 ? _c : [];
200
+ const occurrenceIds = options.occurrenceIds?.filter(Boolean) ?? [];
207
201
  const times = occurrenceIds.length > 0
208
202
  ? effectiveEventTimes(event, occurrenceIds[0])
209
203
  : { start: event.start, end: event.end };
210
204
  return {
211
205
  ics,
212
- eventName: ((_d = event.name) === null || _d === void 0 ? void 0 : _d.trim()) || 'Event',
206
+ eventName: event.name?.trim() || 'Event',
213
207
  start: times.start,
214
- end: (_e = times.end) !== null && _e !== void 0 ? _e : null,
215
- location: (_g = (_f = event.physicalLocation) === null || _f === void 0 ? void 0 : _f.text) !== null && _g !== void 0 ? _g : null,
216
- allDay: (_h = event.wholeDay) !== null && _h !== void 0 ? _h : false,
208
+ end: times.end ?? null,
209
+ location: event.physicalLocation?.text ?? null,
210
+ allDay: event.wholeDay ?? false,
217
211
  occurrenceCount: occurrenceIds.length,
218
212
  };
219
213
  };
@@ -22,6 +22,23 @@ export declare const expandEventOccurrences: (event: Event, window: {
22
22
  }) => ExpandedOccurrence[];
23
23
  export declare const occurrencesForIndex: (event: Event, now?: Date) => ExpandedOccurrence[];
24
24
  export declare const listRsvpOccurrences: (event: Event, now?: Date) => ExpandedOccurrence[];
25
+ export declare const occurrenceHasEnded: (start: string, end?: string, now?: Date) => boolean;
26
+ export type EventRsvpOpenOptions = {
27
+ recurrenceId?: string;
28
+ lockToOccurrence?: boolean;
29
+ now?: Date;
30
+ };
31
+ /** False once the event, or the locked occurrence, is over. */
32
+ export declare const eventRsvpOpen: (event: Event, options?: EventRsvpOpenOptions) => boolean;
33
+ export type RsvpTimeTarget = {
34
+ occurrenceIds?: string[];
35
+ recurrenceId?: string;
36
+ };
37
+ /**
38
+ * True when every targeted time is already over. A series RSVP with no ids
39
+ * is past only when the series has nothing left open.
40
+ */
41
+ export declare const rsvpTargetsPastEvent: (event: Event, target?: RsvpTimeTarget, now?: Date) => boolean;
25
42
  export declare const defaultRsvpRecurrenceId: (event: Event, queryId?: string, now?: Date) => string | undefined;
26
43
  export declare const previewUpcomingOccurrences: (event: Event, count?: number, now?: Date) => ExpandedOccurrence[];
27
44
  export declare const effectiveEventTimes: (event: Event, recurrenceId?: string) => {
@@ -53,9 +53,8 @@ const applyDuration = (start, durationMs) => {
53
53
  return toIso(new Date(start.getTime() + durationMs));
54
54
  };
55
55
  const exceptionById = (event) => {
56
- var _a;
57
56
  const map = new Map();
58
- for (const exception of (_a = event.exceptions) !== null && _a !== void 0 ? _a : []) {
57
+ for (const exception of event.exceptions ?? []) {
59
58
  map.set(normalizeRecurrenceId(exception.recurrenceId), exception);
60
59
  }
61
60
  return map;
@@ -77,13 +76,12 @@ const nextByFreq = (date, freq, interval) => {
77
76
  return addMonths(date, interval);
78
77
  };
79
78
  const generateRawStarts = (event, untilBound) => {
80
- var _a, _b, _c;
81
79
  const recurrence = event.recurrence;
82
80
  const dtstart = new Date(event.start);
83
81
  if (!recurrence) {
84
82
  return [dtstart];
85
83
  }
86
- const interval = (_a = recurrence.interval) !== null && _a !== void 0 ? _a : 1;
84
+ const interval = recurrence.interval ?? 1;
87
85
  const until = recurrence.until ? new Date(recurrence.until) : undefined;
88
86
  const hardStop = until && until < untilBound ? until : untilBound;
89
87
  const starts = [];
@@ -94,7 +92,7 @@ const generateRawStarts = (event, untilBound) => {
94
92
  return;
95
93
  starts.push(date);
96
94
  };
97
- if (recurrence.freq === 'WEEKLY' && ((_c = (_b = recurrence.byDay) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) > 0) {
95
+ if (recurrence.freq === 'WEEKLY' && (recurrence.byDay?.length ?? 0) > 0) {
98
96
  const byDays = new Set(recurrence.byDay);
99
97
  let cursor = dtstart;
100
98
  while (cursor.getTime() <= hardStop.getTime()) {
@@ -122,23 +120,22 @@ const generateRawStarts = (event, untilBound) => {
122
120
  return recurrence.count ? unique.slice(0, recurrence.count) : unique;
123
121
  };
124
122
  const decorateOccurrence = (originalStart, event, exceptions, durationMs) => {
125
- var _a, _b, _c;
126
123
  const recurrenceId = toIso(originalStart);
127
124
  const exception = exceptions.get(recurrenceId);
128
- if (exception === null || exception === void 0 ? void 0 : exception.cancelled) {
125
+ if (exception?.cancelled) {
129
126
  return {
130
127
  recurrenceId,
131
- start: (_a = exception.start) !== null && _a !== void 0 ? _a : recurrenceId,
132
- end: (_b = exception.end) !== null && _b !== void 0 ? _b : applyDuration(originalStart, durationMs),
128
+ start: exception.start ?? recurrenceId,
129
+ end: exception.end ?? applyDuration(originalStart, durationMs),
133
130
  cancelled: true,
134
131
  };
135
132
  }
136
- if (exception === null || exception === void 0 ? void 0 : exception.start) {
133
+ if (exception?.start) {
137
134
  const start = new Date(exception.start);
138
135
  return {
139
136
  recurrenceId,
140
137
  start: toIso(start),
141
- end: (_c = exception.end) !== null && _c !== void 0 ? _c : applyDuration(start, durationMs),
138
+ end: exception.end ?? applyDuration(start, durationMs),
142
139
  cancelled: false,
143
140
  };
144
141
  }
@@ -181,11 +178,73 @@ export const listRsvpOccurrences = (event, now = new Date()) => expandEventOccur
181
178
  from: now,
182
179
  to: new Date(now.getTime() + OCCURRENCE_HORIZON_MS),
183
180
  }).filter((occurrence) => !occurrence.cancelled);
181
+ /** Matches the agenda: a missing end is one hour after start, not open forever. */
182
+ const IMPLIED_EVENT_DURATION_MS = 60 * 60 * 1000;
183
+ export const occurrenceHasEnded = (start, end, now = new Date()) => {
184
+ const startMs = new Date(start).getTime();
185
+ if (!Number.isFinite(startMs))
186
+ return false;
187
+ const explicitEnd = end ? new Date(end).getTime() : Number.NaN;
188
+ const endMs = Number.isFinite(explicitEnd)
189
+ ? explicitEnd
190
+ : startMs + IMPLIED_EVENT_DURATION_MS;
191
+ return endMs < now.getTime();
192
+ };
193
+ const findExpandedOccurrence = (event, recurrenceId) => {
194
+ const anchor = new Date(recurrenceId).getTime();
195
+ if (!Number.isFinite(anchor))
196
+ return undefined;
197
+ return expandEventOccurrences(event, {
198
+ from: new Date(anchor - OCCURRENCE_HORIZON_MS),
199
+ to: new Date(anchor + OCCURRENCE_HORIZON_MS),
200
+ }).find((occurrence) => sameRecurrenceId(occurrence.recurrenceId, recurrenceId));
201
+ };
202
+ const occurrenceClosed = (event, recurrenceId, now) => {
203
+ if (!event.recurrence) {
204
+ return occurrenceHasEnded(event.start, event.end, now);
205
+ }
206
+ const match = findExpandedOccurrence(event, recurrenceId);
207
+ if (!match || match.cancelled)
208
+ return true;
209
+ return occurrenceHasEnded(match.start, match.end, now);
210
+ };
211
+ /** False once the event, or the locked occurrence, is over. */
212
+ export const eventRsvpOpen = (event, options) => {
213
+ const now = options?.now ?? new Date();
214
+ if (options?.lockToOccurrence && options.recurrenceId) {
215
+ return !occurrenceClosed(event, options.recurrenceId, now);
216
+ }
217
+ if (!event.recurrence) {
218
+ return !occurrenceHasEnded(event.start, event.end, now);
219
+ }
220
+ return expandEventOccurrences(event, {
221
+ from: new Date(now.getTime() - OCCURRENCE_HORIZON_MS),
222
+ to: new Date(now.getTime() + OCCURRENCE_HORIZON_MS),
223
+ }).some((occurrence) => !occurrence.cancelled &&
224
+ !occurrenceHasEnded(occurrence.start, occurrence.end, now));
225
+ };
226
+ /**
227
+ * True when every targeted time is already over. A series RSVP with no ids
228
+ * is past only when the series has nothing left open.
229
+ */
230
+ export const rsvpTargetsPastEvent = (event, target, now = new Date()) => {
231
+ const ids = target?.occurrenceIds?.length
232
+ ? target.occurrenceIds
233
+ : target?.recurrenceId
234
+ ? [target.recurrenceId]
235
+ : undefined;
236
+ if (!ids)
237
+ return !eventRsvpOpen(event, { now });
238
+ return ids.every((id) => !eventRsvpOpen(event, {
239
+ recurrenceId: id,
240
+ lockToOccurrence: true,
241
+ now,
242
+ }));
243
+ };
184
244
  export const defaultRsvpRecurrenceId = (event, queryId, now = new Date()) => {
185
- var _a;
186
245
  if (queryId)
187
246
  return normalizeRecurrenceId(queryId);
188
- return (_a = listRsvpOccurrences(event, now)[0]) === null || _a === void 0 ? void 0 : _a.recurrenceId;
247
+ return listRsvpOccurrences(event, now)[0]?.recurrenceId;
189
248
  };
190
249
  export const previewUpcomingOccurrences = (event, count = 3, now = new Date()) => listRsvpOccurrences(event, now).slice(0, count);
191
250
  export const effectiveEventTimes = (event, recurrenceId) => {
@@ -203,9 +262,8 @@ export const effectiveEventTimes = (event, recurrenceId) => {
203
262
  return { start: match.start, end: match.end };
204
263
  };
205
264
  export const upsertEventException = (event, exception) => {
206
- var _a;
207
265
  const recurrenceId = normalizeRecurrenceId(exception.recurrenceId);
208
- const rest = ((_a = event.exceptions) !== null && _a !== void 0 ? _a : []).filter((existing) => !sameRecurrenceId(existing.recurrenceId, recurrenceId));
266
+ const rest = (event.exceptions ?? []).filter((existing) => !sameRecurrenceId(existing.recurrenceId, recurrenceId));
209
267
  return {
210
268
  ...event,
211
269
  exceptions: [...rest, { ...exception, recurrenceId }],
@@ -221,8 +279,7 @@ const formatWeekdayLabels = (days, t) => sortWeekdays(days)
221
279
  .map((day) => t(`events.form.repeat.day.${day}`, { defaultValue: day }))
222
280
  .join(', ');
223
281
  const formatRecurrencePattern = (recurrence, t, start) => {
224
- var _a, _b;
225
- const interval = (_a = recurrence.interval) !== null && _a !== void 0 ? _a : 1;
282
+ const interval = recurrence.interval ?? 1;
226
283
  if (recurrence.freq === 'DAILY') {
227
284
  return interval === 1
228
285
  ? t('events.repeat.daily', { defaultValue: 'Daily' })
@@ -239,7 +296,7 @@ const formatRecurrencePattern = (recurrence, t, start) => {
239
296
  count: interval,
240
297
  });
241
298
  }
242
- const days = ((_b = recurrence.byDay) === null || _b === void 0 ? void 0 : _b.length) && recurrence.byDay.length > 0
299
+ const days = recurrence.byDay?.length && recurrence.byDay.length > 0
243
300
  ? recurrence.byDay
244
301
  : start
245
302
  ? [weekdayFromDate(new Date(start))]
@@ -1,6 +1,6 @@
1
1
  import { isIanaTimeZone } from './timeZone.js';
2
2
  const DATETIME_LOCAL_RE = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2}))?$/;
3
- const partNumber = (parts, type) => { var _a; return Number((_a = parts.find((part) => part.type === type)) === null || _a === void 0 ? void 0 : _a.value); };
3
+ const partNumber = (parts, type) => Number(parts.find((part) => part.type === type)?.value);
4
4
  /** Milliseconds to add to UTC to get wall time in `timeZone` at `utcMs`. */
5
5
  const tzOffsetMs = (utcMs, timeZone) => {
6
6
  const parts = new Intl.DateTimeFormat('en-US', {
@@ -23,7 +23,6 @@ const pad2 = (value) => String(value).padStart(2, '0');
23
23
  * and return a UTC ISO string.
24
24
  */
25
25
  export const zonedDateTimeToUtcIso = (local, timeZone) => {
26
- var _a;
27
26
  if (!local)
28
27
  return undefined;
29
28
  const match = DATETIME_LOCAL_RE.exec(local);
@@ -31,7 +30,7 @@ export const zonedDateTimeToUtcIso = (local, timeZone) => {
31
30
  const parsed = new Date(local);
32
31
  return Number.isNaN(parsed.getTime()) ? undefined : parsed.toISOString();
33
32
  }
34
- const utcGuess = Date.UTC(Number(match[1]), Number(match[2]) - 1, Number(match[3]), Number(match[4]), Number(match[5]), Number((_a = match[6]) !== null && _a !== void 0 ? _a : 0));
33
+ const utcGuess = Date.UTC(Number(match[1]), Number(match[2]) - 1, Number(match[3]), Number(match[4]), Number(match[5]), Number(match[6] ?? 0));
35
34
  try {
36
35
  const offset = tzOffsetMs(utcGuess, timeZone);
37
36
  const utcWithOffset = utcGuess - offset;
@@ -94,9 +93,8 @@ export const utcIsoToWallClockDate = (iso, timeZone) => {
94
93
  };
95
94
  /** Treat `date`'s local components as wall time in `timeZone`. */
96
95
  export const wallClockDateToUtcIso = (date, timeZone) => {
97
- var _a;
98
96
  const local = `${date.getFullYear()}-${pad2(date.getMonth() + 1)}-${pad2(date.getDate())}T${pad2(date.getHours())}:${pad2(date.getMinutes())}`;
99
- return (_a = zonedDateTimeToUtcIso(local, timeZone)) !== null && _a !== void 0 ? _a : date.toISOString();
97
+ return zonedDateTimeToUtcIso(local, timeZone) ?? date.toISOString();
100
98
  };
101
99
  /** Intl `timeZone` option when `timeZone` is a valid IANA identifier. */
102
100
  export const eventTimeZoneOptions = (timeZone) => {
@@ -105,8 +103,8 @@ export const eventTimeZoneOptions = (timeZone) => {
105
103
  };
106
104
  /** Clock time in the event timezone, always including a short zone name. */
107
105
  export const formatEventClockTime = (iso, options) => {
108
- const timeZone = eventTimeZoneOptions(options === null || options === void 0 ? void 0 : options.timeZone).timeZone;
109
- return new Date(iso).toLocaleTimeString(options === null || options === void 0 ? void 0 : options.locale, {
106
+ const timeZone = eventTimeZoneOptions(options?.timeZone).timeZone;
107
+ return new Date(iso).toLocaleTimeString(options?.locale, {
110
108
  hour: '2-digit',
111
109
  minute: '2-digit',
112
110
  timeZoneName: 'short',
@@ -114,7 +112,7 @@ export const formatEventClockTime = (iso, options) => {
114
112
  });
115
113
  };
116
114
  export const formatEventWhen = (start, options) => {
117
- const timeZone = (options === null || options === void 0 ? void 0 : options.timeZone) || undefined;
115
+ const timeZone = options?.timeZone || undefined;
118
116
  const dateOptions = {
119
117
  weekday: 'long',
120
118
  year: 'numeric',
@@ -122,7 +120,7 @@ export const formatEventWhen = (start, options) => {
122
120
  day: 'numeric',
123
121
  ...(timeZone ? { timeZone } : {}),
124
122
  };
125
- if (options === null || options === void 0 ? void 0 : options.allDay) {
123
+ if (options?.allDay) {
126
124
  const startLabel = new Date(start).toLocaleDateString(options.locale, dateOptions);
127
125
  if (!options.end)
128
126
  return startLabel;
@@ -135,8 +133,8 @@ export const formatEventWhen = (start, options) => {
135
133
  minute: '2-digit',
136
134
  ...(timeZone ? { timeZoneName: 'short' } : {}),
137
135
  };
138
- const startLabel = new Date(start).toLocaleString(options === null || options === void 0 ? void 0 : options.locale, dateTimeOptions);
139
- if (!(options === null || options === void 0 ? void 0 : options.end))
136
+ const startLabel = new Date(start).toLocaleString(options?.locale, dateTimeOptions);
137
+ if (!options?.end)
140
138
  return startLabel;
141
139
  const endLabel = new Date(options.end).toLocaleString(options.locale, dateTimeOptions);
142
140
  return `${startLabel} – ${endLabel}`;