@openpeepshq/common 0.6.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/capabilitiesHelpers.d.ts +7 -7
- package/dist/lib/eventIcs.js +58 -15
- package/dist/lib/eventRecurrence.js +3 -3
- package/dist/lib/eventTime.d.ts +2 -0
- package/dist/lib/eventTime.js +2 -0
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.js +1 -0
- package/dist/lib/utils.d.ts +1 -0
- package/dist/lib/utils.js +27 -0
- package/dist/lib/videoEmbed.d.ts +12 -0
- package/dist/lib/videoEmbed.js +105 -0
- package/dist/types/api.d.ts +9 -5
- package/dist/types/auth.d.ts +6 -0
- package/dist/types/db.d.ts +77 -0
- package/dist/types/internal.d.ts +464 -0
- package/dist/types/models.d.ts +8 -0
- package/dist/types/models.js +7 -1
- package/package.json +9 -8
- package/src/lib/eventIcs.ts +71 -15
- package/src/lib/eventRecurrence.ts +3 -3
- package/src/lib/eventTime.ts +4 -0
- package/src/lib/index.ts +1 -0
- package/src/lib/utils.ts +34 -0
- package/src/lib/videoEmbed.ts +116 -0
- package/src/types/models.ts +7 -1
package/dist/types/models.d.ts
CHANGED
|
@@ -264,6 +264,7 @@ export declare const profileResourceTypeSchema: z.ZodEnum<{
|
|
|
264
264
|
groups: "groups";
|
|
265
265
|
reports: "reports";
|
|
266
266
|
webhooks: "webhooks";
|
|
267
|
+
conversations: "conversations";
|
|
267
268
|
}>;
|
|
268
269
|
export type ProfileResourceType = z.infer<typeof profileResourceTypeSchema>;
|
|
269
270
|
export declare const serviceResourceTypeSchema: z.ZodEnum<{
|
|
@@ -288,6 +289,7 @@ export declare const resourceSchema: z.ZodObject<{
|
|
|
288
289
|
groups: "groups";
|
|
289
290
|
reports: "reports";
|
|
290
291
|
webhooks: "webhooks";
|
|
292
|
+
conversations: "conversations";
|
|
291
293
|
analytics: "analytics";
|
|
292
294
|
render: "render";
|
|
293
295
|
}>;
|
|
@@ -321,6 +323,7 @@ export declare const scopeSchema: z.ZodObject<{
|
|
|
321
323
|
groups: "groups";
|
|
322
324
|
reports: "reports";
|
|
323
325
|
webhooks: "webhooks";
|
|
326
|
+
conversations: "conversations";
|
|
324
327
|
analytics: "analytics";
|
|
325
328
|
render: "render";
|
|
326
329
|
}>;
|
|
@@ -410,6 +413,7 @@ export declare const profileDataSchema: z.ZodObject<{
|
|
|
410
413
|
groups: "groups";
|
|
411
414
|
reports: "reports";
|
|
412
415
|
webhooks: "webhooks";
|
|
416
|
+
conversations: "conversations";
|
|
413
417
|
analytics: "analytics";
|
|
414
418
|
render: "render";
|
|
415
419
|
}>;
|
|
@@ -466,6 +470,7 @@ export declare const profileSchema: z.ZodObject<{
|
|
|
466
470
|
groups: "groups";
|
|
467
471
|
reports: "reports";
|
|
468
472
|
webhooks: "webhooks";
|
|
473
|
+
conversations: "conversations";
|
|
469
474
|
analytics: "analytics";
|
|
470
475
|
render: "render";
|
|
471
476
|
}>;
|
|
@@ -539,6 +544,7 @@ export declare const accountWithMetaSchema: z.ZodObject<{
|
|
|
539
544
|
groups: "groups";
|
|
540
545
|
reports: "reports";
|
|
541
546
|
webhooks: "webhooks";
|
|
547
|
+
conversations: "conversations";
|
|
542
548
|
analytics: "analytics";
|
|
543
549
|
render: "render";
|
|
544
550
|
}>;
|
|
@@ -648,6 +654,7 @@ export declare const followSchema: z.ZodObject<{
|
|
|
648
654
|
groups: "groups";
|
|
649
655
|
reports: "reports";
|
|
650
656
|
webhooks: "webhooks";
|
|
657
|
+
conversations: "conversations";
|
|
651
658
|
analytics: "analytics";
|
|
652
659
|
render: "render";
|
|
653
660
|
}>;
|
|
@@ -707,6 +714,7 @@ export declare const followSchema: z.ZodObject<{
|
|
|
707
714
|
groups: "groups";
|
|
708
715
|
reports: "reports";
|
|
709
716
|
webhooks: "webhooks";
|
|
717
|
+
conversations: "conversations";
|
|
710
718
|
analytics: "analytics";
|
|
711
719
|
render: "render";
|
|
712
720
|
}>;
|
package/dist/types/models.js
CHANGED
|
@@ -2,6 +2,7 @@ import { z } from 'zod';
|
|
|
2
2
|
import validator from 'validator';
|
|
3
3
|
import ISO6391 from 'iso-639-1';
|
|
4
4
|
import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi';
|
|
5
|
+
import { isEndBeforeStart } from '../lib/eventTime.js';
|
|
5
6
|
import { groupRelationships } from './capabilities.js';
|
|
6
7
|
import { capabilitiesSchema } from './config.js';
|
|
7
8
|
import { HANDLE_RESERVED_MESSAGE, additionalForbiddenHandlesSchema, classifyAdditionalForbiddenHandle, collectAdditionalForbiddenHandles, forbiddenHandles, handleRegex, handleRegexBase, isDefaultForbiddenHandle, isForbiddenHandle, normalizeForbiddenHandle, } from './forbiddenHandles.js';
|
|
@@ -153,6 +154,7 @@ const profileResourceTypes = [
|
|
|
153
154
|
'reports',
|
|
154
155
|
'webhooks',
|
|
155
156
|
'notifications',
|
|
157
|
+
'conversations',
|
|
156
158
|
];
|
|
157
159
|
export const profileResourceTypeSchema = z.enum(profileResourceTypes);
|
|
158
160
|
const serviceResourceTypes = [
|
|
@@ -420,6 +422,10 @@ export const eventOccurrenceExceptionSchema = z
|
|
|
420
422
|
start: eventIsoDatetimeSchema.optional(),
|
|
421
423
|
end: eventIsoDatetimeSchema.optional(),
|
|
422
424
|
physicalLocation: locationSchema.optional(),
|
|
425
|
+
})
|
|
426
|
+
.refine((exception) => !isEndBeforeStart(exception.start, exception.end), {
|
|
427
|
+
message: 'events.form.endBeforeStart',
|
|
428
|
+
path: ['end'],
|
|
423
429
|
})
|
|
424
430
|
.openapi('EventOccurrenceException');
|
|
425
431
|
export const eventSchema = noteSchema
|
|
@@ -442,7 +448,7 @@ export const eventSchema = noteSchema
|
|
|
442
448
|
recurrence: eventRecurrenceSchema.optional(),
|
|
443
449
|
exceptions: eventOccurrenceExceptionSchema.array().optional(),
|
|
444
450
|
})
|
|
445
|
-
.refine((data) => !data.
|
|
451
|
+
.refine((data) => !isEndBeforeStart(data.start, data.end), {
|
|
446
452
|
message: 'events.form.endBeforeStart',
|
|
447
453
|
path: ['end'],
|
|
448
454
|
})
|
package/package.json
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpeepshq/common",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@asteasolutions/zod-to-openapi": "^8.5.0",
|
|
9
|
+
"@date-fns/tz": "^1.5.0",
|
|
9
10
|
"date-fns": "^4.1.0",
|
|
10
|
-
"ical-generator": "^
|
|
11
|
+
"ical-generator": "^11.1.3",
|
|
11
12
|
"iso-639-1": "^3.1.5",
|
|
12
13
|
"jose": "^6.2.2",
|
|
14
|
+
"timezones-ical-library": "^2.4.0",
|
|
13
15
|
"type-fest": "^5.5.0",
|
|
14
16
|
"validator": "^13.15.35",
|
|
15
|
-
"zod": "^4.
|
|
17
|
+
"zod": "^4.6.6"
|
|
16
18
|
},
|
|
17
19
|
"main": "./dist/index.js",
|
|
18
20
|
"types": "./dist/index.d.ts",
|
|
@@ -57,10 +59,9 @@
|
|
|
57
59
|
"@types/validator": "^13.15.10",
|
|
58
60
|
"@typescript-eslint/eslint-plugin": "^8.72.0",
|
|
59
61
|
"@typescript-eslint/parser": "^8.72.0",
|
|
60
|
-
"@vitest/coverage-v8": "^
|
|
61
|
-
"@vitest/ui": "^
|
|
62
|
-
"
|
|
63
|
-
"eslint": "^10.1.0",
|
|
62
|
+
"@vitest/coverage-v8": "^4.1.12",
|
|
63
|
+
"@vitest/ui": "^4.1.12",
|
|
64
|
+
"eslint": "^10.14.0",
|
|
64
65
|
"eslint-config-prettier": "^9.1.0",
|
|
65
66
|
"i18next": "^26.0.3",
|
|
66
67
|
"livekit-client": "^2.19.2",
|
|
@@ -68,7 +69,7 @@
|
|
|
68
69
|
"tsc-alias": "^1.8.16",
|
|
69
70
|
"typed-emitter": "^2.1.0",
|
|
70
71
|
"typescript": "^6.0.2",
|
|
71
|
-
"vitest": "^
|
|
72
|
+
"vitest": "^4.1.12"
|
|
72
73
|
},
|
|
73
74
|
"scripts": {
|
|
74
75
|
"lint": "eslint .",
|
package/src/lib/eventIcs.ts
CHANGED
|
@@ -3,9 +3,12 @@ import ical, {
|
|
|
3
3
|
ICalEventRepeatingFreq,
|
|
4
4
|
ICalWeekday,
|
|
5
5
|
} from 'ical-generator';
|
|
6
|
+
import { TZDate } from '@date-fns/tz';
|
|
7
|
+
import { tzlib_get_ical_block } from 'timezones-ical-library';
|
|
6
8
|
import type { Event, PublicPost, RecurrenceWeekday } from '../types';
|
|
7
9
|
import { effectiveEventTimes } from './eventRecurrence';
|
|
8
10
|
import { getJamUrl } from './jamHelpers';
|
|
11
|
+
import { isIanaTimeZone } from './timeZone';
|
|
9
12
|
|
|
10
13
|
const utcDateFromYmd = (yyyyMmDd: string): Date => {
|
|
11
14
|
const [y, m, d] = yyyyMmDd.split('-').map(Number);
|
|
@@ -18,6 +21,45 @@ const exclusiveEndAfterInclusiveDay = (yyyyMmDd: string): Date => {
|
|
|
18
21
|
return dt;
|
|
19
22
|
};
|
|
20
23
|
|
|
24
|
+
/**
|
|
25
|
+
* The event's stored IANA zone when it is one; ical-generator writes any
|
|
26
|
+
* `timezone` string verbatim into `TZID=`, so non-IANA values fall back to
|
|
27
|
+
* UTC output here.
|
|
28
|
+
*/
|
|
29
|
+
const eventTimeZone = (event: Event): string | undefined =>
|
|
30
|
+
isIanaTimeZone(event.timeZone) ? event.timeZone : undefined;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A zone-aware Date: ical-generator formats a TZDate's wall-clock components
|
|
34
|
+
* in the event's zone, so the host's local zone (and its DST gaps) never
|
|
35
|
+
* shifts the exported time.
|
|
36
|
+
*/
|
|
37
|
+
const instantInZone = (iso: string, timeZone?: string): Date =>
|
|
38
|
+
timeZone ? new TZDate(iso, timeZone) : new Date(iso);
|
|
39
|
+
|
|
40
|
+
/** The default 1-hour end keeps the event's zone (or UTC). */
|
|
41
|
+
const defaultEnd = (start: Date, timeZone?: string): Date =>
|
|
42
|
+
timeZone
|
|
43
|
+
? new TZDate(start.getTime() + 60 * 60 * 1000, timeZone)
|
|
44
|
+
: new Date(start.getTime() + 60 * 60 * 1000);
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* RFC 5545 requires a VTIMEZONE for every TZID used. ical-generator only
|
|
48
|
+
* emits one via a calendar-level timezone, which in v10 also re-zones
|
|
49
|
+
* UNTIL and DTSTAMP (both of which must stay UTC), so the component is
|
|
50
|
+
* spliced in before the first VEVENT instead.
|
|
51
|
+
*/
|
|
52
|
+
const withVtimezone = (calendarText: string, timeZone: string): string => {
|
|
53
|
+
const [block] = tzlib_get_ical_block(timeZone) as [string, string];
|
|
54
|
+
const normalized = block.replace(/\r?\n/g, '\r\n').trim() + '\r\n';
|
|
55
|
+
const veventIndex = calendarText.indexOf('BEGIN:VEVENT');
|
|
56
|
+
return (
|
|
57
|
+
calendarText.slice(0, veventIndex) +
|
|
58
|
+
normalized +
|
|
59
|
+
calendarText.slice(veventIndex)
|
|
60
|
+
);
|
|
61
|
+
};
|
|
62
|
+
|
|
21
63
|
const originFromUrl = (url?: string): string | undefined => {
|
|
22
64
|
if (!url) {
|
|
23
65
|
return undefined;
|
|
@@ -67,12 +109,12 @@ const repeatingWeekday: Record<RecurrenceWeekday, ICalWeekday> = {
|
|
|
67
109
|
SU: ICalWeekday.SU,
|
|
68
110
|
};
|
|
69
111
|
|
|
70
|
-
const repeatingOptions = (event: Event) => {
|
|
112
|
+
const repeatingOptions = (event: Event, timeZone?: string) => {
|
|
71
113
|
const recurrence = event.recurrence;
|
|
72
114
|
if (!recurrence) return undefined;
|
|
73
115
|
const exclude = (event.exceptions ?? [])
|
|
74
116
|
.filter((exception) => exception.cancelled)
|
|
75
|
-
.map((exception) =>
|
|
117
|
+
.map((exception) => instantInZone(exception.recurrenceId, timeZone));
|
|
76
118
|
return {
|
|
77
119
|
freq: repeatingFreq[recurrence.freq],
|
|
78
120
|
interval: recurrence.interval ?? 1,
|
|
@@ -104,7 +146,10 @@ export const buildEventIcs = (
|
|
|
104
146
|
const summary = event.name?.trim() || 'Event';
|
|
105
147
|
const description = event.content?.trim();
|
|
106
148
|
const location = eventLocation(post, event, options?.postUrl);
|
|
107
|
-
|
|
149
|
+
// Timed events keep the event's own zone; all-day events use DATE values
|
|
150
|
+
// and carry no zone.
|
|
151
|
+
const timeZone = event.wholeDay ? undefined : eventTimeZone(event);
|
|
152
|
+
const repeating = repeatingOptions(event, timeZone);
|
|
108
153
|
|
|
109
154
|
if (event.wholeDay) {
|
|
110
155
|
const startYmd = event.start.slice(0, 10);
|
|
@@ -121,14 +166,15 @@ export const buildEventIcs = (
|
|
|
121
166
|
...(repeating ? { repeating } : {}),
|
|
122
167
|
});
|
|
123
168
|
} else {
|
|
124
|
-
const start =
|
|
169
|
+
const start = instantInZone(event.start, timeZone);
|
|
125
170
|
const end = event.end
|
|
126
|
-
?
|
|
127
|
-
:
|
|
171
|
+
? instantInZone(event.end, timeZone)
|
|
172
|
+
: defaultEnd(start, timeZone);
|
|
128
173
|
calendar.createEvent({
|
|
129
174
|
id: `openpeeps-event-${post.id}@openpeepshq`,
|
|
130
175
|
start,
|
|
131
176
|
end,
|
|
177
|
+
...(timeZone ? { timezone: timeZone } : {}),
|
|
132
178
|
summary,
|
|
133
179
|
...(description ? { description } : {}),
|
|
134
180
|
...(location ? { location } : {}),
|
|
@@ -139,23 +185,27 @@ export const buildEventIcs = (
|
|
|
139
185
|
|
|
140
186
|
for (const exception of event.exceptions ?? []) {
|
|
141
187
|
if (exception.cancelled || !exception.start) continue;
|
|
142
|
-
const start =
|
|
188
|
+
const start = instantInZone(exception.start, timeZone);
|
|
143
189
|
const end = exception.end
|
|
144
|
-
?
|
|
145
|
-
:
|
|
190
|
+
? instantInZone(exception.end, timeZone)
|
|
191
|
+
: defaultEnd(start, timeZone);
|
|
146
192
|
calendar.createEvent({
|
|
147
193
|
id: `openpeeps-event-${post.id}-${exception.recurrenceId}@openpeepshq`,
|
|
148
194
|
start,
|
|
149
195
|
end,
|
|
196
|
+
...(timeZone ? { timezone: timeZone } : {}),
|
|
150
197
|
summary,
|
|
151
198
|
...(description ? { description } : {}),
|
|
152
199
|
...(location ? { location } : {}),
|
|
153
200
|
...(link ? { url: link } : {}),
|
|
154
|
-
recurrenceId:
|
|
201
|
+
recurrenceId: instantInZone(exception.recurrenceId, timeZone),
|
|
155
202
|
});
|
|
156
203
|
}
|
|
157
204
|
|
|
158
|
-
|
|
205
|
+
const calendarText = calendar.toString();
|
|
206
|
+
return (
|
|
207
|
+
(timeZone ? withVtimezone(calendarText, timeZone) : calendarText) + '\r\n'
|
|
208
|
+
);
|
|
159
209
|
};
|
|
160
210
|
|
|
161
211
|
const addOccurrenceEvent = (
|
|
@@ -171,6 +221,7 @@ const addOccurrenceEvent = (
|
|
|
171
221
|
const location = eventLocation(post, event, options?.postUrl);
|
|
172
222
|
const times = effectiveEventTimes(event, recurrenceId);
|
|
173
223
|
const id = `openpeeps-event-${post.id}-${recurrenceId}@openpeepshq`;
|
|
224
|
+
const timeZone = event.wholeDay ? undefined : eventTimeZone(event);
|
|
174
225
|
|
|
175
226
|
if (event.wholeDay) {
|
|
176
227
|
const startYmd = times.start.slice(0, 10);
|
|
@@ -188,14 +239,15 @@ const addOccurrenceEvent = (
|
|
|
188
239
|
return;
|
|
189
240
|
}
|
|
190
241
|
|
|
191
|
-
const start =
|
|
242
|
+
const start = instantInZone(times.start, timeZone);
|
|
192
243
|
const end = times.end
|
|
193
|
-
?
|
|
194
|
-
:
|
|
244
|
+
? instantInZone(times.end, timeZone)
|
|
245
|
+
: defaultEnd(start, timeZone);
|
|
195
246
|
calendar.createEvent({
|
|
196
247
|
id,
|
|
197
248
|
start,
|
|
198
249
|
end,
|
|
250
|
+
...(timeZone ? { timezone: timeZone } : {}),
|
|
199
251
|
summary,
|
|
200
252
|
...(description ? { description } : {}),
|
|
201
253
|
...(location ? { location } : {}),
|
|
@@ -227,7 +279,11 @@ export const buildRsvpIcs = (
|
|
|
227
279
|
addOccurrenceEvent(calendar, post, event, recurrenceId, options);
|
|
228
280
|
}
|
|
229
281
|
|
|
230
|
-
|
|
282
|
+
const timeZone = event.wholeDay ? undefined : eventTimeZone(event);
|
|
283
|
+
const calendarText = calendar.toString();
|
|
284
|
+
return (
|
|
285
|
+
(timeZone ? withVtimezone(calendarText, timeZone) : calendarText) + '\r\n'
|
|
286
|
+
);
|
|
231
287
|
};
|
|
232
288
|
|
|
233
289
|
export const rsvpConfirmationContent = (
|
|
@@ -437,7 +437,7 @@ const formatRecurrencePattern = (
|
|
|
437
437
|
|
|
438
438
|
if (recurrence.freq === 'DAILY') {
|
|
439
439
|
return interval === 1
|
|
440
|
-
? t('events.repeat.daily', { defaultValue: 'Daily' })
|
|
440
|
+
? t('events.form.repeat.daily', { defaultValue: 'Daily' })
|
|
441
441
|
: t('events.repeat.everyNDays', {
|
|
442
442
|
defaultValue: 'Every {{count}} days',
|
|
443
443
|
count: interval,
|
|
@@ -446,7 +446,7 @@ const formatRecurrencePattern = (
|
|
|
446
446
|
|
|
447
447
|
if (recurrence.freq === 'MONTHLY') {
|
|
448
448
|
return interval === 1
|
|
449
|
-
? t('events.repeat.monthly', { defaultValue: 'Monthly' })
|
|
449
|
+
? t('events.form.repeat.monthly', { defaultValue: 'Monthly' })
|
|
450
450
|
: t('events.repeat.everyNMonths', {
|
|
451
451
|
defaultValue: 'Every {{count}} months',
|
|
452
452
|
count: interval,
|
|
@@ -475,7 +475,7 @@ const formatRecurrencePattern = (
|
|
|
475
475
|
}
|
|
476
476
|
|
|
477
477
|
return interval === 1
|
|
478
|
-
? t('events.repeat.weekly', { defaultValue: 'Weekly' })
|
|
478
|
+
? t('events.form.repeat.weekly', { defaultValue: 'Weekly' })
|
|
479
479
|
: t('events.repeat.everyNWeeks', {
|
|
480
480
|
defaultValue: 'Every {{count}} weeks',
|
|
481
481
|
count: interval,
|
package/src/lib/eventTime.ts
CHANGED
|
@@ -34,6 +34,10 @@ const tzOffsetMs = (utcMs: number, timeZone: string): number => {
|
|
|
34
34
|
|
|
35
35
|
const pad2 = (value: number): string => String(value).padStart(2, '0');
|
|
36
36
|
|
|
37
|
+
/** True when `end` is set and not after `start` (equal times are invalid). */
|
|
38
|
+
export const isEndBeforeStart = (start?: string, end?: string) =>
|
|
39
|
+
Boolean(start && end && new Date(end) <= new Date(start));
|
|
40
|
+
|
|
37
41
|
/**
|
|
38
42
|
* Interpret a datetime-local wall clock (`YYYY-MM-DDTHH:mm`) in `timeZone`
|
|
39
43
|
* and return a UTC ISO string.
|
package/src/lib/index.ts
CHANGED
package/src/lib/utils.ts
CHANGED
|
@@ -104,6 +104,8 @@ export const getUniqueBy = <T, V = string>(
|
|
|
104
104
|
return arr.filter((o) => !set.has(predicate(o)) && set.add(predicate(o)));
|
|
105
105
|
};
|
|
106
106
|
|
|
107
|
+
const UNSAFE_KEYS = new Set(['__proto__', 'prototype', 'constructor']);
|
|
108
|
+
|
|
107
109
|
export const interpolate = (
|
|
108
110
|
text: string | undefined,
|
|
109
111
|
params: Record<string, string> = {},
|
|
@@ -113,6 +115,20 @@ export const interpolate = (
|
|
|
113
115
|
|
|
114
116
|
const names = Object.keys(params);
|
|
115
117
|
const vals = Object.values(params);
|
|
118
|
+
|
|
119
|
+
// Sanitize: reject param values that would produce unsafe jsonpath keys.
|
|
120
|
+
// jsonpath 1.3.0 throws "Unsafe key" for __proto__/prototype/constructor,
|
|
121
|
+
// which would cause an unhandled 500 in the SSO handler.
|
|
122
|
+
for (const val of vals) {
|
|
123
|
+
if (UNSAFE_KEYS.has(val)) {
|
|
124
|
+
throw new Error(
|
|
125
|
+
`Interpolated value "${val}" matches an unsafe key (` +
|
|
126
|
+
[...UNSAFE_KEYS].join(', ') +
|
|
127
|
+
`) — this would trigger a jsonpath parse error`,
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
116
132
|
return new Function(...names, `return \`${text}\`;`)(...vals);
|
|
117
133
|
} catch {
|
|
118
134
|
throw new Error(
|
|
@@ -170,6 +186,24 @@ export const deepGet = (obj: unknown, path: (string | number)[]) =>
|
|
|
170
186
|
// @ts-expect-error deepget is not typeable
|
|
171
187
|
path.reduce((o, i) => o[i], obj);
|
|
172
188
|
|
|
189
|
+
export const deepEqual = (a: unknown, b: unknown): boolean => {
|
|
190
|
+
if (a === b) return true;
|
|
191
|
+
if (typeof a !== 'object' || typeof b !== 'object') return false;
|
|
192
|
+
if (a === null || b === null) return false;
|
|
193
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
194
|
+
const keysA = Object.keys(a);
|
|
195
|
+
const keysB = Object.keys(b);
|
|
196
|
+
if (keysA.length !== keysB.length) return false;
|
|
197
|
+
return keysA.every(
|
|
198
|
+
(key) =>
|
|
199
|
+
Object.prototype.hasOwnProperty.call(b, key) &&
|
|
200
|
+
deepEqual(
|
|
201
|
+
(a as Record<string, unknown>)[key],
|
|
202
|
+
(b as Record<string, unknown>)[key],
|
|
203
|
+
),
|
|
204
|
+
);
|
|
205
|
+
};
|
|
206
|
+
|
|
173
207
|
/**
|
|
174
208
|
* Checks if a value is valid => not (null, undefined, empty, etc.)
|
|
175
209
|
* Special case: treats 0 as a valid value unlike standard JS truthiness
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
const YOUTUBE_ID_RE = /^[A-Za-z0-9_-]{6,15}$/;
|
|
2
|
+
const VIMEO_ID_RE = /^\d{6,}$/;
|
|
3
|
+
const YOUTUBE_ORIGIN = 'https://www.youtube-nocookie.com';
|
|
4
|
+
const VIMEO_ORIGIN = 'https://player.vimeo.com';
|
|
5
|
+
|
|
6
|
+
export interface VideoEmbed {
|
|
7
|
+
provider: 'youtube' | 'vimeo';
|
|
8
|
+
embedUrl: string;
|
|
9
|
+
/** Origin of `embedUrl`, for same-origin checks in WebView guards. */
|
|
10
|
+
origin: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Maps a YouTube `t=`/`start=` timestamp to seconds. Accepts `42`, `42s`,
|
|
15
|
+
* `1:30`, `1m30s`, and `1h2m3s` forms.
|
|
16
|
+
*/
|
|
17
|
+
const parseYouTubeStart = (raw: string): number | undefined => {
|
|
18
|
+
const trimmed = raw.trim();
|
|
19
|
+
if (trimmed === '') return undefined;
|
|
20
|
+
if (/^\d+$/.test(trimmed)) return Number(trimmed);
|
|
21
|
+
const compact = trimmed.match(/^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?$/);
|
|
22
|
+
if (compact) {
|
|
23
|
+
const [, hours, minutes, seconds] = compact;
|
|
24
|
+
if (!hours && !minutes && !seconds) return undefined;
|
|
25
|
+
return (
|
|
26
|
+
Number(hours ?? 0) * 3600 +
|
|
27
|
+
Number(minutes ?? 0) * 60 +
|
|
28
|
+
Number(seconds ?? 0)
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
const parts = trimmed.split(':');
|
|
32
|
+
if (parts.length > 3 || parts.some((part) => !/^\d+$/.test(part))) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
return parts.reduce((total, part) => total * 60 + Number(part), 0);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const youtubeEmbed = (id: string, parsed: URL): VideoEmbed => {
|
|
39
|
+
const rawStart =
|
|
40
|
+
parsed.searchParams.get('t') ?? parsed.searchParams.get('start');
|
|
41
|
+
const start = rawStart ? parseYouTubeStart(rawStart) : undefined;
|
|
42
|
+
return {
|
|
43
|
+
provider: 'youtube',
|
|
44
|
+
embedUrl:
|
|
45
|
+
`${YOUTUBE_ORIGIN}/embed/${id}` +
|
|
46
|
+
(start !== undefined && start > 0 ? `?start=${start}` : ''),
|
|
47
|
+
origin: YOUTUBE_ORIGIN,
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Embed info for plain video URLs on supported providers (YouTube
|
|
53
|
+
* watch/share/shorts/embed, Vimeo). Lets the client render a playable
|
|
54
|
+
* player instead of a link card.
|
|
55
|
+
*/
|
|
56
|
+
export const videoEmbedForUrl = (url: string): VideoEmbed | undefined => {
|
|
57
|
+
let parsed: URL;
|
|
58
|
+
try {
|
|
59
|
+
parsed = new URL(url);
|
|
60
|
+
} catch {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
const host = parsed.hostname.replace(/^(www|m)\./, '');
|
|
64
|
+
|
|
65
|
+
if (host === 'youtu.be') {
|
|
66
|
+
const id = parsed.pathname.split('/')[1] ?? '';
|
|
67
|
+
return YOUTUBE_ID_RE.test(id) ? youtubeEmbed(id, parsed) : undefined;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (host === 'youtube.com') {
|
|
71
|
+
const segments = parsed.pathname.split('/').filter(Boolean);
|
|
72
|
+
let id: string | undefined;
|
|
73
|
+
if (segments[0] === 'watch') {
|
|
74
|
+
id = parsed.searchParams.get('v') ?? undefined;
|
|
75
|
+
} else if (segments[0] === 'shorts' || segments[0] === 'embed') {
|
|
76
|
+
id = segments[1];
|
|
77
|
+
}
|
|
78
|
+
return id && YOUTUBE_ID_RE.test(id) ? youtubeEmbed(id, parsed) : undefined;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (host === 'vimeo.com' || host === 'player.vimeo.com') {
|
|
82
|
+
const segments = parsed.pathname.split('/').filter(Boolean);
|
|
83
|
+
let id: string | undefined;
|
|
84
|
+
let hash: string | undefined;
|
|
85
|
+
if (host === 'player.vimeo.com') {
|
|
86
|
+
if (segments[0] === 'video') {
|
|
87
|
+
id = segments[1];
|
|
88
|
+
hash = parsed.searchParams.get('h') ?? undefined;
|
|
89
|
+
}
|
|
90
|
+
} else if (segments.length === 1) {
|
|
91
|
+
id = segments[0];
|
|
92
|
+
} else if (segments.length === 2 && VIMEO_ID_RE.test(segments[0])) {
|
|
93
|
+
// `vimeo.com/<id>/<hash>` — unlisted videos carry the privacy hash
|
|
94
|
+
// in the path.
|
|
95
|
+
id = segments[0];
|
|
96
|
+
hash = segments[1];
|
|
97
|
+
} else if (segments.length === 3 && segments[0] === 'channels') {
|
|
98
|
+
id = segments[2];
|
|
99
|
+
} else if (
|
|
100
|
+
segments.length === 4 &&
|
|
101
|
+
segments[0] === 'groups' &&
|
|
102
|
+
segments[2] === 'videos'
|
|
103
|
+
) {
|
|
104
|
+
id = segments[3];
|
|
105
|
+
}
|
|
106
|
+
if (!id || !VIMEO_ID_RE.test(id)) return undefined;
|
|
107
|
+
return {
|
|
108
|
+
provider: 'vimeo',
|
|
109
|
+
embedUrl:
|
|
110
|
+
`${VIMEO_ORIGIN}/video/${id}?dnt=1` + (hash ? `&h=${hash}` : ''),
|
|
111
|
+
origin: VIMEO_ORIGIN,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return undefined;
|
|
116
|
+
};
|
package/src/types/models.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { z, util, ZodObject, ZodRawShape } from 'zod';
|
|
|
2
2
|
import validator from 'validator';
|
|
3
3
|
import ISO6391 from 'iso-639-1';
|
|
4
4
|
import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi';
|
|
5
|
+
import { isEndBeforeStart } from '../lib/eventTime';
|
|
5
6
|
import { groupRelationships } from './capabilities';
|
|
6
7
|
import { capabilitiesSchema } from './config';
|
|
7
8
|
import {
|
|
@@ -235,6 +236,7 @@ const profileResourceTypes = [
|
|
|
235
236
|
'reports',
|
|
236
237
|
'webhooks',
|
|
237
238
|
'notifications',
|
|
239
|
+
'conversations',
|
|
238
240
|
] as const;
|
|
239
241
|
|
|
240
242
|
export const profileResourceTypeSchema = z.enum(profileResourceTypes);
|
|
@@ -596,6 +598,10 @@ export const eventOccurrenceExceptionSchema = z
|
|
|
596
598
|
end: eventIsoDatetimeSchema.optional(),
|
|
597
599
|
physicalLocation: locationSchema.optional(),
|
|
598
600
|
})
|
|
601
|
+
.refine((exception) => !isEndBeforeStart(exception.start, exception.end), {
|
|
602
|
+
message: 'events.form.endBeforeStart',
|
|
603
|
+
path: ['end'],
|
|
604
|
+
})
|
|
599
605
|
.openapi('EventOccurrenceException');
|
|
600
606
|
export type EventOccurrenceException = z.infer<
|
|
601
607
|
typeof eventOccurrenceExceptionSchema
|
|
@@ -621,7 +627,7 @@ export const eventSchema = noteSchema
|
|
|
621
627
|
recurrence: eventRecurrenceSchema.optional(),
|
|
622
628
|
exceptions: eventOccurrenceExceptionSchema.array().optional(),
|
|
623
629
|
})
|
|
624
|
-
.refine((data) => !data.
|
|
630
|
+
.refine((data) => !isEndBeforeStart(data.start, data.end), {
|
|
625
631
|
message: 'events.form.endBeforeStart',
|
|
626
632
|
path: ['end'],
|
|
627
633
|
})
|