@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Answer, AnswerWithPublicProfile, AuthorizationData, CapabilitiesConfig, EntryWithPublicProfile, Event, GroupWithMeta, PostType, PostDataUnion, PublicPost, PublicProfile, PublicRsvp, RSVP, Thread, VisibilityType } from '../types';
|
|
1
|
+
import { Answer, AnswerWithPublicProfile, AuthorizationData, CapabilitiesConfig, EntryWithPublicProfile, Event, GroupWithMeta, PostType, PostDataUnion, PublicPost, PublicProfile, PublicRsvp, Role, RSVP, Thread, VisibilityType } from '../types';
|
|
2
2
|
export declare const buildThreads: (posts: PublicPost[]) => Thread[];
|
|
3
3
|
export type ThreadPreviewPost = {
|
|
4
4
|
id: string;
|
|
@@ -261,6 +261,23 @@ export declare const parseEventMaxAttendeesInput: (raw: string) => number | unde
|
|
|
261
261
|
export declare const normalizeWaitlistOfferMinutes: (value: number | null | undefined) => number | undefined;
|
|
262
262
|
export declare const parseEventWaitlistOfferMinutesInput: (raw: string) => number | undefined;
|
|
263
263
|
export declare const withoutEventMaxAttendees: <T extends Event>(event: T) => T;
|
|
264
|
+
/** A community-wide jam only broadcasts when the creator opted in. */
|
|
265
|
+
export declare const withoutJamNotifyEveryone: <T extends Event>(event: T) => T;
|
|
266
|
+
/**
|
|
267
|
+
* Broadcast requires community-wide visibility AND the announce capability
|
|
268
|
+
* (same rule as `POST /admin/posts/:postId/announce`); other visibilities or
|
|
269
|
+
* roles drop the flag. The capability check matters because the save path is
|
|
270
|
+
* reachable without the UI toggle: a plain member's role wildcard-matches
|
|
271
|
+
* `core-posts-create-*`, so a crafted API payload could otherwise plant the
|
|
272
|
+
* flag and blast the whole instance.
|
|
273
|
+
*
|
|
274
|
+
* Exported (rather than kept module-local) because `@openpeepshq/core`'s
|
|
275
|
+
* `createPost`/`updatePost` mutations apply it on the server-side save path;
|
|
276
|
+
* it is not a general-purpose utility — unlike `withoutJamNotifyEveryone` and
|
|
277
|
+
* `withoutEventMaxAttendees`, it takes the creator's roles in addition to the
|
|
278
|
+
* event.
|
|
279
|
+
*/
|
|
280
|
+
export declare const withoutCommunityJamNotifyEveryone: <T extends Event>(event: T, visibility: string | undefined, roles?: Role[]) => T;
|
|
264
281
|
export declare const normalizeEventDataForSave: <T extends Event>(event: T) => T;
|
|
265
282
|
/** Null capacity means it was cleared; strip for validation/output. */
|
|
266
283
|
export declare const normalizeEventDataFromDb: <T extends Event>(event: T) => T;
|
package/dist/lib/postHelpers.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { POLL_OPTION_MAX_LENGTH, visibilityTypeValues, } from '../types/index.js';
|
|
2
2
|
import { canModerateJam } from './jamHelpers.js';
|
|
3
|
+
import { canAnnouncePosts, isCommunityWideVisibility, } from './capabilitiesHelpers.js';
|
|
3
4
|
import { defaultRsvpRecurrenceId, effectiveEventTimes, isRecurringEvent, listRsvpOccurrences, normalizeRecurrenceId, sameRecurrenceId, } from './eventRecurrence.js';
|
|
4
5
|
import { formatEventWhen } from './eventTime.js';
|
|
5
6
|
import { checkCapabilities, checkGroupCapabilities, checkPostCapabilities, checkRoleCapabilities, getGroupCapabilities, } from './capabilitiesHelpers.js';
|
|
@@ -368,6 +369,29 @@ export const withoutEventMaxAttendees = (event) => {
|
|
|
368
369
|
const { maxAttendees: _, waitlistOfferMinutes: __, ...rest } = event;
|
|
369
370
|
return rest;
|
|
370
371
|
};
|
|
372
|
+
/** A community-wide jam only broadcasts when the creator opted in. */
|
|
373
|
+
export const withoutJamNotifyEveryone = (event) => {
|
|
374
|
+
if (!event.jam?.notifyEveryone)
|
|
375
|
+
return event;
|
|
376
|
+
return { ...event, jam: { ...event.jam, notifyEveryone: undefined } };
|
|
377
|
+
};
|
|
378
|
+
/**
|
|
379
|
+
* Broadcast requires community-wide visibility AND the announce capability
|
|
380
|
+
* (same rule as `POST /admin/posts/:postId/announce`); other visibilities or
|
|
381
|
+
* roles drop the flag. The capability check matters because the save path is
|
|
382
|
+
* reachable without the UI toggle: a plain member's role wildcard-matches
|
|
383
|
+
* `core-posts-create-*`, so a crafted API payload could otherwise plant the
|
|
384
|
+
* flag and blast the whole instance.
|
|
385
|
+
*
|
|
386
|
+
* Exported (rather than kept module-local) because `@openpeepshq/core`'s
|
|
387
|
+
* `createPost`/`updatePost` mutations apply it on the server-side save path;
|
|
388
|
+
* it is not a general-purpose utility — unlike `withoutJamNotifyEveryone` and
|
|
389
|
+
* `withoutEventMaxAttendees`, it takes the creator's roles in addition to the
|
|
390
|
+
* event.
|
|
391
|
+
*/
|
|
392
|
+
export const withoutCommunityJamNotifyEveryone = (event, visibility, roles) => isCommunityWideVisibility(visibility) && canAnnouncePosts(roles)
|
|
393
|
+
? event
|
|
394
|
+
: withoutJamNotifyEveryone(event);
|
|
371
395
|
export const normalizeEventDataForSave = (event) => {
|
|
372
396
|
const { maxAttendees } = event;
|
|
373
397
|
if (maxAttendees == null ||
|