@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.
Files changed (126) hide show
  1. package/dist/lib/adminSections.js +1 -1
  2. package/dist/lib/capabilitiesHelpers.d.ts +9 -7
  3. package/dist/lib/capabilitiesHelpers.js +43 -38
  4. package/dist/lib/csvHelpers.js +1 -1
  5. package/dist/lib/eventIcs.d.ts +17 -0
  6. package/dist/lib/eventIcs.js +91 -15
  7. package/dist/lib/eventRecurrence.d.ts +19 -0
  8. package/dist/lib/eventRecurrence.js +82 -20
  9. package/dist/lib/eventTime.d.ts +7 -0
  10. package/dist/lib/eventTime.js +23 -9
  11. package/dist/lib/federationHosts.d.ts +3 -0
  12. package/dist/lib/federationHosts.js +17 -0
  13. package/dist/lib/feedCursor.d.ts +14 -0
  14. package/dist/lib/feedCursor.js +22 -0
  15. package/dist/lib/feedFormat.d.ts +12 -0
  16. package/dist/lib/feedFormat.js +14 -0
  17. package/dist/lib/groupHelpers.js +13 -34
  18. package/dist/lib/groupTemplateHelpers.js +6 -10
  19. package/dist/lib/index.d.ts +7 -0
  20. package/dist/lib/index.js +7 -0
  21. package/dist/lib/jamHelpers.d.ts +11 -2
  22. package/dist/lib/jamHelpers.js +43 -9
  23. package/dist/lib/legacyThemeRoot.d.ts +3 -0
  24. package/dist/lib/legacyThemeRoot.js +10 -0
  25. package/dist/lib/markdownHelpers.d.ts +8 -0
  26. package/dist/lib/markdownHelpers.js +34 -6
  27. package/dist/lib/postHelpers.d.ts +142 -3
  28. package/dist/lib/postHelpers.js +323 -47
  29. package/dist/lib/profileHelpers.d.ts +11 -0
  30. package/dist/lib/profileHelpers.js +34 -10
  31. package/dist/lib/pushHelpers.js +3 -4
  32. package/dist/lib/reactions.d.ts +17 -0
  33. package/dist/lib/reactions.js +37 -0
  34. package/dist/lib/scopeHelpers.d.ts +31 -2
  35. package/dist/lib/scopeHelpers.js +39 -8
  36. package/dist/lib/ssoLoginUrl.js +4 -6
  37. package/dist/lib/ssoProviders.d.ts +72 -0
  38. package/dist/lib/ssoProviders.js +366 -0
  39. package/dist/lib/timeZone.d.ts +9 -0
  40. package/dist/lib/timeZone.js +44 -0
  41. package/dist/lib/tokenHelpers.js +5 -5
  42. package/dist/lib/utils.js +6 -7
  43. package/dist/types/admin-db.js +1 -1
  44. package/dist/types/analytics.d.ts +20 -0
  45. package/dist/types/analytics.js +4 -0
  46. package/dist/types/api.d.ts +41800 -11853
  47. package/dist/types/api.js +53 -5
  48. package/dist/types/auth.d.ts +20 -6
  49. package/dist/types/capabilities.d.ts +15 -1
  50. package/dist/types/capabilities.js +51 -0
  51. package/dist/types/config.d.ts +99 -0
  52. package/dist/types/config.js +56 -4
  53. package/dist/types/db.d.ts +1155 -164
  54. package/dist/types/db.js +14 -0
  55. package/dist/types/export.d.ts +120 -0
  56. package/dist/types/export.js +7 -0
  57. package/dist/types/index.d.ts +2 -0
  58. package/dist/types/index.js +2 -0
  59. package/dist/types/internal.d.ts +2577 -524
  60. package/dist/types/internal.js +6 -0
  61. package/dist/types/models.d.ts +63 -7
  62. package/dist/types/models.js +40 -3
  63. package/dist/types/plugins.d.ts +22 -0
  64. package/dist/types/plugins.js +66 -0
  65. package/dist/types/roleDefaults.d.ts +31 -0
  66. package/dist/types/roleDefaults.js +110 -0
  67. package/dist/types/stats.d.ts +54606 -6065
  68. package/dist/types/stats.js +30 -0
  69. package/dist/types/utils.d.ts +2 -0
  70. package/dist/types/utils.js +1 -3
  71. package/dist/zod.d.ts +1 -0
  72. package/dist/zod.js +1 -0
  73. package/package.json +36 -6
  74. package/src/index.ts +4 -0
  75. package/src/lib/adminSections.ts +84 -0
  76. package/src/lib/attachmentHelpers.ts +14 -0
  77. package/src/lib/capabilitiesHelpers.ts +532 -0
  78. package/src/lib/colors.ts +20 -0
  79. package/src/lib/csvHelpers.ts +31 -0
  80. package/src/lib/eventIcs.ts +265 -0
  81. package/src/lib/eventRecurrence.ts +495 -0
  82. package/src/lib/eventTime.ts +206 -0
  83. package/src/lib/federationHosts.ts +22 -0
  84. package/src/lib/feedCursor.ts +27 -0
  85. package/src/lib/feedFormat.ts +24 -0
  86. package/src/lib/groupHelpers.ts +421 -0
  87. package/src/lib/groupTemplateHelpers.ts +83 -0
  88. package/src/lib/index.ts +29 -0
  89. package/src/lib/jamHelpers.ts +164 -0
  90. package/src/lib/legacyThemeRoot.ts +14 -0
  91. package/src/lib/markdownHelpers.ts +122 -0
  92. package/src/lib/mediaDimensions.ts +21 -0
  93. package/src/lib/postHelpers.ts +783 -0
  94. package/src/lib/profileHelpers.ts +220 -0
  95. package/src/lib/pushHelpers.ts +34 -0
  96. package/src/lib/reactions.ts +52 -0
  97. package/src/lib/reportHelpers.ts +7 -0
  98. package/src/lib/scopeHelpers.ts +176 -0
  99. package/src/lib/ssoLoginUrl.ts +93 -0
  100. package/src/lib/ssoProviders.ts +472 -0
  101. package/src/lib/text.ts +26 -0
  102. package/src/lib/timeZone.ts +52 -0
  103. package/src/lib/tokenHelpers.ts +119 -0
  104. package/src/lib/utils.ts +322 -0
  105. package/src/types/admin-db.ts +74 -0
  106. package/src/types/admin-email.ts +55 -0
  107. package/src/types/admin-jobs.ts +17 -0
  108. package/src/types/admin-performance.ts +20 -0
  109. package/src/types/analytics.ts +318 -0
  110. package/src/types/api.ts +871 -0
  111. package/src/types/apple-app-site-association.ts +54 -0
  112. package/src/types/auth.ts +22 -0
  113. package/src/types/capabilities.ts +280 -0
  114. package/src/types/config.ts +546 -0
  115. package/src/types/db.ts +138 -0
  116. package/src/types/export.ts +10 -0
  117. package/src/types/index.ts +20 -0
  118. package/src/types/internal.ts +338 -0
  119. package/src/types/models.ts +939 -0
  120. package/src/types/notifications.ts +92 -0
  121. package/src/types/plugins.ts +150 -0
  122. package/src/types/roleDefaults.ts +132 -0
  123. package/src/types/stats.ts +195 -0
  124. package/src/types/stripe.ts +45 -0
  125. package/src/types/utils.ts +100 -0
  126. package/src/zod.ts +1 -0
@@ -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
  });
@@ -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;
@@ -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.1.45",
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
- ".": "./dist/index.js",
20
- "./*": "./dist/*/index.js"
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
- "/dist"
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,4 @@
1
+ export * from './types';
2
+ export * from './lib';
3
+
4
+ export const PLUGIN_ASSETS_PREFIX = '/plugin-assets';
@@ -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
+ }