@openpeepshq/common 0.12.0 → 0.13.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 +18 -1
- package/dist/lib/postHelpers.js +24 -0
- package/dist/types/api.d.ts +118 -0
- package/dist/types/db.d.ts +22 -0
- package/dist/types/internal.d.ts +44 -0
- package/dist/types/models.d.ts +9 -0
- package/dist/types/models.js +2 -0
- package/dist/types/stats.d.ts +108 -0
- package/package.json +1 -1
- package/src/lib/postHelpers.ts +34 -0
- package/src/types/models.ts +2 -0
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/types/models.ts
CHANGED
|
@@ -380,6 +380,8 @@ export const jamDataSchema = z
|
|
|
380
380
|
maxPresenters: z.number().int().positive().optional(),
|
|
381
381
|
maxAudience: z.number().int().positive().optional(),
|
|
382
382
|
waitingRoom: z.boolean().optional(),
|
|
383
|
+
/** Opt-in broadcast to the whole community when the jam starts. */
|
|
384
|
+
notifyEveryone: z.boolean().optional(),
|
|
383
385
|
})
|
|
384
386
|
.openapi('Jam');
|
|
385
387
|
|