@openpeepshq/common 0.1.46 → 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 (82) hide show
  1. package/dist/lib/adminSections.js +1 -1
  2. package/dist/lib/capabilitiesHelpers.js +30 -40
  3. package/dist/lib/csvHelpers.js +1 -1
  4. package/dist/lib/eventIcs.js +26 -32
  5. package/dist/lib/eventRecurrence.d.ts +17 -0
  6. package/dist/lib/eventRecurrence.js +75 -18
  7. package/dist/lib/eventTime.js +9 -11
  8. package/dist/lib/groupHelpers.js +13 -34
  9. package/dist/lib/groupTemplateHelpers.js +6 -10
  10. package/dist/lib/jamHelpers.js +6 -9
  11. package/dist/lib/markdownHelpers.js +2 -3
  12. package/dist/lib/postHelpers.js +70 -97
  13. package/dist/lib/profileHelpers.js +17 -24
  14. package/dist/lib/pushHelpers.js +3 -4
  15. package/dist/lib/scopeHelpers.js +6 -9
  16. package/dist/lib/ssoLoginUrl.js +4 -6
  17. package/dist/lib/ssoProviders.js +35 -39
  18. package/dist/lib/tokenHelpers.js +5 -5
  19. package/dist/lib/utils.js +6 -7
  20. package/dist/types/admin-db.js +1 -1
  21. package/dist/types/api.d.ts +1 -0
  22. package/dist/types/api.js +1 -1
  23. package/dist/types/config.d.ts +3 -0
  24. package/dist/types/config.js +3 -0
  25. package/dist/types/models.js +1 -1
  26. package/dist/types/plugins.js +2 -2
  27. package/dist/zod.d.ts +1 -0
  28. package/dist/zod.js +1 -0
  29. package/package.json +36 -6
  30. package/src/index.ts +4 -0
  31. package/src/lib/adminSections.ts +84 -0
  32. package/src/lib/attachmentHelpers.ts +14 -0
  33. package/src/lib/capabilitiesHelpers.ts +532 -0
  34. package/src/lib/colors.ts +20 -0
  35. package/src/lib/csvHelpers.ts +31 -0
  36. package/src/lib/eventIcs.ts +265 -0
  37. package/src/lib/eventRecurrence.ts +495 -0
  38. package/src/lib/eventTime.ts +206 -0
  39. package/src/lib/federationHosts.ts +22 -0
  40. package/src/lib/feedCursor.ts +27 -0
  41. package/src/lib/feedFormat.ts +24 -0
  42. package/src/lib/groupHelpers.ts +421 -0
  43. package/src/lib/groupTemplateHelpers.ts +83 -0
  44. package/src/lib/index.ts +29 -0
  45. package/src/lib/jamHelpers.ts +164 -0
  46. package/src/lib/legacyThemeRoot.ts +14 -0
  47. package/src/lib/markdownHelpers.ts +122 -0
  48. package/src/lib/mediaDimensions.ts +21 -0
  49. package/src/lib/postHelpers.ts +783 -0
  50. package/src/lib/profileHelpers.ts +220 -0
  51. package/src/lib/pushHelpers.ts +34 -0
  52. package/src/lib/reactions.ts +52 -0
  53. package/src/lib/reportHelpers.ts +7 -0
  54. package/src/lib/scopeHelpers.ts +176 -0
  55. package/src/lib/ssoLoginUrl.ts +93 -0
  56. package/src/lib/ssoProviders.ts +472 -0
  57. package/src/lib/text.ts +26 -0
  58. package/src/lib/timeZone.ts +52 -0
  59. package/src/lib/tokenHelpers.ts +119 -0
  60. package/src/lib/utils.ts +322 -0
  61. package/src/types/admin-db.ts +74 -0
  62. package/src/types/admin-email.ts +55 -0
  63. package/src/types/admin-jobs.ts +17 -0
  64. package/src/types/admin-performance.ts +20 -0
  65. package/src/types/analytics.ts +318 -0
  66. package/src/types/api.ts +871 -0
  67. package/src/types/apple-app-site-association.ts +54 -0
  68. package/src/types/auth.ts +22 -0
  69. package/src/types/capabilities.ts +280 -0
  70. package/src/types/config.ts +546 -0
  71. package/src/types/db.ts +138 -0
  72. package/src/types/export.ts +10 -0
  73. package/src/types/index.ts +20 -0
  74. package/src/types/internal.ts +338 -0
  75. package/src/types/models.ts +939 -0
  76. package/src/types/notifications.ts +92 -0
  77. package/src/types/plugins.ts +150 -0
  78. package/src/types/roleDefaults.ts +132 -0
  79. package/src/types/stats.ts +195 -0
  80. package/src/types/stripe.ts +45 -0
  81. package/src/types/utils.ts +100 -0
  82. package/src/zod.ts +1 -0
@@ -51,17 +51,16 @@ export const getPublicPostReadScope = (postId) => ({
51
51
  * that post id (same pattern as {@link withPublicGroupReadScopes}).
52
52
  */
53
53
  export const withPublicPostReadScopes = (authData, post, neededCapabilities) => {
54
- var _a;
55
54
  if (!neededCapabilities.every((c) => c.endsWith('-read'))) {
56
55
  return authData;
57
56
  }
58
57
  const publicGroupPost = post.visibility === 'group' &&
59
- neededCapabilities.every((c) => { var _a, _b, _c, _d, _e; return (_e = (_d = (_c = (_b = (_a = post.group) === null || _a === void 0 ? void 0 : _a.capabilities) === null || _b === void 0 ? void 0 : _b.none) === null || _c === void 0 ? void 0 : _c.add) === null || _d === void 0 ? void 0 : _d.includes(c)) !== null && _e !== void 0 ? _e : false; });
58
+ neededCapabilities.every((c) => post.group?.capabilities?.none?.add?.includes(c) ?? false);
60
59
  if (post.visibility !== 'public' && !publicGroupPost) {
61
60
  return authData;
62
61
  }
63
62
  const publicReadScope = getPublicPostReadScope(post.id);
64
- const scopes = (_a = authData.scopes) !== null && _a !== void 0 ? _a : [];
63
+ const scopes = authData.scopes ?? [];
65
64
  if (scopeMatches({ scopes, requiredScope: publicReadScope })) {
66
65
  return authData;
67
66
  }
@@ -76,16 +75,15 @@ export const getPublicGroupReadScope = (groupId) => ({
76
75
  * without auth (same pattern as {@link withPublicPostReadScopes}).
77
76
  */
78
77
  export const withPublicGroupReadScopes = (authData, group, neededCapabilities) => {
79
- var _a, _b, _c, _d;
80
78
  if (!neededCapabilities.every((c) => c.endsWith('-read'))) {
81
79
  return authData;
82
80
  }
83
- const noneAdd = (_c = (_b = (_a = group.capabilities) === null || _a === void 0 ? void 0 : _a.none) === null || _b === void 0 ? void 0 : _b.add) !== null && _c !== void 0 ? _c : [];
81
+ const noneAdd = group.capabilities?.none?.add ?? [];
84
82
  if (!neededCapabilities.every((c) => noneAdd.includes(c))) {
85
83
  return authData;
86
84
  }
87
85
  const publicReadScope = getPublicGroupReadScope(group.id);
88
- const scopes = (_d = authData.scopes) !== null && _d !== void 0 ? _d : [];
86
+ const scopes = authData.scopes ?? [];
89
87
  if (scopeMatches({ scopes, requiredScope: publicReadScope })) {
90
88
  return authData;
91
89
  }
@@ -102,16 +100,15 @@ export const getPublicProfileReadScope = (profileId) => ({
102
100
  * still enforced by `ensureAccess` on the profile endpoints.
103
101
  */
104
102
  export const withPublicProfileReadScopes = (authData, profile, neededCapabilities, config) => {
105
- var _a, _b, _c, _d;
106
103
  if (!neededCapabilities.every((c) => c.endsWith('-read'))) {
107
104
  return authData;
108
105
  }
109
- const noneAdd = (_c = (_b = (_a = config.profile) === null || _a === void 0 ? void 0 : _a.none) === null || _b === void 0 ? void 0 : _b.add) !== null && _c !== void 0 ? _c : [];
106
+ const noneAdd = config.profile?.none?.add ?? [];
110
107
  if (!neededCapabilities.every((c) => noneAdd.includes(c))) {
111
108
  return authData;
112
109
  }
113
110
  const publicReadScope = getPublicProfileReadScope(profile.id);
114
- const scopes = (_d = authData.scopes) !== null && _d !== void 0 ? _d : [];
111
+ const scopes = authData.scopes ?? [];
115
112
  if (scopeMatches({ scopes, requiredScope: publicReadScope })) {
116
113
  return authData;
117
114
  }
@@ -16,16 +16,15 @@ export const isAllowedSsoLoginUrl = (url) => {
16
16
  };
17
17
  export const oidcAuthorizePath = (id) => `/api/openpeeps/core/v1/sso/oidc/${encodeURIComponent(id)}/authorize`;
18
18
  export const ssoLoginDestinations = (sso) => {
19
- var _a, _b;
20
19
  const destinations = [];
21
- for (const provider of (_a = sso === null || sso === void 0 ? void 0 : sso.generic) !== null && _a !== void 0 ? _a : []) {
20
+ for (const provider of sso?.generic ?? []) {
22
21
  destinations.push({
23
22
  href: provider.loginLink,
24
23
  name: provider.name,
25
24
  testId: `auth-login-generic-${provider.id}`,
26
25
  });
27
26
  }
28
- for (const provider of (_b = sso === null || sso === void 0 ? void 0 : sso.oidc) !== null && _b !== void 0 ? _b : []) {
27
+ for (const provider of sso?.oidc ?? []) {
29
28
  destinations.push({
30
29
  href: oidcAuthorizePath(provider.id),
31
30
  name: provider.name,
@@ -35,7 +34,7 @@ export const ssoLoginDestinations = (sso) => {
35
34
  return destinations;
36
35
  };
37
36
  export const resolveOnlySsoView = (sso, searchParams) => {
38
- if (!(sso === null || sso === void 0 ? void 0 : sso.onlySSO) || searchParams.has(LOCAL_LOGIN_PARAM)) {
37
+ if (!sso?.onlySSO || searchParams.has(LOCAL_LOGIN_PARAM)) {
39
38
  return { mode: 'form' };
40
39
  }
41
40
  const destinations = ssoLoginDestinations(sso);
@@ -51,8 +50,7 @@ export const publicSsoInfo = (sso) => {
51
50
  name: provider.name,
52
51
  }));
53
52
  const generic = sso.generic.flatMap((provider) => {
54
- var _a;
55
- const loginLink = (_a = provider.loginLink) === null || _a === void 0 ? void 0 : _a.trim();
53
+ const loginLink = provider.loginLink?.trim();
56
54
  if (!loginLink || !isAllowedSsoLoginUrl(loginLink))
57
55
  return [];
58
56
  return [
@@ -137,9 +137,8 @@ export const gitlabOidcEndpoints = (instanceUrl) => {
137
137
  };
138
138
  };
139
139
  export const oidcEndpoints = (kind, fields = {}) => {
140
- var _a;
141
140
  const instance = withHttps(fields.instanceUrl || '');
142
- const tenant = (_a = fields.tenant) === null || _a === void 0 ? void 0 : _a.trim();
141
+ const tenant = fields.tenant?.trim();
143
142
  switch (kind) {
144
143
  case 'github':
145
144
  return githubOidcEndpoints(fields.instanceUrl);
@@ -230,19 +229,18 @@ export const oidcEndpoints = (kind, fields = {}) => {
230
229
  }
231
230
  };
232
231
  export const applyOidcProvider = (kind, fields) => {
233
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
234
232
  const tpl = oidcEndpoints(kind, fields);
235
233
  if (tpl) {
236
234
  return {
237
235
  kind,
238
236
  id: fields.id.trim(),
239
237
  name: fields.name.trim(),
240
- instanceUrl: ((_a = fields.instanceUrl) === null || _a === void 0 ? void 0 : _a.trim()) || undefined,
241
- tenant: ((_b = fields.tenant) === null || _b === void 0 ? void 0 : _b.trim()) || undefined,
238
+ instanceUrl: fields.instanceUrl?.trim() || undefined,
239
+ tenant: fields.tenant?.trim() || undefined,
242
240
  clientId: fields.clientId.trim(),
243
241
  clientSecret: fields.clientSecret,
244
242
  approvalRequired: fields.approvalRequired,
245
- scope: ((_c = fields.scope) === null || _c === void 0 ? void 0 : _c.trim()) || tpl.scope,
243
+ scope: fields.scope?.trim() || tpl.scope,
246
244
  authorizationUrl: tpl.authorizationUrl,
247
245
  tokenUrl: tpl.tokenUrl,
248
246
  userinfoUrl: tpl.userinfoUrl,
@@ -258,40 +256,37 @@ export const applyOidcProvider = (kind, fields) => {
258
256
  clientId: fields.clientId.trim(),
259
257
  clientSecret: fields.clientSecret,
260
258
  approvalRequired: fields.approvalRequired,
261
- scope: ((_d = fields.scope) === null || _d === void 0 ? void 0 : _d.trim()) || 'openid email profile',
262
- authorizationUrl: ((_e = fields.authorizationUrl) === null || _e === void 0 ? void 0 : _e.trim()) || '',
263
- tokenUrl: ((_f = fields.tokenUrl) === null || _f === void 0 ? void 0 : _f.trim()) || '',
264
- userinfoUrl: ((_g = fields.userinfoUrl) === null || _g === void 0 ? void 0 : _g.trim()) || '',
265
- emailsUrl: ((_h = fields.emailsUrl) === null || _h === void 0 ? void 0 : _h.trim()) || undefined,
266
- jwksUri: ((_j = fields.jwksUri) === null || _j === void 0 ? void 0 : _j.trim()) || undefined,
259
+ scope: fields.scope?.trim() || 'openid email profile',
260
+ authorizationUrl: fields.authorizationUrl?.trim() || '',
261
+ tokenUrl: fields.tokenUrl?.trim() || '',
262
+ userinfoUrl: fields.userinfoUrl?.trim() || '',
263
+ emailsUrl: fields.emailsUrl?.trim() || undefined,
264
+ jwksUri: fields.jwksUri?.trim() || undefined,
267
265
  claimMapping: {
268
- email: ((_k = fields.claimMapping) === null || _k === void 0 ? void 0 : _k.email) || 'email',
269
- handle: ((_l = fields.claimMapping) === null || _l === void 0 ? void 0 : _l.handle) || 'preferred_username',
270
- displayName: ((_m = fields.claimMapping) === null || _m === void 0 ? void 0 : _m.displayName) || 'name',
271
- avatar: ((_o = fields.claimMapping) === null || _o === void 0 ? void 0 : _o.avatar) || 'picture',
266
+ email: fields.claimMapping?.email || 'email',
267
+ handle: fields.claimMapping?.handle || 'preferred_username',
268
+ displayName: fields.claimMapping?.displayName || 'name',
269
+ avatar: fields.claimMapping?.avatar || 'picture',
272
270
  },
273
271
  };
274
272
  };
275
- export const applyGenericProvider = (fields) => {
276
- var _a, _b, _c, _d, _e;
277
- return ({
278
- id: fields.id.trim(),
279
- name: fields.name.trim(),
280
- loginLink: ((_a = fields.loginLink) === null || _a === void 0 ? void 0 : _a.trim()) || undefined,
281
- userProfileRequest: {
282
- url: fields.profileUrl.trim(),
283
- authHeader: ((_b = fields.authHeader) === null || _b === void 0 ? void 0 : _b.trim()) || undefined,
284
- },
285
- userProfilePaths: {
286
- email: fields.emailPath.trim(),
287
- handle: ((_c = fields.handlePath) === null || _c === void 0 ? void 0 : _c.trim()) || undefined,
288
- displayName: ((_d = fields.displayNamePath) === null || _d === void 0 ? void 0 : _d.trim()) || undefined,
289
- avatar: ((_e = fields.avatarPath) === null || _e === void 0 ? void 0 : _e.trim()) || undefined,
290
- },
291
- createAccounts: fields.createAccounts,
292
- createProfiles: fields.createProfiles,
293
- });
294
- };
273
+ export const applyGenericProvider = (fields) => ({
274
+ id: fields.id.trim(),
275
+ name: fields.name.trim(),
276
+ loginLink: fields.loginLink?.trim() || undefined,
277
+ userProfileRequest: {
278
+ url: fields.profileUrl.trim(),
279
+ authHeader: fields.authHeader?.trim() || undefined,
280
+ },
281
+ userProfilePaths: {
282
+ email: fields.emailPath.trim(),
283
+ handle: fields.handlePath?.trim() || undefined,
284
+ displayName: fields.displayNamePath?.trim() || undefined,
285
+ avatar: fields.avatarPath?.trim() || undefined,
286
+ },
287
+ createAccounts: fields.createAccounts,
288
+ createProfiles: fields.createProfiles,
289
+ });
295
290
  export const githubEmailsUrl = (provider) => provider.emailsUrl ||
296
291
  (ssoOidcKind(provider) === 'github'
297
292
  ? githubOidcEndpoints(provider.instanceUrl).emailsUrl
@@ -312,7 +307,6 @@ export const discordAvatarUrl = (claims) => {
312
307
  return `https://cdn.discordapp.com/embed/avatars/${Number.isFinite(index) ? index : 0}.png`;
313
308
  };
314
309
  export const pickOAuthEmail = (emails) => {
315
- var _a, _b, _c, _d, _e;
316
310
  if (!Array.isArray(emails))
317
311
  return undefined;
318
312
  const rows = emails.flatMap((entry) => {
@@ -329,11 +323,13 @@ export const pickOAuthEmail = (emails) => {
329
323
  },
330
324
  ];
331
325
  });
332
- return ((_d = (_b = (_a = rows.find((row) => row.primary && row.verified)) === null || _a === void 0 ? void 0 : _a.email) !== null && _b !== void 0 ? _b : (_c = rows.find((row) => row.verified)) === null || _c === void 0 ? void 0 : _c.email) !== null && _d !== void 0 ? _d : (_e = rows[0]) === null || _e === void 0 ? void 0 : _e.email);
326
+ return (rows.find((row) => row.primary && row.verified)?.email ??
327
+ rows.find((row) => row.verified)?.email ??
328
+ rows[0]?.email);
333
329
  };
334
330
  export const parseOAuthTokenBody = (body, contentType) => {
335
331
  const trimmed = body.trim();
336
- const type = contentType !== null && contentType !== void 0 ? contentType : '';
332
+ const type = contentType ?? '';
337
333
  if (type.includes('application/json') || trimmed.startsWith('{')) {
338
334
  return JSON.parse(trimmed);
339
335
  }
@@ -6,7 +6,7 @@ export const decodeJwtPayloadUnverified = (token) => decodeJwt(token);
6
6
  * Session and access tokens embed that shape in the claim set.
7
7
  */
8
8
  export const parseScopesFromJwt = (token) => {
9
- if (!(token === null || token === void 0 ? void 0 : token.trim())) {
9
+ if (!token?.trim()) {
10
10
  return [];
11
11
  }
12
12
  try {
@@ -22,7 +22,7 @@ export const parseScopesFromJwt = (token) => {
22
22
  * (e.g. jam observer / egress links). These cannot load `profiles/current`.
23
23
  */
24
24
  export const isServiceOnlyJwt = (token) => {
25
- if (!(token === null || token === void 0 ? void 0 : token.trim())) {
25
+ if (!token?.trim()) {
26
26
  return false;
27
27
  }
28
28
  try {
@@ -41,7 +41,7 @@ export const isServiceOnlyJwt = (token) => {
41
41
  * These must not use the login JWT refresh path or `/accounts/current`.
42
42
  */
43
43
  export const isAccountlessJwt = (token) => {
44
- if (!(token === null || token === void 0 ? void 0 : token.trim())) {
44
+ if (!token?.trim()) {
45
45
  return false;
46
46
  }
47
47
  try {
@@ -63,7 +63,7 @@ export const isAccountlessJwt = (token) => {
63
63
  export const jwtHasRemainingValidityAtLeast = (token, minRemainingSeconds) => {
64
64
  if (!Number.isFinite(minRemainingSeconds) ||
65
65
  minRemainingSeconds < 0 ||
66
- !(token === null || token === void 0 ? void 0 : token.trim())) {
66
+ !token?.trim()) {
67
67
  return false;
68
68
  }
69
69
  try {
@@ -87,7 +87,7 @@ export const verifyJwt = async (token, publicKey) => {
87
87
  const verification = await jwtVerify(token, jwkPublicKey, {
88
88
  algorithms: ['EdDSA'],
89
89
  }).catch(() => undefined);
90
- return verification === null || verification === void 0 ? void 0 : verification.payload;
90
+ return verification?.payload;
91
91
  };
92
92
  export const parseJwtKeyId = (token) => {
93
93
  try {
package/dist/lib/utils.js CHANGED
@@ -114,10 +114,10 @@ const getMode = (config, profileSettings, systemTheme) => {
114
114
  if (profileSettings.theme === "system") {
115
115
  return systemTheme;
116
116
  }
117
- else if ((profileSettings === null || profileSettings === void 0 ? void 0 : profileSettings.theme) === "dark") {
117
+ else if (profileSettings?.theme === "dark") {
118
118
  return "dark";
119
119
  }
120
- else if ((profileSettings === null || profileSettings === void 0 ? void 0 : profileSettings.theme) === "light") {
120
+ else if (profileSettings?.theme === "light") {
121
121
  return "light";
122
122
  }
123
123
  }
@@ -134,12 +134,12 @@ export const getSystemTheme = () => {
134
134
  return 'light';
135
135
  };
136
136
  export const getProfileAvatar = (profile, config) => {
137
- return (profile === null || profile === void 0 ? void 0 : profile.avatar)
137
+ return profile?.avatar
138
138
  ? profile.avatar
139
139
  : getTheme(config).defaultProfileAvatar;
140
140
  };
141
141
  export const getGroupAvatar = (group, config) => {
142
- return (group === null || group === void 0 ? void 0 : group.avatar)
142
+ return group?.avatar
143
143
  ? group.avatar
144
144
  : getTheme(config).defaultGroupAvatar;
145
145
  };
@@ -177,15 +177,14 @@ export const formatSize = (bytes) => {
177
177
  return (bytes / (1024 * 1024)).toFixed(1) + ' MB';
178
178
  };
179
179
  export const hasVisibilityChanged = (previousAudienceSetting, newAudienceSetting) => {
180
- var _a, _b;
181
180
  if (previousAudienceSetting.visibility !== newAudienceSetting.visibility) {
182
181
  return true;
183
182
  }
184
183
  if (previousAudienceSetting.groupId !== newAudienceSetting.groupId) {
185
184
  return true;
186
185
  }
187
- const prevAudience = (_a = previousAudienceSetting.audience) !== null && _a !== void 0 ? _a : [];
188
- const newAudience = (_b = newAudienceSetting.audience) !== null && _b !== void 0 ? _b : [];
186
+ const prevAudience = previousAudienceSetting.audience ?? [];
187
+ const newAudience = newAudienceSetting.audience ?? [];
189
188
  if (prevAudience.length !== newAudience.length) {
190
189
  return true;
191
190
  }
@@ -31,7 +31,7 @@ export const explorerUpdateRowResponseSchema = z.object({
31
31
  export const explorerSqlInputSchema = z.object({
32
32
  statement: z.string().min(1),
33
33
  /** Max rows to return (capped server-side). Omit for the default cap. */
34
- limit: z.number().int().positive().max(10000).optional(),
34
+ limit: z.number().int().positive().max(10_000).optional(),
35
35
  });
36
36
  export const explorerSqlResponseSchema = z.object({
37
37
  columns: z.array(z.string()),
@@ -35065,6 +35065,7 @@ export declare const serverInfoSchema: z.ZodObject<{
35065
35065
  threaded: "threaded";
35066
35066
  linear: "linear";
35067
35067
  }>>;
35068
+ indexProfiles: z.ZodOptional<z.ZodBoolean>;
35068
35069
  }, z.core.$strip>;
35069
35070
  roles: z.ZodObject<{
35070
35071
  onRegistration: z.ZodObject<{
package/dist/types/api.js CHANGED
@@ -42,7 +42,7 @@ export const publicProfileSchema = z.object({
42
42
  group: groupSchema,
43
43
  }))
44
44
  .optional()
45
- .transform((memberships) => memberships === null || memberships === void 0 ? void 0 : memberships.filter((m) => { var _a, _b, _c; return (_c = (_b = (_a = m.group.capabilities) === null || _a === void 0 ? void 0 : _a.none) === null || _b === void 0 ? void 0 : _b.add) === null || _c === void 0 ? void 0 : _c.includes('core-groups-read'); })),
45
+ .transform((memberships) => memberships?.filter((m) => m.group.capabilities?.none?.add?.includes('core-groups-read'))),
46
46
  fields: z
47
47
  .array(z.object({
48
48
  name: z.string().max(255).min(1),
@@ -691,6 +691,7 @@ export declare const communityConfigSchemaFactory: (_sanitize?: boolean) => z.Zo
691
691
  threaded: "threaded";
692
692
  linear: "linear";
693
693
  }>>;
694
+ indexProfiles: z.ZodOptional<z.ZodBoolean>;
694
695
  }, z.core.$strip>;
695
696
  roles: z.ZodObject<{
696
697
  onRegistration: z.ZodObject<{
@@ -770,6 +771,7 @@ export declare const communityConfigSchema: z.ZodObject<{
770
771
  threaded: "threaded";
771
772
  linear: "linear";
772
773
  }>>;
774
+ indexProfiles: z.ZodOptional<z.ZodBoolean>;
773
775
  }, z.core.$strip>;
774
776
  roles: z.ZodObject<{
775
777
  onRegistration: z.ZodObject<{
@@ -849,6 +851,7 @@ export declare const communityConfigSanitizedSchema: z.ZodObject<{
849
851
  threaded: "threaded";
850
852
  linear: "linear";
851
853
  }>>;
854
+ indexProfiles: z.ZodOptional<z.ZodBoolean>;
852
855
  }, z.core.$strip>;
853
856
  roles: z.ZodObject<{
854
857
  onRegistration: z.ZodObject<{
@@ -332,6 +332,9 @@ export const communityConfigSchemaFactory = (_sanitize) => z.object({
332
332
  defaultLanguage: z.string().optional(),
333
333
  defaultTimeZone: z.string().optional(),
334
334
  defaultFeedFormat: z.enum(['threaded', 'linear']).optional(),
335
+ /** Adds member profile pages to the sitemap. Off by default: a crawled
336
+ * profile is cached by search engines long after the member leaves. */
337
+ indexProfiles: z.boolean().optional(),
335
338
  }),
336
339
  roles: z.object({
337
340
  onRegistration: z.object({
@@ -145,7 +145,7 @@ export const accountNameSchema = z
145
145
  .refine((value) => !forbiddenHandles.includes(value.toLowerCase()), {
146
146
  message: 'Handle is reserved',
147
147
  })
148
- .refine((value) => handleRegex.test(value !== null && value !== void 0 ? value : ''), {
148
+ .refine((value) => handleRegex.test(value ?? ''), {
149
149
  message: 'Handle must be 1–16 characters: letters, numbers, underscores, or hyphens (no spaces or punctuation)',
150
150
  })
151
151
  .openapi({
@@ -66,14 +66,14 @@ export const pluginInstallSourceSchema = z.discriminatedUnion('type', [
66
66
  path: ['url'],
67
67
  });
68
68
  }
69
- if ((auth === null || auth === void 0 ? void 0 : auth.type) === 'token' && parsedUrl.protocol !== 'https:') {
69
+ if (auth?.type === 'token' && parsedUrl.protocol !== 'https:') {
70
70
  context.addIssue({
71
71
  code: 'custom',
72
72
  message: 'Token authentication requires an HTTPS repository URL',
73
73
  path: ['url'],
74
74
  });
75
75
  }
76
- if ((auth === null || auth === void 0 ? void 0 : auth.type) === 'ssh' && parsedUrl.protocol !== 'ssh:') {
76
+ if (auth?.type === 'ssh' && parsedUrl.protocol !== 'ssh:') {
77
77
  context.addIssue({
78
78
  code: 'custom',
79
79
  message: 'SSH authentication requires an ssh:// repository URL',
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.46",
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
+ }