@openpeepshq/common 0.13.0 → 0.15.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 +1 -1
- 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 +132 -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 +29 -63
- package/dist/types/export.d.ts +54 -118
- package/dist/types/export.js +35 -5
- package/dist/types/internal.d.ts +54 -90
- package/dist/types/models.d.ts +28 -40
- package/dist/types/models.js +23 -8
- package/dist/types/stats.d.ts +116 -72
- package/package.json +1 -1
- 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/export.ts +56 -6
- package/src/types/models.ts +27 -9
package/package.json
CHANGED
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/export.ts
CHANGED
|
@@ -1,10 +1,60 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { publicAccountSchema, publicProfileSchema } from './api';
|
|
3
2
|
|
|
4
|
-
/**
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Full personal data export (GDPR-style). Requested via `POST`, assembled
|
|
5
|
+
* asynchronously by a worker job, downloaded via a short-lived token.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export const accountExportJobSchema = z.object({
|
|
9
|
+
jobId: z.uuid(),
|
|
10
|
+
});
|
|
11
|
+
export type AccountExportJob = z.infer<typeof accountExportJobSchema>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Lifecycle states of an account export, as reported by the status endpoint:
|
|
15
|
+
* - `building` — the worker has not (yet) written a record, or is assembling
|
|
16
|
+
* the archive; the client keeps polling.
|
|
17
|
+
* - `ready` — the archive exists; the response carries the single-use
|
|
18
|
+
* `downloadToken` and its `expiresAt`. The client stops polling and offers
|
|
19
|
+
* the download.
|
|
20
|
+
* - `error` — assembly failed; the response carries `error`. Stop polling.
|
|
21
|
+
* - `expired` — the record's token lapsed or the archive was cleaned up; the
|
|
22
|
+
* client stops polling and asks the user to start a new export.
|
|
23
|
+
* - `not-found` — no record for the given `jobId` (unknown to this account).
|
|
24
|
+
*/
|
|
25
|
+
export const accountExportStateSchema = z.enum([
|
|
26
|
+
'building',
|
|
27
|
+
'ready',
|
|
28
|
+
'error',
|
|
29
|
+
'expired',
|
|
30
|
+
'not-found',
|
|
31
|
+
]);
|
|
32
|
+
export type AccountExportState = z.infer<typeof accountExportStateSchema>;
|
|
33
|
+
|
|
34
|
+
/** `GET /accounts/current/export/status?jobId=…` */
|
|
35
|
+
export const accountExportStatusSchema = z.object({
|
|
36
|
+
jobId: z.uuid(),
|
|
37
|
+
state: accountExportStateSchema,
|
|
38
|
+
/** Present once `state === 'ready'`. Pass to the download endpoint. */
|
|
39
|
+
downloadToken: z.string().optional(),
|
|
40
|
+
/** When `state === 'ready'`, the download token stops working after this. */
|
|
41
|
+
expiresAt: z.string().datetime().optional(),
|
|
42
|
+
error: z.string().optional(),
|
|
8
43
|
});
|
|
44
|
+
export type AccountExportStatus = z.infer<typeof accountExportStatusSchema>;
|
|
9
45
|
|
|
10
|
-
|
|
46
|
+
/**
|
|
47
|
+
* The "ready" payload shared by every producer of a finished export — the
|
|
48
|
+
* worker that assembles the archive and the status endpoint that reports it.
|
|
49
|
+
* Single-sourcing the `state`/`downloadToken`/`expiresAt` triple here keeps the
|
|
50
|
+
* two from drifting as the API grows (adding a field to the shape now means
|
|
51
|
+
* touching one type instead of both construction sites). Type-only: it mirrors
|
|
52
|
+
* `AccountExportStatus`'s ready fields, so it changes no runtime surface.
|
|
53
|
+
*/
|
|
54
|
+
export type AccountExportReady = Pick<
|
|
55
|
+
AccountExportStatus,
|
|
56
|
+
'downloadToken' | 'expiresAt'
|
|
57
|
+
> & {
|
|
58
|
+
/** The ready state, as a literal — the only state that carries the fields. */
|
|
59
|
+
state: 'ready';
|
|
60
|
+
};
|
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,6 +374,8 @@ 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(),
|
|
@@ -588,6 +590,9 @@ export type Article = z.infer<typeof articleSchema>;
|
|
|
588
590
|
/** Resource titles are library headings, so they stay much shorter than the description. */
|
|
589
591
|
export const RESOURCE_TITLE_MAX_LENGTH = 200;
|
|
590
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
|
+
|
|
591
596
|
export const resourcePostSchema = noteBaseSchema
|
|
592
597
|
.extend({
|
|
593
598
|
type: z.literal('resource'),
|
|
@@ -918,10 +923,8 @@ export const pushSubscriptionSchema = z.discriminatedUnion('type', [
|
|
|
918
923
|
modelSchema(pushSubscriptionWebhookDataSchema),
|
|
919
924
|
]);
|
|
920
925
|
export type PushSubscription = z.infer<typeof pushSubscriptionSchema>;
|
|
921
|
-
/**
|
|
922
|
-
*
|
|
923
|
-
* picker UI and the API schema.
|
|
924
|
-
*/
|
|
926
|
+
/** Curated default reactions: the set that applies when a community has not
|
|
927
|
+
* configured its own via the community config (`content.allowedReactions`). */
|
|
925
928
|
export const REACTION_TYPES = [
|
|
926
929
|
'👍',
|
|
927
930
|
'👎',
|
|
@@ -932,14 +935,28 @@ export const REACTION_TYPES = [
|
|
|
932
935
|
'🎉',
|
|
933
936
|
] as const;
|
|
934
937
|
|
|
935
|
-
export const reactionTypeSchema = z.enum(REACTION_TYPES);
|
|
936
|
-
|
|
937
938
|
export const reactionDataSchema = z.object({
|
|
938
|
-
reaction:
|
|
939
|
+
reaction: reactionEmojiSchema,
|
|
939
940
|
});
|
|
940
941
|
export type ReactionData = z.infer<typeof reactionDataSchema>;
|
|
941
942
|
export type Reaction = Model<ReactionData>;
|
|
942
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
|
+
|
|
943
960
|
export const mentionDataSchema = z.object({
|
|
944
961
|
text: z.string().optional(),
|
|
945
962
|
});
|
|
@@ -1006,6 +1023,7 @@ export const jamEventDataSchema = z.object({
|
|
|
1006
1023
|
'leave',
|
|
1007
1024
|
'start',
|
|
1008
1025
|
'close',
|
|
1026
|
+
'kicked',
|
|
1009
1027
|
'recordStart',
|
|
1010
1028
|
'recordStop',
|
|
1011
1029
|
'streamStart',
|
|
@@ -1013,7 +1031,7 @@ export const jamEventDataSchema = z.object({
|
|
|
1013
1031
|
]),
|
|
1014
1032
|
profileId: z.string(),
|
|
1015
1033
|
content: z.string().optional(),
|
|
1016
|
-
reaction:
|
|
1034
|
+
reaction: reactionEmojiSchema.optional(),
|
|
1017
1035
|
recurrenceId: eventIsoDatetimeSchema.optional(),
|
|
1018
1036
|
});
|
|
1019
1037
|
|