@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
|
@@ -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;
|
|
@@ -12,7 +12,7 @@ export type ThreadPreviewGroup = {
|
|
|
12
12
|
posts: ThreadPreviewPost[];
|
|
13
13
|
};
|
|
14
14
|
export declare const buildThreadPreview: (rootId: string, replies: ThreadPreviewPost[]) => ThreadPreviewGroup[];
|
|
15
|
-
export declare const getReactionCount: (post: PublicPost) => Record<
|
|
15
|
+
export declare const getReactionCount: (post: PublicPost) => Record<string, number>;
|
|
16
16
|
export declare const countVotes: (optionsCount: number, answers: Answer[]) => number[];
|
|
17
17
|
/** Fill blank poll choices with their placeholder label (e.g. "Option 1"). */
|
|
18
18
|
export declare const resolvePollOptionContents: (options: readonly string[], fallbackLabel: (index: number) => string) => 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 ||
|
package/dist/lib/reactions.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export declare const AP_LIKE_REACTION = "\uD83D\uDC4D";
|
|
2
|
+
/**
|
|
3
|
+
* Whether a logged reaction value is usable: a non-empty emoji string.
|
|
4
|
+
* The community may configure a custom allowed set, so this no longer
|
|
5
|
+
* restricts to the curated defaults — it only guards against malformed/empty
|
|
6
|
+
* entries so response validation cannot fail on legacy logs. Reactions that
|
|
7
|
+
* were attached before being removed from the configured set still pass.
|
|
8
|
+
*/
|
|
9
|
+
export declare const isReactionType: (reaction: string) => boolean;
|
|
6
10
|
export type ReactionLogEntry = {
|
|
7
11
|
type: string;
|
|
8
12
|
createdAt: string;
|
package/dist/lib/reactions.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export const AP_LIKE_REACTION = '👍';
|
|
2
|
+
/**
|
|
3
|
+
* Whether a logged reaction value is usable: a non-empty emoji string.
|
|
4
|
+
* The community may configure a custom allowed set, so this no longer
|
|
5
|
+
* restricts to the curated defaults — it only guards against malformed/empty
|
|
6
|
+
* entries so response validation cannot fail on legacy logs. Reactions that
|
|
7
|
+
* were attached before being removed from the configured set still pass.
|
|
8
|
+
*/
|
|
9
|
+
export const isReactionType = (reaction) => typeof reaction === 'string' && reaction.trim().length > 0;
|
|
6
10
|
const reactionFromData = (data) => {
|
|
7
11
|
if (!data || typeof data !== 'object' || !('reaction' in data)) {
|
|
8
12
|
return undefined;
|
package/dist/lib/resources.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RESOURCE_TITLE_MAX_LENGTH, type MediaAttachmentData, type ResourceKind, type VisibilityType } from '../types/models';
|
|
2
|
-
export { RESOURCE_TITLE_MAX_LENGTH };
|
|
1
|
+
import { RESOURCE_CATEGORY_NAME_MAX_LENGTH, RESOURCE_TITLE_MAX_LENGTH, type MediaAttachmentData, type ResourceKind, type VisibilityType } from '../types/models';
|
|
2
|
+
export { RESOURCE_CATEGORY_NAME_MAX_LENGTH, RESOURCE_TITLE_MAX_LENGTH };
|
|
3
3
|
export declare const isValidResourceUrl: (url: string | undefined) => boolean;
|
|
4
4
|
export declare const RESOURCE_KINDS: readonly ["video", "file", "gallery", "audio", "link"];
|
|
5
5
|
export declare const attachmentMediaKind: (att: Pick<MediaAttachmentData, "type" | "meta">) => "image" | "video" | "audio" | "file";
|
package/dist/lib/resources.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { RESOURCE_TITLE_MAX_LENGTH, visibilityTypeValues, } from '../types/models.js';
|
|
3
|
-
export { RESOURCE_TITLE_MAX_LENGTH };
|
|
2
|
+
import { RESOURCE_CATEGORY_NAME_MAX_LENGTH, RESOURCE_TITLE_MAX_LENGTH, visibilityTypeValues, } from '../types/models.js';
|
|
3
|
+
export { RESOURCE_CATEGORY_NAME_MAX_LENGTH, RESOURCE_TITLE_MAX_LENGTH };
|
|
4
4
|
/** Matches `resourcePostSchema.url` (`z.url()`), after trimming. */
|
|
5
5
|
const resourceUrlSchema = z.url();
|
|
6
6
|
export const isValidResourceUrl = (url) => {
|