@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
|
@@ -48,7 +48,7 @@ export declare const checkGroupCapabilities: (authData: AuthorizationData, neede
|
|
|
48
48
|
missingCapabilities: string[];
|
|
49
49
|
missingScope: {
|
|
50
50
|
resource: {
|
|
51
|
-
type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
|
|
51
|
+
type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "conversations" | "analytics" | "render";
|
|
52
52
|
id?: string | undefined;
|
|
53
53
|
};
|
|
54
54
|
scopeLevel?: "admin" | "write" | "read" | undefined;
|
|
@@ -59,7 +59,7 @@ export declare const checkPostCapabilities: (authData: AuthorizationData, needed
|
|
|
59
59
|
missingCapabilities: string[];
|
|
60
60
|
missingScope: {
|
|
61
61
|
resource: {
|
|
62
|
-
type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
|
|
62
|
+
type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "conversations" | "analytics" | "render";
|
|
63
63
|
id?: string | undefined;
|
|
64
64
|
};
|
|
65
65
|
scopeLevel?: "admin" | "write" | "read" | undefined;
|
|
@@ -70,7 +70,7 @@ export declare const checkProfileCapabilities: (authData: AuthorizationData, nee
|
|
|
70
70
|
missingCapabilities: string[];
|
|
71
71
|
missingScope: {
|
|
72
72
|
resource: {
|
|
73
|
-
type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
|
|
73
|
+
type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "conversations" | "analytics" | "render";
|
|
74
74
|
id?: string | undefined;
|
|
75
75
|
};
|
|
76
76
|
scopeLevel?: "admin" | "write" | "read" | undefined;
|
|
@@ -81,7 +81,7 @@ export declare const checkReportCapabilities: (authData: AuthorizationData, need
|
|
|
81
81
|
missingCapabilities: string[];
|
|
82
82
|
missingScope: {
|
|
83
83
|
resource: {
|
|
84
|
-
type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
|
|
84
|
+
type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "conversations" | "analytics" | "render";
|
|
85
85
|
id?: string | undefined;
|
|
86
86
|
};
|
|
87
87
|
scopeLevel?: "admin" | "write" | "read" | undefined;
|
|
@@ -92,7 +92,7 @@ export declare const checkAccessTokenCapabilities: (authData: AuthorizationData,
|
|
|
92
92
|
missingCapabilities: string[];
|
|
93
93
|
missingScope: {
|
|
94
94
|
resource: {
|
|
95
|
-
type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
|
|
95
|
+
type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "conversations" | "analytics" | "render";
|
|
96
96
|
id?: string | undefined;
|
|
97
97
|
};
|
|
98
98
|
scopeLevel?: "admin" | "write" | "read" | undefined;
|
|
@@ -103,7 +103,7 @@ export declare const checkAccountCapabilities: (authData: AuthorizationData, nee
|
|
|
103
103
|
missingCapabilities: string[];
|
|
104
104
|
missingScope: {
|
|
105
105
|
resource: {
|
|
106
|
-
type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
|
|
106
|
+
type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "conversations" | "analytics" | "render";
|
|
107
107
|
id?: string | undefined;
|
|
108
108
|
};
|
|
109
109
|
scopeLevel?: "admin" | "write" | "read" | undefined;
|
|
@@ -121,7 +121,7 @@ export declare const checkAccountCreateAuthorization: (authData: AuthorizationDa
|
|
|
121
121
|
missingCapabilities: string[];
|
|
122
122
|
missingScope: {
|
|
123
123
|
resource: {
|
|
124
|
-
type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
|
|
124
|
+
type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "conversations" | "analytics" | "render";
|
|
125
125
|
id?: string | undefined;
|
|
126
126
|
};
|
|
127
127
|
scopeLevel?: "admin" | "write" | "read" | undefined;
|
package/dist/lib/eventIcs.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import ical, { ICalCalendarMethod, ICalEventRepeatingFreq, ICalWeekday, } from 'ical-generator';
|
|
2
|
+
import { TZDate } from '@date-fns/tz';
|
|
3
|
+
import { tzlib_get_ical_block } from 'timezones-ical-library';
|
|
2
4
|
import { effectiveEventTimes } from './eventRecurrence.js';
|
|
3
5
|
import { getJamUrl } from './jamHelpers.js';
|
|
6
|
+
import { isIanaTimeZone } from './timeZone.js';
|
|
4
7
|
const utcDateFromYmd = (yyyyMmDd) => {
|
|
5
8
|
const [y, m, d] = yyyyMmDd.split('-').map(Number);
|
|
6
9
|
return new Date(Date.UTC(y, m - 1, d));
|
|
@@ -10,6 +13,36 @@ const exclusiveEndAfterInclusiveDay = (yyyyMmDd) => {
|
|
|
10
13
|
dt.setUTCDate(dt.getUTCDate() + 1);
|
|
11
14
|
return dt;
|
|
12
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* The event's stored IANA zone when it is one; ical-generator writes any
|
|
18
|
+
* `timezone` string verbatim into `TZID=`, so non-IANA values fall back to
|
|
19
|
+
* UTC output here.
|
|
20
|
+
*/
|
|
21
|
+
const eventTimeZone = (event) => isIanaTimeZone(event.timeZone) ? event.timeZone : undefined;
|
|
22
|
+
/**
|
|
23
|
+
* A zone-aware Date: ical-generator formats a TZDate's wall-clock components
|
|
24
|
+
* in the event's zone, so the host's local zone (and its DST gaps) never
|
|
25
|
+
* shifts the exported time.
|
|
26
|
+
*/
|
|
27
|
+
const instantInZone = (iso, timeZone) => timeZone ? new TZDate(iso, timeZone) : new Date(iso);
|
|
28
|
+
/** The default 1-hour end keeps the event's zone (or UTC). */
|
|
29
|
+
const defaultEnd = (start, timeZone) => timeZone
|
|
30
|
+
? new TZDate(start.getTime() + 60 * 60 * 1000, timeZone)
|
|
31
|
+
: new Date(start.getTime() + 60 * 60 * 1000);
|
|
32
|
+
/**
|
|
33
|
+
* RFC 5545 requires a VTIMEZONE for every TZID used. ical-generator only
|
|
34
|
+
* emits one via a calendar-level timezone, which in v10 also re-zones
|
|
35
|
+
* UNTIL and DTSTAMP (both of which must stay UTC), so the component is
|
|
36
|
+
* spliced in before the first VEVENT instead.
|
|
37
|
+
*/
|
|
38
|
+
const withVtimezone = (calendarText, timeZone) => {
|
|
39
|
+
const [block] = tzlib_get_ical_block(timeZone);
|
|
40
|
+
const normalized = block.replace(/\r?\n/g, '\r\n').trim() + '\r\n';
|
|
41
|
+
const veventIndex = calendarText.indexOf('BEGIN:VEVENT');
|
|
42
|
+
return (calendarText.slice(0, veventIndex) +
|
|
43
|
+
normalized +
|
|
44
|
+
calendarText.slice(veventIndex));
|
|
45
|
+
};
|
|
13
46
|
const originFromUrl = (url) => {
|
|
14
47
|
if (!url) {
|
|
15
48
|
return undefined;
|
|
@@ -49,13 +82,13 @@ const repeatingWeekday = {
|
|
|
49
82
|
SA: ICalWeekday.SA,
|
|
50
83
|
SU: ICalWeekday.SU,
|
|
51
84
|
};
|
|
52
|
-
const repeatingOptions = (event) => {
|
|
85
|
+
const repeatingOptions = (event, timeZone) => {
|
|
53
86
|
const recurrence = event.recurrence;
|
|
54
87
|
if (!recurrence)
|
|
55
88
|
return undefined;
|
|
56
89
|
const exclude = (event.exceptions ?? [])
|
|
57
90
|
.filter((exception) => exception.cancelled)
|
|
58
|
-
.map((exception) =>
|
|
91
|
+
.map((exception) => instantInZone(exception.recurrenceId, timeZone));
|
|
59
92
|
return {
|
|
60
93
|
freq: repeatingFreq[recurrence.freq],
|
|
61
94
|
interval: recurrence.interval ?? 1,
|
|
@@ -81,7 +114,10 @@ export const buildEventIcs = (post, options) => {
|
|
|
81
114
|
const summary = event.name?.trim() || 'Event';
|
|
82
115
|
const description = event.content?.trim();
|
|
83
116
|
const location = eventLocation(post, event, options?.postUrl);
|
|
84
|
-
|
|
117
|
+
// Timed events keep the event's own zone; all-day events use DATE values
|
|
118
|
+
// and carry no zone.
|
|
119
|
+
const timeZone = event.wholeDay ? undefined : eventTimeZone(event);
|
|
120
|
+
const repeating = repeatingOptions(event, timeZone);
|
|
85
121
|
if (event.wholeDay) {
|
|
86
122
|
const startYmd = event.start.slice(0, 10);
|
|
87
123
|
const lastInclusiveYmd = event.end?.slice(0, 10) ?? startYmd;
|
|
@@ -98,14 +134,15 @@ export const buildEventIcs = (post, options) => {
|
|
|
98
134
|
});
|
|
99
135
|
}
|
|
100
136
|
else {
|
|
101
|
-
const start =
|
|
137
|
+
const start = instantInZone(event.start, timeZone);
|
|
102
138
|
const end = event.end
|
|
103
|
-
?
|
|
104
|
-
:
|
|
139
|
+
? instantInZone(event.end, timeZone)
|
|
140
|
+
: defaultEnd(start, timeZone);
|
|
105
141
|
calendar.createEvent({
|
|
106
142
|
id: `openpeeps-event-${post.id}@openpeepshq`,
|
|
107
143
|
start,
|
|
108
144
|
end,
|
|
145
|
+
...(timeZone ? { timezone: timeZone } : {}),
|
|
109
146
|
summary,
|
|
110
147
|
...(description ? { description } : {}),
|
|
111
148
|
...(location ? { location } : {}),
|
|
@@ -116,22 +153,24 @@ export const buildEventIcs = (post, options) => {
|
|
|
116
153
|
for (const exception of event.exceptions ?? []) {
|
|
117
154
|
if (exception.cancelled || !exception.start)
|
|
118
155
|
continue;
|
|
119
|
-
const start =
|
|
156
|
+
const start = instantInZone(exception.start, timeZone);
|
|
120
157
|
const end = exception.end
|
|
121
|
-
?
|
|
122
|
-
:
|
|
158
|
+
? instantInZone(exception.end, timeZone)
|
|
159
|
+
: defaultEnd(start, timeZone);
|
|
123
160
|
calendar.createEvent({
|
|
124
161
|
id: `openpeeps-event-${post.id}-${exception.recurrenceId}@openpeepshq`,
|
|
125
162
|
start,
|
|
126
163
|
end,
|
|
164
|
+
...(timeZone ? { timezone: timeZone } : {}),
|
|
127
165
|
summary,
|
|
128
166
|
...(description ? { description } : {}),
|
|
129
167
|
...(location ? { location } : {}),
|
|
130
168
|
...(link ? { url: link } : {}),
|
|
131
|
-
recurrenceId:
|
|
169
|
+
recurrenceId: instantInZone(exception.recurrenceId, timeZone),
|
|
132
170
|
});
|
|
133
171
|
}
|
|
134
|
-
|
|
172
|
+
const calendarText = calendar.toString();
|
|
173
|
+
return ((timeZone ? withVtimezone(calendarText, timeZone) : calendarText) + '\r\n');
|
|
135
174
|
};
|
|
136
175
|
const addOccurrenceEvent = (calendar, post, event, recurrenceId, options) => {
|
|
137
176
|
const link = event.url ?? options?.postUrl;
|
|
@@ -140,6 +179,7 @@ const addOccurrenceEvent = (calendar, post, event, recurrenceId, options) => {
|
|
|
140
179
|
const location = eventLocation(post, event, options?.postUrl);
|
|
141
180
|
const times = effectiveEventTimes(event, recurrenceId);
|
|
142
181
|
const id = `openpeeps-event-${post.id}-${recurrenceId}@openpeepshq`;
|
|
182
|
+
const timeZone = event.wholeDay ? undefined : eventTimeZone(event);
|
|
143
183
|
if (event.wholeDay) {
|
|
144
184
|
const startYmd = times.start.slice(0, 10);
|
|
145
185
|
const lastInclusiveYmd = times.end?.slice(0, 10) ?? startYmd;
|
|
@@ -155,14 +195,15 @@ const addOccurrenceEvent = (calendar, post, event, recurrenceId, options) => {
|
|
|
155
195
|
});
|
|
156
196
|
return;
|
|
157
197
|
}
|
|
158
|
-
const start =
|
|
198
|
+
const start = instantInZone(times.start, timeZone);
|
|
159
199
|
const end = times.end
|
|
160
|
-
?
|
|
161
|
-
:
|
|
200
|
+
? instantInZone(times.end, timeZone)
|
|
201
|
+
: defaultEnd(start, timeZone);
|
|
162
202
|
calendar.createEvent({
|
|
163
203
|
id,
|
|
164
204
|
start,
|
|
165
205
|
end,
|
|
206
|
+
...(timeZone ? { timezone: timeZone } : {}),
|
|
166
207
|
summary,
|
|
167
208
|
...(description ? { description } : {}),
|
|
168
209
|
...(location ? { location } : {}),
|
|
@@ -187,7 +228,9 @@ export const buildRsvpIcs = (post, options) => {
|
|
|
187
228
|
for (const recurrenceId of occurrenceIds) {
|
|
188
229
|
addOccurrenceEvent(calendar, post, event, recurrenceId, options);
|
|
189
230
|
}
|
|
190
|
-
|
|
231
|
+
const timeZone = event.wholeDay ? undefined : eventTimeZone(event);
|
|
232
|
+
const calendarText = calendar.toString();
|
|
233
|
+
return ((timeZone ? withVtimezone(calendarText, timeZone) : calendarText) + '\r\n');
|
|
191
234
|
};
|
|
192
235
|
export const rsvpConfirmationContent = (post, options) => {
|
|
193
236
|
if (post.type !== 'event' || post.data?.type !== 'event') {
|
|
@@ -292,7 +292,7 @@ const formatRecurrencePattern = (recurrence, t, start) => {
|
|
|
292
292
|
const interval = recurrence.interval ?? 1;
|
|
293
293
|
if (recurrence.freq === 'DAILY') {
|
|
294
294
|
return interval === 1
|
|
295
|
-
? t('events.repeat.daily', { defaultValue: 'Daily' })
|
|
295
|
+
? t('events.form.repeat.daily', { defaultValue: 'Daily' })
|
|
296
296
|
: t('events.repeat.everyNDays', {
|
|
297
297
|
defaultValue: 'Every {{count}} days',
|
|
298
298
|
count: interval,
|
|
@@ -300,7 +300,7 @@ const formatRecurrencePattern = (recurrence, t, start) => {
|
|
|
300
300
|
}
|
|
301
301
|
if (recurrence.freq === 'MONTHLY') {
|
|
302
302
|
return interval === 1
|
|
303
|
-
? t('events.repeat.monthly', { defaultValue: 'Monthly' })
|
|
303
|
+
? t('events.form.repeat.monthly', { defaultValue: 'Monthly' })
|
|
304
304
|
: t('events.repeat.everyNMonths', {
|
|
305
305
|
defaultValue: 'Every {{count}} months',
|
|
306
306
|
count: interval,
|
|
@@ -325,7 +325,7 @@ const formatRecurrencePattern = (recurrence, t, start) => {
|
|
|
325
325
|
});
|
|
326
326
|
}
|
|
327
327
|
return interval === 1
|
|
328
|
-
? t('events.repeat.weekly', { defaultValue: 'Weekly' })
|
|
328
|
+
? t('events.form.repeat.weekly', { defaultValue: 'Weekly' })
|
|
329
329
|
: t('events.repeat.everyNWeeks', {
|
|
330
330
|
defaultValue: 'Every {{count}} weeks',
|
|
331
331
|
count: interval,
|
package/dist/lib/eventTime.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** True when `end` is set and not after `start` (equal times are invalid). */
|
|
2
|
+
export declare const isEndBeforeStart: (start?: string, end?: string) => boolean;
|
|
1
3
|
/**
|
|
2
4
|
* Interpret a datetime-local wall clock (`YYYY-MM-DDTHH:mm`) in `timeZone`
|
|
3
5
|
* and return a UTC ISO string.
|
package/dist/lib/eventTime.js
CHANGED
|
@@ -18,6 +18,8 @@ const tzOffsetMs = (utcMs, timeZone) => {
|
|
|
18
18
|
return asUtc - utcMs;
|
|
19
19
|
};
|
|
20
20
|
const pad2 = (value) => String(value).padStart(2, '0');
|
|
21
|
+
/** True when `end` is set and not after `start` (equal times are invalid). */
|
|
22
|
+
export const isEndBeforeStart = (start, end) => Boolean(start && end && new Date(end) <= new Date(start));
|
|
21
23
|
/**
|
|
22
24
|
* Interpret a datetime-local wall clock (`YYYY-MM-DDTHH:mm`) in `timeZone`
|
|
23
25
|
* and return a UTC ISO string.
|
package/dist/lib/index.d.ts
CHANGED
package/dist/lib/index.js
CHANGED
package/dist/lib/utils.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export declare const interpolate: (text: string | undefined, params?: Record<str
|
|
|
19
19
|
export declare const sleep: (seconds: number) => Promise<void>;
|
|
20
20
|
export declare const deepSet: <T>(obj: T, path: string | (string | number)[], val: unknown) => T;
|
|
21
21
|
export declare const deepGet: (obj: unknown, path: (string | number)[]) => unknown;
|
|
22
|
+
export declare const deepEqual: (a: unknown, b: unknown) => boolean;
|
|
22
23
|
/**
|
|
23
24
|
* Checks if a value is valid => not (null, undefined, empty, etc.)
|
|
24
25
|
* Special case: treats 0 as a valid value unlike standard JS truthiness
|
package/dist/lib/utils.js
CHANGED
|
@@ -34,12 +34,23 @@ export const getUniqueBy = (arr, predicate) => {
|
|
|
34
34
|
const set = new Set();
|
|
35
35
|
return arr.filter((o) => !set.has(predicate(o)) && set.add(predicate(o)));
|
|
36
36
|
};
|
|
37
|
+
const UNSAFE_KEYS = new Set(['__proto__', 'prototype', 'constructor']);
|
|
37
38
|
export const interpolate = (text, params = {}) => {
|
|
38
39
|
try {
|
|
39
40
|
if (!text)
|
|
40
41
|
return text;
|
|
41
42
|
const names = Object.keys(params);
|
|
42
43
|
const vals = Object.values(params);
|
|
44
|
+
// Sanitize: reject param values that would produce unsafe jsonpath keys.
|
|
45
|
+
// jsonpath 1.3.0 throws "Unsafe key" for __proto__/prototype/constructor,
|
|
46
|
+
// which would cause an unhandled 500 in the SSO handler.
|
|
47
|
+
for (const val of vals) {
|
|
48
|
+
if (UNSAFE_KEYS.has(val)) {
|
|
49
|
+
throw new Error(`Interpolated value "${val}" matches an unsafe key (` +
|
|
50
|
+
[...UNSAFE_KEYS].join(', ') +
|
|
51
|
+
`) — this would trigger a jsonpath parse error`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
43
54
|
return new Function(...names, `return \`${text}\`;`)(...vals);
|
|
44
55
|
}
|
|
45
56
|
catch {
|
|
@@ -84,6 +95,22 @@ export const deepSet = (obj, path, val) => {
|
|
|
84
95
|
export const deepGet = (obj, path) =>
|
|
85
96
|
// @ts-expect-error deepget is not typeable
|
|
86
97
|
path.reduce((o, i) => o[i], obj);
|
|
98
|
+
export const deepEqual = (a, b) => {
|
|
99
|
+
if (a === b)
|
|
100
|
+
return true;
|
|
101
|
+
if (typeof a !== 'object' || typeof b !== 'object')
|
|
102
|
+
return false;
|
|
103
|
+
if (a === null || b === null)
|
|
104
|
+
return false;
|
|
105
|
+
if (Array.isArray(a) !== Array.isArray(b))
|
|
106
|
+
return false;
|
|
107
|
+
const keysA = Object.keys(a);
|
|
108
|
+
const keysB = Object.keys(b);
|
|
109
|
+
if (keysA.length !== keysB.length)
|
|
110
|
+
return false;
|
|
111
|
+
return keysA.every((key) => Object.prototype.hasOwnProperty.call(b, key) &&
|
|
112
|
+
deepEqual(a[key], b[key]));
|
|
113
|
+
};
|
|
87
114
|
/**
|
|
88
115
|
* Checks if a value is valid => not (null, undefined, empty, etc.)
|
|
89
116
|
* Special case: treats 0 as a valid value unlike standard JS truthiness
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface VideoEmbed {
|
|
2
|
+
provider: 'youtube' | 'vimeo';
|
|
3
|
+
embedUrl: string;
|
|
4
|
+
/** Origin of `embedUrl`, for same-origin checks in WebView guards. */
|
|
5
|
+
origin: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Embed info for plain video URLs on supported providers (YouTube
|
|
9
|
+
* watch/share/shorts/embed, Vimeo). Lets the client render a playable
|
|
10
|
+
* player instead of a link card.
|
|
11
|
+
*/
|
|
12
|
+
export declare const videoEmbedForUrl: (url: string) => VideoEmbed | undefined;
|
|
@@ -0,0 +1,105 @@
|
|
|
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
|
+
* Maps a YouTube `t=`/`start=` timestamp to seconds. Accepts `42`, `42s`,
|
|
7
|
+
* `1:30`, `1m30s`, and `1h2m3s` forms.
|
|
8
|
+
*/
|
|
9
|
+
const parseYouTubeStart = (raw) => {
|
|
10
|
+
const trimmed = raw.trim();
|
|
11
|
+
if (trimmed === '')
|
|
12
|
+
return undefined;
|
|
13
|
+
if (/^\d+$/.test(trimmed))
|
|
14
|
+
return Number(trimmed);
|
|
15
|
+
const compact = trimmed.match(/^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?$/);
|
|
16
|
+
if (compact) {
|
|
17
|
+
const [, hours, minutes, seconds] = compact;
|
|
18
|
+
if (!hours && !minutes && !seconds)
|
|
19
|
+
return undefined;
|
|
20
|
+
return (Number(hours ?? 0) * 3600 +
|
|
21
|
+
Number(minutes ?? 0) * 60 +
|
|
22
|
+
Number(seconds ?? 0));
|
|
23
|
+
}
|
|
24
|
+
const parts = trimmed.split(':');
|
|
25
|
+
if (parts.length > 3 || parts.some((part) => !/^\d+$/.test(part))) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
return parts.reduce((total, part) => total * 60 + Number(part), 0);
|
|
29
|
+
};
|
|
30
|
+
const youtubeEmbed = (id, parsed) => {
|
|
31
|
+
const rawStart = parsed.searchParams.get('t') ?? parsed.searchParams.get('start');
|
|
32
|
+
const start = rawStart ? parseYouTubeStart(rawStart) : undefined;
|
|
33
|
+
return {
|
|
34
|
+
provider: 'youtube',
|
|
35
|
+
embedUrl: `${YOUTUBE_ORIGIN}/embed/${id}` +
|
|
36
|
+
(start !== undefined && start > 0 ? `?start=${start}` : ''),
|
|
37
|
+
origin: YOUTUBE_ORIGIN,
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Embed info for plain video URLs on supported providers (YouTube
|
|
42
|
+
* watch/share/shorts/embed, Vimeo). Lets the client render a playable
|
|
43
|
+
* player instead of a link card.
|
|
44
|
+
*/
|
|
45
|
+
export const videoEmbedForUrl = (url) => {
|
|
46
|
+
let parsed;
|
|
47
|
+
try {
|
|
48
|
+
parsed = new URL(url);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
const host = parsed.hostname.replace(/^(www|m)\./, '');
|
|
54
|
+
if (host === 'youtu.be') {
|
|
55
|
+
const id = parsed.pathname.split('/')[1] ?? '';
|
|
56
|
+
return YOUTUBE_ID_RE.test(id) ? youtubeEmbed(id, parsed) : undefined;
|
|
57
|
+
}
|
|
58
|
+
if (host === 'youtube.com') {
|
|
59
|
+
const segments = parsed.pathname.split('/').filter(Boolean);
|
|
60
|
+
let id;
|
|
61
|
+
if (segments[0] === 'watch') {
|
|
62
|
+
id = parsed.searchParams.get('v') ?? undefined;
|
|
63
|
+
}
|
|
64
|
+
else if (segments[0] === 'shorts' || segments[0] === 'embed') {
|
|
65
|
+
id = segments[1];
|
|
66
|
+
}
|
|
67
|
+
return id && YOUTUBE_ID_RE.test(id) ? youtubeEmbed(id, parsed) : undefined;
|
|
68
|
+
}
|
|
69
|
+
if (host === 'vimeo.com' || host === 'player.vimeo.com') {
|
|
70
|
+
const segments = parsed.pathname.split('/').filter(Boolean);
|
|
71
|
+
let id;
|
|
72
|
+
let hash;
|
|
73
|
+
if (host === 'player.vimeo.com') {
|
|
74
|
+
if (segments[0] === 'video') {
|
|
75
|
+
id = segments[1];
|
|
76
|
+
hash = parsed.searchParams.get('h') ?? undefined;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else if (segments.length === 1) {
|
|
80
|
+
id = segments[0];
|
|
81
|
+
}
|
|
82
|
+
else if (segments.length === 2 && VIMEO_ID_RE.test(segments[0])) {
|
|
83
|
+
// `vimeo.com/<id>/<hash>` — unlisted videos carry the privacy hash
|
|
84
|
+
// in the path.
|
|
85
|
+
id = segments[0];
|
|
86
|
+
hash = segments[1];
|
|
87
|
+
}
|
|
88
|
+
else if (segments.length === 3 && segments[0] === 'channels') {
|
|
89
|
+
id = segments[2];
|
|
90
|
+
}
|
|
91
|
+
else if (segments.length === 4 &&
|
|
92
|
+
segments[0] === 'groups' &&
|
|
93
|
+
segments[2] === 'videos') {
|
|
94
|
+
id = segments[3];
|
|
95
|
+
}
|
|
96
|
+
if (!id || !VIMEO_ID_RE.test(id))
|
|
97
|
+
return undefined;
|
|
98
|
+
return {
|
|
99
|
+
provider: 'vimeo',
|
|
100
|
+
embedUrl: `${VIMEO_ORIGIN}/video/${id}?dnt=1` + (hash ? `&h=${hash}` : ''),
|
|
101
|
+
origin: VIMEO_ORIGIN,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return undefined;
|
|
105
|
+
};
|
package/dist/types/api.d.ts
CHANGED
|
@@ -265,6 +265,7 @@ export declare const publicAccessTokenSchema: z.ZodObject<{
|
|
|
265
265
|
groups: "groups";
|
|
266
266
|
reports: "reports";
|
|
267
267
|
webhooks: "webhooks";
|
|
268
|
+
conversations: "conversations";
|
|
268
269
|
analytics: "analytics";
|
|
269
270
|
render: "render";
|
|
270
271
|
}>;
|
|
@@ -38710,6 +38711,7 @@ export declare const guestPassRequestSchema: z.ZodObject<{
|
|
|
38710
38711
|
groups: "groups";
|
|
38711
38712
|
reports: "reports";
|
|
38712
38713
|
webhooks: "webhooks";
|
|
38714
|
+
conversations: "conversations";
|
|
38713
38715
|
analytics: "analytics";
|
|
38714
38716
|
render: "render";
|
|
38715
38717
|
}>;
|
|
@@ -39004,6 +39006,7 @@ export declare const mediaStreamRequestSchema: z.ZodObject<{
|
|
|
39004
39006
|
}, z.core.$strip>;
|
|
39005
39007
|
export type MediaStreamRequest = z.infer<typeof mediaStreamRequestSchema>;
|
|
39006
39008
|
export declare const updateProfileRequestSchema: z.ZodObject<{
|
|
39009
|
+
timeZone: z.ZodOptional<z.ZodString>;
|
|
39007
39010
|
type: z.ZodEnum<{
|
|
39008
39011
|
local: "local";
|
|
39009
39012
|
guest: "guest";
|
|
@@ -39023,7 +39026,6 @@ export declare const updateProfileRequestSchema: z.ZodObject<{
|
|
|
39023
39026
|
alt: z.ZodOptional<z.ZodNumber>;
|
|
39024
39027
|
}, z.core.$strip>>;
|
|
39025
39028
|
}, z.core.$strip>>;
|
|
39026
|
-
timeZone: z.ZodOptional<z.ZodString>;
|
|
39027
39029
|
deletedHandle: z.ZodOptional<z.ZodString>;
|
|
39028
39030
|
header: z.ZodOptional<z.ZodNullable<z.ZodURL>>;
|
|
39029
39031
|
bio: z.ZodOptional<z.ZodString>;
|
|
@@ -39050,6 +39052,7 @@ export declare const updateProfileRequestSchema: z.ZodObject<{
|
|
|
39050
39052
|
groups: "groups";
|
|
39051
39053
|
reports: "reports";
|
|
39052
39054
|
webhooks: "webhooks";
|
|
39055
|
+
conversations: "conversations";
|
|
39053
39056
|
analytics: "analytics";
|
|
39054
39057
|
render: "render";
|
|
39055
39058
|
}>;
|
|
@@ -39060,16 +39063,16 @@ export declare const updateProfileRequestSchema: z.ZodObject<{
|
|
|
39060
39063
|
export type UpdateProfileRequest = z.infer<typeof updateProfileRequestSchema>;
|
|
39061
39064
|
export declare const updateAccountPasswordRequestSchema: z.ZodObject<{
|
|
39062
39065
|
email: z.ZodOptional<z.ZodString>;
|
|
39063
|
-
newPassword: z.ZodPreprocess<z.ZodOptional<z.ZodString
|
|
39066
|
+
newPassword: z.ZodPreprocess<z.ZodOptional<z.ZodString>, unknown>;
|
|
39064
39067
|
oldPassword: z.ZodString;
|
|
39065
|
-
confirmPassword: z.ZodPreprocess<z.ZodOptional<z.ZodString
|
|
39068
|
+
confirmPassword: z.ZodPreprocess<z.ZodOptional<z.ZodString>, unknown>;
|
|
39066
39069
|
}, z.core.$strip>;
|
|
39067
39070
|
export type UpdateAccountPasswordRequest = z.infer<typeof updateAccountPasswordRequestSchema>;
|
|
39068
39071
|
export declare const updateAccountPasswordFormSchema: z.ZodObject<{
|
|
39069
39072
|
email: z.ZodOptional<z.ZodString>;
|
|
39070
|
-
newPassword: z.ZodPreprocess<z.ZodOptional<z.ZodString
|
|
39073
|
+
newPassword: z.ZodPreprocess<z.ZodOptional<z.ZodString>, unknown>;
|
|
39071
39074
|
oldPassword: z.ZodString;
|
|
39072
|
-
confirmPassword: z.ZodPreprocess<z.ZodOptional<z.ZodString
|
|
39075
|
+
confirmPassword: z.ZodPreprocess<z.ZodOptional<z.ZodString>, unknown>;
|
|
39073
39076
|
}, z.core.$strip>;
|
|
39074
39077
|
export declare const updateAccountEmailRequestSchema: z.ZodObject<{
|
|
39075
39078
|
newEmail: z.ZodEmail;
|
|
@@ -73051,6 +73054,7 @@ export declare const accessTokenCreationDataSchema: z.ZodObject<{
|
|
|
73051
73054
|
groups: "groups";
|
|
73052
73055
|
reports: "reports";
|
|
73053
73056
|
webhooks: "webhooks";
|
|
73057
|
+
conversations: "conversations";
|
|
73054
73058
|
analytics: "analytics";
|
|
73055
73059
|
render: "render";
|
|
73056
73060
|
}>;
|
package/dist/types/auth.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export declare const authorizationSchema: z.ZodObject<{
|
|
|
23
23
|
groups: "groups";
|
|
24
24
|
reports: "reports";
|
|
25
25
|
webhooks: "webhooks";
|
|
26
|
+
conversations: "conversations";
|
|
26
27
|
analytics: "analytics";
|
|
27
28
|
render: "render";
|
|
28
29
|
}>;
|
|
@@ -79,6 +80,7 @@ export declare const authorizationDataSchema: z.ZodObject<{
|
|
|
79
80
|
groups: "groups";
|
|
80
81
|
reports: "reports";
|
|
81
82
|
webhooks: "webhooks";
|
|
83
|
+
conversations: "conversations";
|
|
82
84
|
analytics: "analytics";
|
|
83
85
|
render: "render";
|
|
84
86
|
}>;
|
|
@@ -148,6 +150,7 @@ export declare const authorizationDataSchema: z.ZodObject<{
|
|
|
148
150
|
groups: "groups";
|
|
149
151
|
reports: "reports";
|
|
150
152
|
webhooks: "webhooks";
|
|
153
|
+
conversations: "conversations";
|
|
151
154
|
analytics: "analytics";
|
|
152
155
|
render: "render";
|
|
153
156
|
}>;
|
|
@@ -207,6 +210,7 @@ export declare const authorizationDataSchema: z.ZodObject<{
|
|
|
207
210
|
groups: "groups";
|
|
208
211
|
reports: "reports";
|
|
209
212
|
webhooks: "webhooks";
|
|
213
|
+
conversations: "conversations";
|
|
210
214
|
analytics: "analytics";
|
|
211
215
|
render: "render";
|
|
212
216
|
}>;
|
|
@@ -334,6 +338,7 @@ export declare const authorizationDataSchema: z.ZodObject<{
|
|
|
334
338
|
groups: "groups";
|
|
335
339
|
reports: "reports";
|
|
336
340
|
webhooks: "webhooks";
|
|
341
|
+
conversations: "conversations";
|
|
337
342
|
analytics: "analytics";
|
|
338
343
|
render: "render";
|
|
339
344
|
}>;
|
|
@@ -366,6 +371,7 @@ export declare const authorizationDataSchema: z.ZodObject<{
|
|
|
366
371
|
groups: "groups";
|
|
367
372
|
reports: "reports";
|
|
368
373
|
webhooks: "webhooks";
|
|
374
|
+
conversations: "conversations";
|
|
369
375
|
analytics: "analytics";
|
|
370
376
|
render: "render";
|
|
371
377
|
}>;
|