@openpeepshq/common 0.31.0 → 0.33.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.
@@ -18,6 +18,11 @@ export type MentionProfileRef = {
18
18
  * Bare `@handle` tokens use the allowed handle charset (letters, digits, `_`, `-`).
19
19
  */
20
20
  export declare const linkProfileMentions: (source: string, mentions?: MentionProfileRef[]) => string;
21
+ /**
22
+ * All mention tokens in the text, deduplicated: local `@handle` tokens plus
23
+ * remote `handle@domain` tokens (domain lowercased).
24
+ */
25
+ export declare const matchFederatedMentionTokens: (text?: string | null) => string[];
21
26
  /**
22
27
  * Pre-process markdown source: convert `@handle` mentions into markdown
23
28
  * profile links. Hashtag conversion is handled per-platform (web regex vs.
@@ -1,4 +1,4 @@
1
- import { mentionHandleRegexBase } from '../types/index.js';
1
+ import { federatedMentionHandleRegexBase, mentionHandleRegexBase, } from '../types/index.js';
2
2
  const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
3
3
  const mentionPrefix = '(^|[\\s(>])';
4
4
  const mentionSuffix = '(?=\\s|$|[.,!?;:])';
@@ -25,8 +25,33 @@ export const linkProfileMentions = (source, mentions = []) => {
25
25
  const pattern = new RegExp(`${mentionPrefix}@(${escapeRegExp(name)})${mentionSuffix}`, 'gi');
26
26
  text = text.replace(pattern, (_full, prefix, mentioned) => `${prefix}[@${mentioned}](/@${handle})`);
27
27
  }
28
+ // Replace bare local `@handle` tokens last; a federated token
29
+ // (`@user@domain`) must not be wrapped in a local profile link. The
30
+ // bare-handle regex's prefix class `(^|[\s(>])` cannot match at the `@`
31
+ // before the domain, so remote mentions stay as plain text here.
28
32
  return text.replace(new RegExp(mentionHandleRegexBase, 'g'), (_full, prefix, handle) => `${prefix}[@${handle}](/@${handle})`);
29
33
  };
34
+ /**
35
+ * All mention tokens in the text, deduplicated: local `@handle` tokens plus
36
+ * remote `handle@domain` tokens (domain lowercased).
37
+ */
38
+ export const matchFederatedMentionTokens = (text) => {
39
+ if (!text)
40
+ return [];
41
+ const tokens = new Set();
42
+ const fedRegex = new RegExp(federatedMentionHandleRegexBase, 'gi');
43
+ for (const match of text.matchAll(fedRegex)) {
44
+ const handle = match[2]?.toLowerCase();
45
+ const domain = match[3]?.toLowerCase();
46
+ if (handle && domain)
47
+ tokens.add(`${handle}@${domain}`);
48
+ }
49
+ for (const match of text.matchAll(new RegExp(mentionHandleRegexBase, 'g'))) {
50
+ if (match[2])
51
+ tokens.add(match[2]);
52
+ }
53
+ return [...tokens];
54
+ };
30
55
  /**
31
56
  * Pre-process markdown source: convert `@handle` mentions into markdown
32
57
  * profile links. Hashtag conversion is handled per-platform (web regex vs.
@@ -258,6 +258,66 @@ export declare const analyticsOverviewSchema: z.ZodObject<{
258
258
  value: z.ZodNumber;
259
259
  }, z.core.$strip>>>;
260
260
  }, z.core.$strip>;
261
+ jamSessions: z.ZodObject<{
262
+ key: z.ZodString;
263
+ value: z.ZodNumber;
264
+ previousValue: z.ZodNumber;
265
+ deltaPct: z.ZodNullable<z.ZodNumber>;
266
+ series: z.ZodOptional<z.ZodArray<z.ZodObject<{
267
+ day: z.ZodString;
268
+ value: z.ZodNumber;
269
+ }, z.core.$strip>>>;
270
+ }, z.core.$strip>;
271
+ jamParticipants: z.ZodObject<{
272
+ key: z.ZodString;
273
+ value: z.ZodNumber;
274
+ previousValue: z.ZodNumber;
275
+ deltaPct: z.ZodNullable<z.ZodNumber>;
276
+ series: z.ZodOptional<z.ZodArray<z.ZodObject<{
277
+ day: z.ZodString;
278
+ value: z.ZodNumber;
279
+ }, z.core.$strip>>>;
280
+ }, z.core.$strip>;
281
+ jamMinutes: z.ZodObject<{
282
+ key: z.ZodString;
283
+ value: z.ZodNumber;
284
+ previousValue: z.ZodNumber;
285
+ deltaPct: z.ZodNullable<z.ZodNumber>;
286
+ series: z.ZodOptional<z.ZodArray<z.ZodObject<{
287
+ day: z.ZodString;
288
+ value: z.ZodNumber;
289
+ }, z.core.$strip>>>;
290
+ }, z.core.$strip>;
291
+ jamUniqueAttendees: z.ZodObject<{
292
+ key: z.ZodString;
293
+ value: z.ZodNumber;
294
+ previousValue: z.ZodNumber;
295
+ deltaPct: z.ZodNullable<z.ZodNumber>;
296
+ series: z.ZodOptional<z.ZodArray<z.ZodObject<{
297
+ day: z.ZodString;
298
+ value: z.ZodNumber;
299
+ }, z.core.$strip>>>;
300
+ }, z.core.$strip>;
301
+ jamPeakConcurrent: z.ZodObject<{
302
+ key: z.ZodString;
303
+ value: z.ZodNumber;
304
+ previousValue: z.ZodNumber;
305
+ deltaPct: z.ZodNullable<z.ZodNumber>;
306
+ series: z.ZodOptional<z.ZodArray<z.ZodObject<{
307
+ day: z.ZodString;
308
+ value: z.ZodNumber;
309
+ }, z.core.$strip>>>;
310
+ }, z.core.$strip>;
311
+ jamRecordings: z.ZodObject<{
312
+ key: z.ZodString;
313
+ value: z.ZodNumber;
314
+ previousValue: z.ZodNumber;
315
+ deltaPct: z.ZodNullable<z.ZodNumber>;
316
+ series: z.ZodOptional<z.ZodArray<z.ZodObject<{
317
+ day: z.ZodString;
318
+ value: z.ZodNumber;
319
+ }, z.core.$strip>>>;
320
+ }, z.core.$strip>;
261
321
  }, z.core.$strip>;
262
322
  postsOverTime: z.ZodArray<z.ZodObject<{
263
323
  day: z.ZodString;
@@ -285,6 +345,11 @@ export declare const analyticsOverviewSchema: z.ZodObject<{
285
345
  label: z.ZodString;
286
346
  value: z.ZodNumber;
287
347
  }, z.core.$strip>>;
348
+ jamsOverTime: z.ZodArray<z.ZodObject<{
349
+ day: z.ZodString;
350
+ label: z.ZodString;
351
+ value: z.ZodNumber;
352
+ }, z.core.$strip>>;
288
353
  topMembers: z.ZodArray<z.ZodObject<{
289
354
  profileId: z.ZodString;
290
355
  handle: z.ZodString;
@@ -401,6 +466,16 @@ export declare const analyticsGrowthSchema: z.ZodObject<{
401
466
  value: z.ZodNumber;
402
467
  }, z.core.$strip>>>;
403
468
  }, z.core.$strip>;
469
+ jamMinutes: z.ZodObject<{
470
+ key: z.ZodString;
471
+ value: z.ZodNumber;
472
+ previousValue: z.ZodNumber;
473
+ deltaPct: z.ZodNullable<z.ZodNumber>;
474
+ series: z.ZodOptional<z.ZodArray<z.ZodObject<{
475
+ day: z.ZodString;
476
+ value: z.ZodNumber;
477
+ }, z.core.$strip>>>;
478
+ }, z.core.$strip>;
404
479
  }, z.core.$strip>;
405
480
  signupsByDay: z.ZodArray<z.ZodObject<{
406
481
  day: z.ZodString;
@@ -142,10 +142,24 @@ export const analyticsOverviewSchema = z.object({
142
142
  unverifiedMembers: analyticsMetricCardSchema,
143
143
  activeMembers: analyticsMetricCardSchema,
144
144
  totalGroups: analyticsMetricCardSchema,
145
+ /** Distinct (jam, occurrence) sessions started in the range. */
146
+ jamSessions: analyticsMetricCardSchema,
147
+ /** Distinct (member, jam) pairings from attended joins in the range. */
148
+ jamParticipants: analyticsMetricCardSchema,
149
+ /** Total minutes of jam sessions that started in the range. */
150
+ jamMinutes: analyticsMetricCardSchema,
151
+ /** Distinct members who joined at least one jam in the range. */
152
+ jamUniqueAttendees: analyticsMetricCardSchema,
153
+ /** Highest number of concurrent jam sessions overlapping in the range. */
154
+ jamPeakConcurrent: analyticsMetricCardSchema,
155
+ /** Jam recordings that reached "completed" in the range. */
156
+ jamRecordings: analyticsMetricCardSchema,
145
157
  }),
146
158
  postsOverTime: analyticsStackedPointSchema.array(),
147
159
  postTypes: analyticsPostTypeCountSchema.array(),
148
160
  activeUsersSeries: analyticsBucketedPointSchema.array(),
161
+ /** Jam sessions over time, bucketed like activeUsersSeries. */
162
+ jamsOverTime: analyticsBucketedPointSchema.array(),
149
163
  topMembers: analyticsMemberRowSchema.array(),
150
164
  topPosts: analyticsPostRowSchema.array(),
151
165
  /** @deprecated kept for report/CSV compatibility */
@@ -163,6 +177,8 @@ export const analyticsGrowthSchema = z.object({
163
177
  dau: analyticsMetricCardSchema,
164
178
  mau: analyticsMetricCardSchema,
165
179
  dauMau: analyticsMetricCardSchema,
180
+ /** Total minutes of jam sessions that started in the range. */
181
+ jamMinutes: analyticsMetricCardSchema,
166
182
  }),
167
183
  /** New-member counts for every day in the selected range. */
168
184
  signupsByDay: analyticsDayHeatmapCellSchema.array(),
@@ -3,6 +3,16 @@ import { HANDLE_RESERVED_MESSAGE, additionalForbiddenHandlesSchema, classifyAddi
3
3
  export { HANDLE_RESERVED_MESSAGE, additionalForbiddenHandlesSchema, classifyAdditionalForbiddenHandle, collectAdditionalForbiddenHandles, forbiddenHandles, handleRegex, handleRegexBase, isDefaultForbiddenHandle, isForbiddenHandle, normalizeForbiddenHandle, };
4
4
  /** `@handle` using the allowed handle charset. No `\\b` — hyphens are not word chars. */
5
5
  export declare const mentionHandleRegexBase = "(^|[\\s(>])@([a-zA-Z0-9_-]{1,16})(?=\\s|$|[.,!?;:])";
6
+ /**
7
+ * Federated handle mention: `@user@domain`. The domain is a dotted host
8
+ * (multi-label allowed, e.g. `mastodon.social`). No `\\b` — hyphens are not
9
+ * word chars. Group 2 = local handle, group 3 = remote domain.
10
+ *
11
+ * The trailing lookahead adds `)` so a parenthesised mention `(@a@x.co)`
12
+ * still matches; the bare local regex keeps the shorter class and so does not
13
+ * match a parenthesised `(@a)` (a pre-existing, intentional gap).
14
+ */
15
+ export declare const federatedMentionHandleRegexBase = "(^|[\\s(>])@([a-zA-Z0-9_-]{1,16})@([a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?){1,})(?=\\s|$|[.,!?;):])";
6
16
  export declare const baseSchemaShape: {
7
17
  createdAt: z.ZodISODateTime;
8
18
  updatedAt: z.ZodISODateTime;
@@ -12,6 +12,16 @@ export { HANDLE_RESERVED_MESSAGE, additionalForbiddenHandlesSchema, classifyAddi
12
12
  extendZodWithOpenApi(z);
13
13
  /** `@handle` using the allowed handle charset. No `\\b` — hyphens are not word chars. */
14
14
  export const mentionHandleRegexBase = `(^|[\\s(>])@(${handleRegexBase})(?=\\s|$|[.,!?;:])`;
15
+ /**
16
+ * Federated handle mention: `@user@domain`. The domain is a dotted host
17
+ * (multi-label allowed, e.g. `mastodon.social`). No `\\b` — hyphens are not
18
+ * word chars. Group 2 = local handle, group 3 = remote domain.
19
+ *
20
+ * The trailing lookahead adds `)` so a parenthesised mention `(@a@x.co)`
21
+ * still matches; the bare local regex keeps the shorter class and so does not
22
+ * match a parenthesised `(@a)` (a pre-existing, intentional gap).
23
+ */
24
+ export const federatedMentionHandleRegexBase = `(^|[\\s(>])@(${handleRegexBase})@([a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?){1,})(?=\\s|$|[.,!?;):])`;
15
25
  export const baseSchemaShape = {
16
26
  createdAt: z.iso.datetime(),
17
27
  updatedAt: z.iso.datetime(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpeepshq/common",
3
- "version": "0.31.0",
3
+ "version": "0.33.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -1,4 +1,7 @@
1
- import { mentionHandleRegexBase } from '../types';
1
+ import {
2
+ federatedMentionHandleRegexBase,
3
+ mentionHandleRegexBase,
4
+ } from '../types';
2
5
 
3
6
  export interface MarkdownRenderProps {
4
7
  source?: string;
@@ -52,6 +55,10 @@ export const linkProfileMentions = (
52
55
  );
53
56
  }
54
57
 
58
+ // Replace bare local `@handle` tokens last; a federated token
59
+ // (`@user@domain`) must not be wrapped in a local profile link. The
60
+ // bare-handle regex's prefix class `(^|[\s(>])` cannot match at the `@`
61
+ // before the domain, so remote mentions stay as plain text here.
55
62
  return text.replace(
56
63
  new RegExp(mentionHandleRegexBase, 'g'),
57
64
  (_full, prefix: string, handle: string) =>
@@ -59,6 +66,25 @@ export const linkProfileMentions = (
59
66
  );
60
67
  };
61
68
 
69
+ /**
70
+ * All mention tokens in the text, deduplicated: local `@handle` tokens plus
71
+ * remote `handle@domain` tokens (domain lowercased).
72
+ */
73
+ export const matchFederatedMentionTokens = (text?: string | null): string[] => {
74
+ if (!text) return [];
75
+ const tokens = new Set<string>();
76
+ const fedRegex = new RegExp(federatedMentionHandleRegexBase, 'gi');
77
+ for (const match of text.matchAll(fedRegex)) {
78
+ const handle = match[2]?.toLowerCase();
79
+ const domain = match[3]?.toLowerCase();
80
+ if (handle && domain) tokens.add(`${handle}@${domain}`);
81
+ }
82
+ for (const match of text.matchAll(new RegExp(mentionHandleRegexBase, 'g'))) {
83
+ if (match[2]) tokens.add(match[2]);
84
+ }
85
+ return [...tokens];
86
+ };
87
+
62
88
  /**
63
89
  * Pre-process markdown source: convert `@handle` mentions into markdown
64
90
  * profile links. Hashtag conversion is handled per-platform (web regex vs.
@@ -189,10 +189,24 @@ export const analyticsOverviewSchema = z.object({
189
189
  unverifiedMembers: analyticsMetricCardSchema,
190
190
  activeMembers: analyticsMetricCardSchema,
191
191
  totalGroups: analyticsMetricCardSchema,
192
+ /** Distinct (jam, occurrence) sessions started in the range. */
193
+ jamSessions: analyticsMetricCardSchema,
194
+ /** Distinct (member, jam) pairings from attended joins in the range. */
195
+ jamParticipants: analyticsMetricCardSchema,
196
+ /** Total minutes of jam sessions that started in the range. */
197
+ jamMinutes: analyticsMetricCardSchema,
198
+ /** Distinct members who joined at least one jam in the range. */
199
+ jamUniqueAttendees: analyticsMetricCardSchema,
200
+ /** Highest number of concurrent jam sessions overlapping in the range. */
201
+ jamPeakConcurrent: analyticsMetricCardSchema,
202
+ /** Jam recordings that reached "completed" in the range. */
203
+ jamRecordings: analyticsMetricCardSchema,
192
204
  }),
193
205
  postsOverTime: analyticsStackedPointSchema.array(),
194
206
  postTypes: analyticsPostTypeCountSchema.array(),
195
207
  activeUsersSeries: analyticsBucketedPointSchema.array(),
208
+ /** Jam sessions over time, bucketed like activeUsersSeries. */
209
+ jamsOverTime: analyticsBucketedPointSchema.array(),
196
210
  topMembers: analyticsMemberRowSchema.array(),
197
211
  topPosts: analyticsPostRowSchema.array(),
198
212
  /** @deprecated kept for report/CSV compatibility */
@@ -212,6 +226,8 @@ export const analyticsGrowthSchema = z.object({
212
226
  dau: analyticsMetricCardSchema,
213
227
  mau: analyticsMetricCardSchema,
214
228
  dauMau: analyticsMetricCardSchema,
229
+ /** Total minutes of jam sessions that started in the range. */
230
+ jamMinutes: analyticsMetricCardSchema,
215
231
  }),
216
232
  /** New-member counts for every day in the selected range. */
217
233
  signupsByDay: analyticsDayHeatmapCellSchema.array(),
@@ -41,6 +41,17 @@ extendZodWithOpenApi(z);
41
41
  /** `@handle` using the allowed handle charset. No `\\b` — hyphens are not word chars. */
42
42
  export const mentionHandleRegexBase = `(^|[\\s(>])@(${handleRegexBase})(?=\\s|$|[.,!?;:])`;
43
43
 
44
+ /**
45
+ * Federated handle mention: `@user@domain`. The domain is a dotted host
46
+ * (multi-label allowed, e.g. `mastodon.social`). No `\\b` — hyphens are not
47
+ * word chars. Group 2 = local handle, group 3 = remote domain.
48
+ *
49
+ * The trailing lookahead adds `)` so a parenthesised mention `(@a@x.co)`
50
+ * still matches; the bare local regex keeps the shorter class and so does not
51
+ * match a parenthesised `(@a)` (a pre-existing, intentional gap).
52
+ */
53
+ export const federatedMentionHandleRegexBase = `(^|[\\s(>])@(${handleRegexBase})@([a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?){1,})(?=\\s|$|[.,!?;):])`;
54
+
44
55
  export const baseSchemaShape = {
45
56
  createdAt: z.iso.datetime(),
46
57
  updatedAt: z.iso.datetime(),