@openpeepshq/common 0.12.0 → 0.14.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.
- package/dist/lib/postHelpers.d.ts +19 -2
- package/dist/lib/postHelpers.js +24 -0
- package/dist/lib/reactions.d.ts +9 -5
- package/dist/lib/reactions.js +9 -5
- package/dist/lib/resources.d.ts +2 -2
- package/dist/lib/resources.js +2 -2
- package/dist/types/api.d.ts +250 -81
- package/dist/types/api.js +3 -0
- package/dist/types/config.d.ts +13 -0
- package/dist/types/config.js +17 -0
- package/dist/types/db.d.ts +51 -63
- package/dist/types/internal.d.ts +98 -90
- package/dist/types/models.d.ts +37 -40
- package/dist/types/models.js +25 -8
- package/dist/types/stats.d.ts +224 -72
- package/package.json +1 -1
- package/src/lib/postHelpers.ts +34 -0
- package/src/lib/reactions.ts +10 -9
- package/src/lib/resources.ts +2 -1
- package/src/types/api.ts +9 -0
- package/src/types/config.ts +18 -0
- package/src/types/models.ts +29 -9
package/package.json
CHANGED
package/src/lib/postHelpers.ts
CHANGED
|
@@ -13,12 +13,17 @@ import {
|
|
|
13
13
|
PublicProfile,
|
|
14
14
|
PublicRsvp,
|
|
15
15
|
Question,
|
|
16
|
+
Role,
|
|
16
17
|
RSVP,
|
|
17
18
|
Thread,
|
|
18
19
|
VisibilityType,
|
|
19
20
|
visibilityTypeValues,
|
|
20
21
|
} from '../types';
|
|
21
22
|
import { canModerateJam } from './jamHelpers';
|
|
23
|
+
import {
|
|
24
|
+
canAnnouncePosts,
|
|
25
|
+
isCommunityWideVisibility,
|
|
26
|
+
} from './capabilitiesHelpers';
|
|
22
27
|
import {
|
|
23
28
|
defaultRsvpRecurrenceId,
|
|
24
29
|
effectiveEventTimes,
|
|
@@ -563,6 +568,35 @@ export const withoutEventMaxAttendees = <T extends Event>(event: T): T => {
|
|
|
563
568
|
return rest as T;
|
|
564
569
|
};
|
|
565
570
|
|
|
571
|
+
/** A community-wide jam only broadcasts when the creator opted in. */
|
|
572
|
+
export const withoutJamNotifyEveryone = <T extends Event>(event: T): T => {
|
|
573
|
+
if (!event.jam?.notifyEveryone) return event;
|
|
574
|
+
return { ...event, jam: { ...event.jam, notifyEveryone: undefined } } as T;
|
|
575
|
+
};
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Broadcast requires community-wide visibility AND the announce capability
|
|
579
|
+
* (same rule as `POST /admin/posts/:postId/announce`); other visibilities or
|
|
580
|
+
* roles drop the flag. The capability check matters because the save path is
|
|
581
|
+
* reachable without the UI toggle: a plain member's role wildcard-matches
|
|
582
|
+
* `core-posts-create-*`, so a crafted API payload could otherwise plant the
|
|
583
|
+
* flag and blast the whole instance.
|
|
584
|
+
*
|
|
585
|
+
* Exported (rather than kept module-local) because `@openpeepshq/core`'s
|
|
586
|
+
* `createPost`/`updatePost` mutations apply it on the server-side save path;
|
|
587
|
+
* it is not a general-purpose utility — unlike `withoutJamNotifyEveryone` and
|
|
588
|
+
* `withoutEventMaxAttendees`, it takes the creator's roles in addition to the
|
|
589
|
+
* event.
|
|
590
|
+
*/
|
|
591
|
+
export const withoutCommunityJamNotifyEveryone = <T extends Event>(
|
|
592
|
+
event: T,
|
|
593
|
+
visibility: string | undefined,
|
|
594
|
+
roles?: Role[],
|
|
595
|
+
): T =>
|
|
596
|
+
isCommunityWideVisibility(visibility) && canAnnouncePosts(roles)
|
|
597
|
+
? event
|
|
598
|
+
: withoutJamNotifyEveryone(event);
|
|
599
|
+
|
|
566
600
|
export const normalizeEventDataForSave = <T extends Event>(event: T): T => {
|
|
567
601
|
const { maxAttendees } = event;
|
|
568
602
|
if (
|
package/src/lib/reactions.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
export const AP_LIKE_REACTION = '👍';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Whether a logged reaction value is usable: a non-empty emoji string.
|
|
5
|
+
* The community may configure a custom allowed set, so this no longer
|
|
6
|
+
* restricts to the curated defaults — it only guards against malformed/empty
|
|
7
|
+
* entries so response validation cannot fail on legacy logs. Reactions that
|
|
8
|
+
* were attached before being removed from the configured set still pass.
|
|
9
|
+
*/
|
|
10
|
+
export const isReactionType = (reaction: string): boolean =>
|
|
11
|
+
typeof reaction === 'string' && reaction.trim().length > 0;
|
|
11
12
|
|
|
12
13
|
export type ReactionLogEntry = {
|
|
13
14
|
type: string;
|
package/src/lib/resources.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import {
|
|
3
|
+
RESOURCE_CATEGORY_NAME_MAX_LENGTH,
|
|
3
4
|
RESOURCE_TITLE_MAX_LENGTH,
|
|
4
5
|
visibilityTypeValues,
|
|
5
6
|
type MediaAttachmentData,
|
|
@@ -7,7 +8,7 @@ import {
|
|
|
7
8
|
type VisibilityType,
|
|
8
9
|
} from '../types/models';
|
|
9
10
|
|
|
10
|
-
export { RESOURCE_TITLE_MAX_LENGTH };
|
|
11
|
+
export { RESOURCE_CATEGORY_NAME_MAX_LENGTH, RESOURCE_TITLE_MAX_LENGTH };
|
|
11
12
|
|
|
12
13
|
/** Matches `resourcePostSchema.url` (`z.url()`), after trimming. */
|
|
13
14
|
const resourceUrlSchema = z.url();
|
package/src/types/api.ts
CHANGED
|
@@ -450,6 +450,15 @@ export const muteParticipantRequestSchema = z.object({
|
|
|
450
450
|
export type MuteParticipantRequest = z.infer<
|
|
451
451
|
typeof muteParticipantRequestSchema
|
|
452
452
|
>;
|
|
453
|
+
|
|
454
|
+
export const removeParticipantRequestSchema = z.object({
|
|
455
|
+
identity: z.string().uuid(),
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
export type RemoveParticipantRequest = z.infer<
|
|
459
|
+
typeof removeParticipantRequestSchema
|
|
460
|
+
>;
|
|
461
|
+
|
|
453
462
|
export interface Thread extends PublicPost {
|
|
454
463
|
children: Thread[];
|
|
455
464
|
}
|
package/src/types/config.ts
CHANGED
|
@@ -14,6 +14,17 @@ import { additionalForbiddenHandlesSchema } from './forbiddenHandles';
|
|
|
14
14
|
|
|
15
15
|
export const passwordPlaceHolder = '*********';
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* A post-reaction value: a non-empty emoji (or emoji sequence) string.
|
|
19
|
+
* Communities allow arbitrary emojis via `content.allowedReactions`, so this
|
|
20
|
+
* is a validated string rather than the curated enum. The schema lives here
|
|
21
|
+
* (not in `models.ts`) because `models.ts` already imports from this file,
|
|
22
|
+
* which keeps the dependency one-directional; the curated default set
|
|
23
|
+
* (`REACTION_TYPES`) and the `resolveAllowedReactions` helper live in
|
|
24
|
+
* `models.ts`, which re-exports nothing from the schema.
|
|
25
|
+
*/
|
|
26
|
+
export const reactionEmojiSchema = z.string().trim().min(1).max(32);
|
|
27
|
+
|
|
17
28
|
export const password = (sanitize?: boolean) =>
|
|
18
29
|
sanitize
|
|
19
30
|
? z
|
|
@@ -412,6 +423,13 @@ export const communityConfigSchemaFactory = (_sanitize?: boolean) =>
|
|
|
412
423
|
* Admin-managed via Community → Auto-follow accounts; only resolvable
|
|
413
424
|
* local profiles may be designated (federated handles are rejected). */
|
|
414
425
|
autoFollow: z.string().array().optional(),
|
|
426
|
+
/**
|
|
427
|
+
* Emojis members can attach to posts. Absent (or empty, the "reset"
|
|
428
|
+
* value) keeps the curated default set (REACTION_TYPES). Enforced at
|
|
429
|
+
* the write path; reactions attached before a set change stay visible
|
|
430
|
+
* (orphans).
|
|
431
|
+
*/
|
|
432
|
+
allowedReactions: z.array(reactionEmojiSchema).max(64).optional(),
|
|
415
433
|
}),
|
|
416
434
|
settings: z.object({
|
|
417
435
|
openRegistrations: z.boolean(),
|
package/src/types/models.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi';
|
|
|
5
5
|
import { isEndBeforeStart } from '../lib/eventTime';
|
|
6
6
|
import { hasVisibleText, postContentWithinBudget } from '../lib/contentLength';
|
|
7
7
|
import { groupRelationships } from './capabilities';
|
|
8
|
-
import { capabilitiesSchema } from './config';
|
|
8
|
+
import { capabilitiesSchema, reactionEmojiSchema } from './config';
|
|
9
9
|
import {
|
|
10
10
|
HANDLE_RESERVED_MESSAGE,
|
|
11
11
|
additionalForbiddenHandlesSchema,
|
|
@@ -374,12 +374,16 @@ export const jamDataSchema = z
|
|
|
374
374
|
speakers: z.string().array().optional(),
|
|
375
375
|
presenters: z.string().array().optional(),
|
|
376
376
|
audience: z.string().array().optional(),
|
|
377
|
+
/** Profile ids banned from rejoining this jam; cleared via the lift-ban endpoint. */
|
|
378
|
+
banned: z.string().array().optional(),
|
|
377
379
|
videoEnabled: z.boolean(),
|
|
378
380
|
type: z.enum(['video-call']),
|
|
379
381
|
maxSpeakers: z.number().int().positive().optional(),
|
|
380
382
|
maxPresenters: z.number().int().positive().optional(),
|
|
381
383
|
maxAudience: z.number().int().positive().optional(),
|
|
382
384
|
waitingRoom: z.boolean().optional(),
|
|
385
|
+
/** Opt-in broadcast to the whole community when the jam starts. */
|
|
386
|
+
notifyEveryone: z.boolean().optional(),
|
|
383
387
|
})
|
|
384
388
|
.openapi('Jam');
|
|
385
389
|
|
|
@@ -586,6 +590,9 @@ export type Article = z.infer<typeof articleSchema>;
|
|
|
586
590
|
/** Resource titles are library headings, so they stay much shorter than the description. */
|
|
587
591
|
export const RESOURCE_TITLE_MAX_LENGTH = 200;
|
|
588
592
|
|
|
593
|
+
/** Category (folder) names render inline in cards, trees and breadcrumbs; keep them bounded so a very long name cannot blow out those layouts. */
|
|
594
|
+
export const RESOURCE_CATEGORY_NAME_MAX_LENGTH = 120;
|
|
595
|
+
|
|
589
596
|
export const resourcePostSchema = noteBaseSchema
|
|
590
597
|
.extend({
|
|
591
598
|
type: z.literal('resource'),
|
|
@@ -916,10 +923,8 @@ export const pushSubscriptionSchema = z.discriminatedUnion('type', [
|
|
|
916
923
|
modelSchema(pushSubscriptionWebhookDataSchema),
|
|
917
924
|
]);
|
|
918
925
|
export type PushSubscription = z.infer<typeof pushSubscriptionSchema>;
|
|
919
|
-
/**
|
|
920
|
-
*
|
|
921
|
-
* picker UI and the API schema.
|
|
922
|
-
*/
|
|
926
|
+
/** Curated default reactions: the set that applies when a community has not
|
|
927
|
+
* configured its own via the community config (`content.allowedReactions`). */
|
|
923
928
|
export const REACTION_TYPES = [
|
|
924
929
|
'👍',
|
|
925
930
|
'👎',
|
|
@@ -930,14 +935,28 @@ export const REACTION_TYPES = [
|
|
|
930
935
|
'🎉',
|
|
931
936
|
] as const;
|
|
932
937
|
|
|
933
|
-
export const reactionTypeSchema = z.enum(REACTION_TYPES);
|
|
934
|
-
|
|
935
938
|
export const reactionDataSchema = z.object({
|
|
936
|
-
reaction:
|
|
939
|
+
reaction: reactionEmojiSchema,
|
|
937
940
|
});
|
|
938
941
|
export type ReactionData = z.infer<typeof reactionDataSchema>;
|
|
939
942
|
export type Reaction = Model<ReactionData>;
|
|
940
943
|
|
|
944
|
+
/**
|
|
945
|
+
* The set of reactions a community allows on posts. A configured list (from
|
|
946
|
+
* `communityConfig.content.allowedReactions`) wins; an absent/empty one falls
|
|
947
|
+
* back to the curated defaults.
|
|
948
|
+
*/
|
|
949
|
+
export const resolveAllowedReactions = (
|
|
950
|
+
config?: { content?: { allowedReactions?: readonly string[] } } | null,
|
|
951
|
+
): readonly string[] => {
|
|
952
|
+
const configured = (config?.content?.allowedReactions ?? [])
|
|
953
|
+
.filter((emoji): emoji is string => typeof emoji === 'string')
|
|
954
|
+
.map((emoji) => emoji.trim())
|
|
955
|
+
.filter((emoji) => emoji.length > 0);
|
|
956
|
+
const unique = [...new Set(configured)];
|
|
957
|
+
return unique.length > 0 ? unique : REACTION_TYPES;
|
|
958
|
+
};
|
|
959
|
+
|
|
941
960
|
export const mentionDataSchema = z.object({
|
|
942
961
|
text: z.string().optional(),
|
|
943
962
|
});
|
|
@@ -1004,6 +1023,7 @@ export const jamEventDataSchema = z.object({
|
|
|
1004
1023
|
'leave',
|
|
1005
1024
|
'start',
|
|
1006
1025
|
'close',
|
|
1026
|
+
'kicked',
|
|
1007
1027
|
'recordStart',
|
|
1008
1028
|
'recordStop',
|
|
1009
1029
|
'streamStart',
|
|
@@ -1011,7 +1031,7 @@ export const jamEventDataSchema = z.object({
|
|
|
1011
1031
|
]),
|
|
1012
1032
|
profileId: z.string(),
|
|
1013
1033
|
content: z.string().optional(),
|
|
1014
|
-
reaction:
|
|
1034
|
+
reaction: reactionEmojiSchema.optional(),
|
|
1015
1035
|
recurrenceId: eventIsoDatetimeSchema.optional(),
|
|
1016
1036
|
});
|
|
1017
1037
|
|