@openpeepshq/common 0.1.45 → 0.2.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/adminSections.js +1 -1
- package/dist/lib/capabilitiesHelpers.d.ts +9 -7
- package/dist/lib/capabilitiesHelpers.js +43 -38
- package/dist/lib/csvHelpers.js +1 -1
- package/dist/lib/eventIcs.d.ts +17 -0
- package/dist/lib/eventIcs.js +91 -15
- package/dist/lib/eventRecurrence.d.ts +19 -0
- package/dist/lib/eventRecurrence.js +82 -20
- package/dist/lib/eventTime.d.ts +7 -0
- package/dist/lib/eventTime.js +23 -9
- package/dist/lib/federationHosts.d.ts +3 -0
- package/dist/lib/federationHosts.js +17 -0
- package/dist/lib/feedCursor.d.ts +14 -0
- package/dist/lib/feedCursor.js +22 -0
- package/dist/lib/feedFormat.d.ts +12 -0
- package/dist/lib/feedFormat.js +14 -0
- package/dist/lib/groupHelpers.js +13 -34
- package/dist/lib/groupTemplateHelpers.js +6 -10
- package/dist/lib/index.d.ts +7 -0
- package/dist/lib/index.js +7 -0
- package/dist/lib/jamHelpers.d.ts +11 -2
- package/dist/lib/jamHelpers.js +43 -9
- package/dist/lib/legacyThemeRoot.d.ts +3 -0
- package/dist/lib/legacyThemeRoot.js +10 -0
- package/dist/lib/markdownHelpers.d.ts +8 -0
- package/dist/lib/markdownHelpers.js +34 -6
- package/dist/lib/postHelpers.d.ts +142 -3
- package/dist/lib/postHelpers.js +323 -47
- package/dist/lib/profileHelpers.d.ts +11 -0
- package/dist/lib/profileHelpers.js +34 -10
- package/dist/lib/pushHelpers.js +3 -4
- package/dist/lib/reactions.d.ts +17 -0
- package/dist/lib/reactions.js +37 -0
- package/dist/lib/scopeHelpers.d.ts +31 -2
- package/dist/lib/scopeHelpers.js +39 -8
- package/dist/lib/ssoLoginUrl.js +4 -6
- package/dist/lib/ssoProviders.d.ts +72 -0
- package/dist/lib/ssoProviders.js +366 -0
- package/dist/lib/timeZone.d.ts +9 -0
- package/dist/lib/timeZone.js +44 -0
- package/dist/lib/tokenHelpers.js +5 -5
- package/dist/lib/utils.js +6 -7
- package/dist/types/admin-db.js +1 -1
- package/dist/types/analytics.d.ts +20 -0
- package/dist/types/analytics.js +4 -0
- package/dist/types/api.d.ts +41800 -11853
- package/dist/types/api.js +53 -5
- package/dist/types/auth.d.ts +20 -6
- package/dist/types/capabilities.d.ts +15 -1
- package/dist/types/capabilities.js +51 -0
- package/dist/types/config.d.ts +99 -0
- package/dist/types/config.js +56 -4
- package/dist/types/db.d.ts +1155 -164
- package/dist/types/db.js +14 -0
- package/dist/types/export.d.ts +120 -0
- package/dist/types/export.js +7 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +2 -0
- package/dist/types/internal.d.ts +2577 -524
- package/dist/types/internal.js +6 -0
- package/dist/types/models.d.ts +63 -7
- package/dist/types/models.js +40 -3
- package/dist/types/plugins.d.ts +22 -0
- package/dist/types/plugins.js +66 -0
- package/dist/types/roleDefaults.d.ts +31 -0
- package/dist/types/roleDefaults.js +110 -0
- package/dist/types/stats.d.ts +54606 -6065
- package/dist/types/stats.js +30 -0
- package/dist/types/utils.d.ts +2 -0
- package/dist/types/utils.js +1 -3
- package/dist/zod.d.ts +1 -0
- package/dist/zod.js +1 -0
- package/package.json +36 -6
- package/src/index.ts +4 -0
- package/src/lib/adminSections.ts +84 -0
- package/src/lib/attachmentHelpers.ts +14 -0
- package/src/lib/capabilitiesHelpers.ts +532 -0
- package/src/lib/colors.ts +20 -0
- package/src/lib/csvHelpers.ts +31 -0
- package/src/lib/eventIcs.ts +265 -0
- package/src/lib/eventRecurrence.ts +495 -0
- package/src/lib/eventTime.ts +206 -0
- package/src/lib/federationHosts.ts +22 -0
- package/src/lib/feedCursor.ts +27 -0
- package/src/lib/feedFormat.ts +24 -0
- package/src/lib/groupHelpers.ts +421 -0
- package/src/lib/groupTemplateHelpers.ts +83 -0
- package/src/lib/index.ts +29 -0
- package/src/lib/jamHelpers.ts +164 -0
- package/src/lib/legacyThemeRoot.ts +14 -0
- package/src/lib/markdownHelpers.ts +122 -0
- package/src/lib/mediaDimensions.ts +21 -0
- package/src/lib/postHelpers.ts +783 -0
- package/src/lib/profileHelpers.ts +220 -0
- package/src/lib/pushHelpers.ts +34 -0
- package/src/lib/reactions.ts +52 -0
- package/src/lib/reportHelpers.ts +7 -0
- package/src/lib/scopeHelpers.ts +176 -0
- package/src/lib/ssoLoginUrl.ts +93 -0
- package/src/lib/ssoProviders.ts +472 -0
- package/src/lib/text.ts +26 -0
- package/src/lib/timeZone.ts +52 -0
- package/src/lib/tokenHelpers.ts +119 -0
- package/src/lib/utils.ts +322 -0
- package/src/types/admin-db.ts +74 -0
- package/src/types/admin-email.ts +55 -0
- package/src/types/admin-jobs.ts +17 -0
- package/src/types/admin-performance.ts +20 -0
- package/src/types/analytics.ts +318 -0
- package/src/types/api.ts +871 -0
- package/src/types/apple-app-site-association.ts +54 -0
- package/src/types/auth.ts +22 -0
- package/src/types/capabilities.ts +280 -0
- package/src/types/config.ts +546 -0
- package/src/types/db.ts +138 -0
- package/src/types/export.ts +10 -0
- package/src/types/index.ts +20 -0
- package/src/types/internal.ts +338 -0
- package/src/types/models.ts +939 -0
- package/src/types/notifications.ts +92 -0
- package/src/types/plugins.ts +150 -0
- package/src/types/roleDefaults.ts +132 -0
- package/src/types/stats.ts +195 -0
- package/src/types/stripe.ts +45 -0
- package/src/types/utils.ts +100 -0
- package/src/zod.ts +1 -0
package/dist/types/stats.js
CHANGED
|
@@ -99,6 +99,11 @@ export const serverCountsSchema = z.object({
|
|
|
99
99
|
reactions: z.number(),
|
|
100
100
|
rsvps: z.number(),
|
|
101
101
|
});
|
|
102
|
+
export const hostResourceStatsSchema = z.object({
|
|
103
|
+
memoryUsedBytes: z.number().nonnegative(),
|
|
104
|
+
memoryTotalBytes: z.number().nonnegative(),
|
|
105
|
+
cpuUsedPercent: z.number().min(0).max(100),
|
|
106
|
+
});
|
|
102
107
|
export const adminServerStatsSchema = z.object({
|
|
103
108
|
profiles: profilesStatsSchema,
|
|
104
109
|
posts: postsStatsSchema,
|
|
@@ -106,4 +111,29 @@ export const adminServerStatsSchema = z.object({
|
|
|
106
111
|
jams: jamsStatsSchema,
|
|
107
112
|
topLists: topListsStatsSchema,
|
|
108
113
|
timelines: timelinesStatsSchema,
|
|
114
|
+
host: hostResourceStatsSchema,
|
|
115
|
+
});
|
|
116
|
+
export const profileActivitySummarySchema = z.object({
|
|
117
|
+
postsCount: z.number().int().nonnegative(),
|
|
118
|
+
repliesCount: z.number().int().nonnegative(),
|
|
119
|
+
eventsCount: z.number().int().nonnegative(),
|
|
120
|
+
reactionsGiven: z.number().int().nonnegative(),
|
|
121
|
+
reactionsReceived: z.number().int().nonnegative(),
|
|
122
|
+
repostsCount: z.number().int().nonnegative(),
|
|
123
|
+
repostsReceived: z.number().int().nonnegative(),
|
|
124
|
+
repliesReceived: z.number().int().nonnegative(),
|
|
125
|
+
rsvpsCount: z.number().int().nonnegative(),
|
|
126
|
+
bookmarksCount: z.number().int().nonnegative(),
|
|
127
|
+
groupsCount: z.number().int().nonnegative(),
|
|
128
|
+
topPosts: publicPostWithActivityScoreSchema.array().max(5),
|
|
129
|
+
});
|
|
130
|
+
export const adminProfileSummarySchema = z.object({
|
|
131
|
+
profile: publicProfileSchema,
|
|
132
|
+
activity: profileActivitySummarySchema,
|
|
133
|
+
createdAt: z.string().datetime(),
|
|
134
|
+
email: z.string().optional(),
|
|
135
|
+
followersCount: z.number().int().nonnegative(),
|
|
136
|
+
followingCount: z.number().int().nonnegative(),
|
|
137
|
+
reportsCount: z.number().int().nonnegative(),
|
|
138
|
+
blockedByCount: z.number().int().nonnegative(),
|
|
109
139
|
});
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -57,6 +57,8 @@ export interface EmailGlobals {
|
|
|
57
57
|
i18n: i18n;
|
|
58
58
|
t: i18n['t'];
|
|
59
59
|
};
|
|
60
|
+
/** Recipient display timezone: profile setting, else community, else UTC. */
|
|
61
|
+
timeZone: string;
|
|
60
62
|
}
|
|
61
63
|
export interface EmailOptionsWithGlobals extends EmailOptions {
|
|
62
64
|
globals: EmailGlobals;
|
package/dist/types/utils.js
CHANGED
|
@@ -8,9 +8,7 @@ import { z } from 'zod';
|
|
|
8
8
|
export const jsonSchema = z
|
|
9
9
|
.any()
|
|
10
10
|
.openapi('JsonValue', { type: 'object' });
|
|
11
|
-
export const i18nResourceKeySchema = z
|
|
12
|
-
.any()
|
|
13
|
-
.openapi('I18nResourceKey', {
|
|
11
|
+
export const i18nResourceKeySchema = z.any().openapi('I18nResourceKey', {
|
|
14
12
|
type: 'object',
|
|
15
13
|
});
|
|
16
14
|
export const i18nResourceLanguageSchema = z.record(z.string(), i18nResourceKeySchema);
|
package/dist/zod.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'zod';
|
package/dist/zod.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'zod';
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpeepshq/common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
6
7
|
"dependencies": {
|
|
7
8
|
"@asteasolutions/zod-to-openapi": "^8.5.0",
|
|
8
9
|
"date-fns": "^4.1.0",
|
|
@@ -13,14 +14,42 @@
|
|
|
13
14
|
"validator": "^13.15.35",
|
|
14
15
|
"zod": "^4.4.3"
|
|
15
16
|
},
|
|
16
|
-
"main": "dist/index.js",
|
|
17
|
-
"types": "dist/index.d.ts",
|
|
17
|
+
"main": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
18
19
|
"exports": {
|
|
19
|
-
".":
|
|
20
|
-
|
|
20
|
+
".": {
|
|
21
|
+
"react-native": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"default": "./src/index.ts"
|
|
24
|
+
},
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"node": "./dist/index.js",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./zod": {
|
|
30
|
+
"react-native": {
|
|
31
|
+
"types": "./dist/zod.d.ts",
|
|
32
|
+
"default": "./src/zod.ts"
|
|
33
|
+
},
|
|
34
|
+
"types": "./dist/zod.d.ts",
|
|
35
|
+
"node": "./dist/zod.js",
|
|
36
|
+
"default": "./dist/zod.js"
|
|
37
|
+
},
|
|
38
|
+
"./*": {
|
|
39
|
+
"react-native": {
|
|
40
|
+
"types": "./dist/*/index.d.ts",
|
|
41
|
+
"default": "./src/*/index.ts"
|
|
42
|
+
},
|
|
43
|
+
"types": "./dist/*/index.d.ts",
|
|
44
|
+
"node": "./dist/*/index.js",
|
|
45
|
+
"default": "./dist/*/index.js"
|
|
46
|
+
}
|
|
21
47
|
},
|
|
22
48
|
"files": [
|
|
23
|
-
"
|
|
49
|
+
"src",
|
|
50
|
+
"dist",
|
|
51
|
+
"!**/__tests__",
|
|
52
|
+
"!**/*.test.ts"
|
|
24
53
|
],
|
|
25
54
|
"devDependencies": {
|
|
26
55
|
"@types/node": "^24.1.12",
|
|
@@ -44,6 +73,7 @@
|
|
|
44
73
|
"lint": "prettier --check . && eslint .",
|
|
45
74
|
"format": "prettier --write .",
|
|
46
75
|
"clean": "rm -rf tsconfig.tsbuildinfo dist",
|
|
76
|
+
"typecheck": "tsc --noEmit",
|
|
47
77
|
"build": "tsc && tsc-alias",
|
|
48
78
|
"build:watch": "tsc && tsc-alias && (concurrently \"tsc -w\" \"tsc-alias -w\")",
|
|
49
79
|
"test": "vitest",
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { Role } from '../types';
|
|
2
|
+
import { checkRoleCapabilities } from './capabilitiesHelpers';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Admin sidebar sections and the role capabilities required to see each one.
|
|
6
|
+
* All listed capabilities must be present (AND). Matches `ensureRoleCapabilities`
|
|
7
|
+
* on the corresponding admin API routes.
|
|
8
|
+
*/
|
|
9
|
+
export const adminSections = [
|
|
10
|
+
{
|
|
11
|
+
key: 'members',
|
|
12
|
+
path: '/admin/members',
|
|
13
|
+
capabilities: ['core-accounts-read', 'core-profiles-read'],
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
key: 'groups',
|
|
17
|
+
path: '/admin/groups',
|
|
18
|
+
capabilities: ['core-groups-read'],
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
key: 'invites',
|
|
22
|
+
path: '/admin/invites',
|
|
23
|
+
capabilities: ['core-inviteLinks-read'],
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
key: 'moderation',
|
|
27
|
+
path: '/admin/moderation',
|
|
28
|
+
capabilities: ['core-reports-read'],
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
key: 'backups',
|
|
32
|
+
path: '/admin/backups',
|
|
33
|
+
capabilities: ['core-backups-read'],
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
key: 'analytics',
|
|
37
|
+
path: '/admin/analytics',
|
|
38
|
+
capabilities: ['core-analytics-read'],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
key: 'apiKeys',
|
|
42
|
+
path: '/admin/api-keys',
|
|
43
|
+
capabilities: ['core-serviceTokens-read'],
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
key: 'plugins',
|
|
47
|
+
path: '/admin/plugins',
|
|
48
|
+
capabilities: ['core-plugins-manage'],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
key: 'configuration',
|
|
52
|
+
path: '/admin/configuration',
|
|
53
|
+
capabilities: ['core-config-read'],
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
key: 'diagnostics',
|
|
57
|
+
path: '/admin/diagnostics',
|
|
58
|
+
capabilities: ['core-config-read'],
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
key: 'database',
|
|
62
|
+
path: '/admin/db',
|
|
63
|
+
capabilities: ['core-db-access'],
|
|
64
|
+
},
|
|
65
|
+
] as const;
|
|
66
|
+
|
|
67
|
+
export type AdminSectionKey = (typeof adminSections)[number]['key'];
|
|
68
|
+
|
|
69
|
+
export type AdminSection = (typeof adminSections)[number];
|
|
70
|
+
|
|
71
|
+
export const canAccessAdminSection = (
|
|
72
|
+
roles: Role[] | undefined,
|
|
73
|
+
section: AdminSection,
|
|
74
|
+
): boolean =>
|
|
75
|
+
checkRoleCapabilities(roles ?? [], [...section.capabilities]).success;
|
|
76
|
+
|
|
77
|
+
export const getVisibleAdminSections = (
|
|
78
|
+
roles: Role[] | undefined,
|
|
79
|
+
): AdminSection[] =>
|
|
80
|
+
adminSections.filter((section) => canAccessAdminSection(roles, section));
|
|
81
|
+
|
|
82
|
+
/** True when the profile may see at least one admin menu entry. */
|
|
83
|
+
export const canAccessAdminMenu = (roles: Role[] | undefined): boolean =>
|
|
84
|
+
getVisibleAdminSections(roles).length > 0;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const getAttachmentType = (file: File) => {
|
|
2
|
+
if (file.name.endsWith('.mkv')) {
|
|
3
|
+
return 'video';
|
|
4
|
+
}
|
|
5
|
+
if (file.name.endsWith('.pdf') || file.name.endsWith('.doc') || file.name.endsWith('.docx') || file.name.endsWith('.odt') || file.name.endsWith('.txt')) {
|
|
6
|
+
return 'document';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const mimeTypeFirstPart = file.type.split('/')[0];
|
|
10
|
+
if (mimeTypeFirstPart === 'application' || mimeTypeFirstPart === 'text') {
|
|
11
|
+
return 'document';
|
|
12
|
+
}
|
|
13
|
+
return mimeTypeFirstPart;
|
|
14
|
+
}
|