@openpeepshq/core 0.1.32 → 0.1.34

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 (261) hide show
  1. package/dist/accessTokens/helpers.d.ts +2 -2
  2. package/dist/accessTokens/tokens.js +14 -7
  3. package/dist/accounts/mutations.d.ts +2 -2
  4. package/dist/accounts/mutations.js +33 -35
  5. package/dist/analytics/cache.js +12 -7
  6. package/dist/analytics/compile.js +16 -10
  7. package/dist/analytics/pdfReport.d.ts +1 -0
  8. package/dist/analytics/pdfReport.js +5 -4
  9. package/dist/analytics/privacy.d.ts +18 -0
  10. package/dist/analytics/privacy.js +10 -0
  11. package/dist/analytics/read.js +75 -19
  12. package/dist/analytics/report.d.ts +21 -1
  13. package/dist/analytics/report.js +9 -2
  14. package/dist/backups/index.js +78 -15
  15. package/dist/backups/metadata.d.ts +8 -2
  16. package/dist/backups/metadata.js +6 -2
  17. package/dist/config/defaults/capabilities.js +13 -2
  18. package/dist/config/defaults/community.js +7 -9
  19. package/dist/config/defaults/core.d.ts +1 -1
  20. package/dist/config/defaults/core.js +3 -0
  21. package/dist/config/defaults/db.d.ts +0 -2
  22. package/dist/config/defaults/db.js +0 -2
  23. package/dist/config/index.d.ts +25 -3
  24. package/dist/config/index.js +7 -1
  25. package/dist/db/helpers.d.ts +7 -28
  26. package/dist/db/helpers.js +30 -152
  27. package/dist/db/index.d.ts +3 -1
  28. package/dist/db/index.js +5 -0
  29. package/dist/db/init.js +2 -2
  30. package/dist/db/migration/importCollections.d.ts +15 -10
  31. package/dist/db/migration/importCollections.js +121 -155
  32. package/dist/db/migration/shared.d.ts +2 -37
  33. package/dist/db/migration/shared.js +2 -59
  34. package/dist/db/pg/client.js +4 -0
  35. package/dist/db/pg/collections.d.ts +2 -2
  36. package/dist/db/pg/collections.js +2 -2
  37. package/dist/db/pg/filters/edges.d.ts +1 -1
  38. package/dist/db/pg/filters/edges.js +1 -1
  39. package/dist/db/pg/filters/posts.d.ts +11 -0
  40. package/dist/db/pg/filters/posts.js +37 -3
  41. package/dist/db/pg/filters/profiles.d.ts +1 -0
  42. package/dist/db/pg/filters/profiles.js +2 -1
  43. package/dist/db/pg/map/filters.js +37 -2
  44. package/dist/db/pg/map/mutations.js +13 -8
  45. package/dist/db/pg/map/registry.d.ts +5 -0
  46. package/dist/db/pg/map/registry.js +64 -24
  47. package/dist/db/pg/map/relations.d.ts +1 -1
  48. package/dist/db/pg/map/relations.js +98 -46
  49. package/dist/db/pg/migrate.d.ts +22 -0
  50. package/dist/db/pg/migrate.js +88 -2
  51. package/dist/db/pg/queries/activity.js +3 -3
  52. package/dist/db/pg/queries/sorts.d.ts +1 -0
  53. package/dist/db/pg/queries/sorts.js +4 -0
  54. package/dist/db/pg/schema/documents.d.ts +422 -41
  55. package/dist/db/pg/schema/documents.js +43 -9
  56. package/dist/db/pg/schema/edges.d.ts +117 -7
  57. package/dist/db/pg/schema/edges.js +4 -2
  58. package/dist/db/pg/schema/index.d.ts +505 -15
  59. package/dist/db/pg/sql/0007_shallow_oracle.sql +3 -0
  60. package/dist/db/pg/sql/0008_group_owner_roles.sql +31 -0
  61. package/dist/db/pg/sql/0009_event_occurrences.sql +26 -0
  62. package/dist/db/pg/sql/0010_user_group_membership_roles.sql +16 -0
  63. package/dist/db/pg/sql/0011_drop_data_migrations.sql +1 -0
  64. package/dist/db/pg/sql/0012_posts_last_activity_at.sql +5 -0
  65. package/dist/db/pg/sql/0013_add_blocks_edge.sql +12 -0
  66. package/dist/db/pg/sql/0014_federation_datamodel.sql +59 -0
  67. package/dist/db/pg/sql/0015_profile_hashtags.sql +12 -0
  68. package/dist/db/pg/sql/meta/{0006_snapshot.json → 0015_snapshot.json} +393 -39
  69. package/dist/db/pg/sql/meta/_journal.json +64 -1
  70. package/dist/db/replaceOrigin.js +6 -0
  71. package/dist/db/types.d.ts +0 -4
  72. package/dist/email/render.js +11 -3
  73. package/dist/events/index.d.ts +6 -1
  74. package/dist/events/index.js +55 -33
  75. package/dist/federation/activities.d.ts +17 -0
  76. package/dist/federation/activities.js +26 -0
  77. package/dist/federation/identity.d.ts +16 -0
  78. package/dist/federation/identity.js +52 -0
  79. package/dist/federation/index.d.ts +4 -0
  80. package/dist/federation/index.js +3 -0
  81. package/dist/federation/profiles.d.ts +3 -0
  82. package/dist/federation/profiles.js +14 -0
  83. package/dist/groups/finders.d.ts +3 -2
  84. package/dist/groups/helpers.d.ts +24 -6
  85. package/dist/groups/mapping.d.ts +6 -4
  86. package/dist/groups/mapping.js +2 -2
  87. package/dist/groups/mutations.js +1 -1
  88. package/dist/hashtags/finders.d.ts +6 -3
  89. package/dist/hashtags/finders.js +2 -0
  90. package/dist/hashtags/helpers.d.ts +8 -0
  91. package/dist/hashtags/helpers.js +4 -0
  92. package/dist/hashtags/index.d.ts +2 -0
  93. package/dist/hashtags/index.js +2 -0
  94. package/dist/hashtags/mutations.d.ts +3 -0
  95. package/dist/hashtags/mutations.js +13 -1
  96. package/dist/i18n/index.d.ts +1 -1
  97. package/dist/i18n/index.js +3 -1
  98. package/dist/i18n/pluginLocales.d.ts +6 -0
  99. package/dist/i18n/pluginLocales.js +15 -0
  100. package/dist/inviteLinks/helpers.d.ts +4 -4
  101. package/dist/jams/cache.d.ts +1 -1
  102. package/dist/jams/cache.js +2 -1
  103. package/dist/jams/export.d.ts +19 -0
  104. package/dist/jams/export.js +60 -0
  105. package/dist/jams/finders.d.ts +2 -1
  106. package/dist/jams/finders.js +18 -7
  107. package/dist/jams/health.d.ts +8 -0
  108. package/dist/jams/health.js +46 -0
  109. package/dist/jams/helpers.d.ts +6 -2
  110. package/dist/jams/index.d.ts +6 -3
  111. package/dist/jams/index.js +41 -27
  112. package/dist/jams/jobs.js +1 -1
  113. package/dist/jams/livekit.d.ts +93 -10
  114. package/dist/jams/livekit.js +151 -52
  115. package/dist/jams/mapping.d.ts +17 -7
  116. package/dist/jams/mutations.d.ts +3 -1
  117. package/dist/jams/recording.d.ts +10 -0
  118. package/dist/jams/recording.js +32 -0
  119. package/dist/jams/rtmp.d.ts +5 -0
  120. package/dist/jams/rtmp.js +8 -0
  121. package/dist/jams/token.d.ts +15 -3
  122. package/dist/jams/token.js +30 -16
  123. package/dist/jams/waitingRoom.d.ts +6 -6
  124. package/dist/jams/waitingRoom.js +24 -23
  125. package/dist/jobs/index.d.ts +1 -0
  126. package/dist/jobs/index.js +6 -1
  127. package/dist/jobs/jobDetail.js +1 -6
  128. package/dist/media/index.d.ts +1 -1
  129. package/dist/media/index.js +23 -8
  130. package/dist/media/processing.js +18 -7
  131. package/dist/notifications/defaultNotifications/follow/index.js +2 -2
  132. package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +3 -1
  133. package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +3 -1
  134. package/dist/notifications/defaultNotifications/index.js +4 -0
  135. package/dist/notifications/defaultNotifications/newGroupPost/index.js +12 -6
  136. package/dist/notifications/defaultNotifications/pollEnded/index.d.ts +19 -0
  137. package/dist/notifications/defaultNotifications/pollEnded/index.js +39 -0
  138. package/dist/notifications/defaultNotifications/pollEnded/recipients.d.ts +3 -0
  139. package/dist/notifications/defaultNotifications/pollEnded/recipients.js +18 -0
  140. package/dist/notifications/defaultNotifications/rsvp/index.d.ts +6 -1
  141. package/dist/notifications/defaultNotifications/rsvp/index.js +7 -0
  142. package/dist/notifications/defaultNotifications/rsvpCanceled/index.d.ts +24 -0
  143. package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +75 -0
  144. package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.d.ts +4 -0
  145. package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.js +11 -0
  146. package/dist/notifications/helpers.js +6 -2
  147. package/dist/notifications/jobs.js +3 -1
  148. package/dist/notifications/mutations.js +4 -0
  149. package/dist/notifications/push.js +11 -4
  150. package/dist/plugins/helpers.d.ts +1 -0
  151. package/dist/plugins/helpers.js +1 -8
  152. package/dist/plugins/index.d.ts +5 -0
  153. package/dist/plugins/index.js +78 -5
  154. package/dist/plugins/install.d.ts +39 -0
  155. package/dist/plugins/install.js +455 -0
  156. package/dist/plugins/pluginAuth.d.ts +1 -1
  157. package/dist/plugins/pluginAuth.js +10 -6
  158. package/dist/plugins/state.d.ts +4 -0
  159. package/dist/plugins/state.js +29 -0
  160. package/dist/posts/activity.d.ts +9 -0
  161. package/dist/posts/activity.js +35 -0
  162. package/dist/posts/contextClosure.d.ts +1 -9
  163. package/dist/posts/contextClosure.js +15 -44
  164. package/dist/posts/conversationQueries.d.ts +7 -0
  165. package/dist/posts/conversationQueries.js +76 -2
  166. package/dist/posts/eventAgenda.d.ts +166 -0
  167. package/dist/posts/eventAgenda.js +126 -0
  168. package/dist/posts/eventOccurrenceJobs.d.ts +4 -0
  169. package/dist/posts/eventOccurrenceJobs.js +28 -0
  170. package/dist/posts/eventOccurrences.d.ts +10 -0
  171. package/dist/posts/eventOccurrences.js +61 -0
  172. package/dist/posts/finders.d.ts +47 -16
  173. package/dist/posts/finders.js +93 -62
  174. package/dist/posts/helpers/filters.js +14 -9
  175. package/dist/posts/helpers/index.d.ts +129 -30
  176. package/dist/posts/helpers/index.js +66 -33
  177. package/dist/posts/index.d.ts +7 -1
  178. package/dist/posts/index.js +7 -1
  179. package/dist/posts/mapping.d.ts +491 -13
  180. package/dist/posts/mapping.js +45 -10
  181. package/dist/posts/mutations.d.ts +441 -4
  182. package/dist/posts/mutations.js +177 -43
  183. package/dist/posts/pollEnd.d.ts +3 -0
  184. package/dist/posts/pollEnd.js +7 -0
  185. package/dist/posts/pollEndJobs.d.ts +8 -0
  186. package/dist/posts/pollEndJobs.js +49 -0
  187. package/dist/posts/replyClosure.d.ts +10 -0
  188. package/dist/posts/replyClosure.js +43 -0
  189. package/dist/posts/rsvpConfirmationEmail.js +14 -15
  190. package/dist/posts/threadPreview.d.ts +8 -0
  191. package/dist/posts/threadPreview.js +44 -0
  192. package/dist/posts/unseenCounts.d.ts +2 -0
  193. package/dist/posts/unseenCounts.js +28 -8
  194. package/dist/profileSettings/cache.js +22 -5
  195. package/dist/profileSettings/mapping.d.ts +2 -0
  196. package/dist/profiles/activityQueries.d.ts +5 -0
  197. package/dist/profiles/activityQueries.js +85 -0
  198. package/dist/profiles/activitySummary.d.ts +3 -0
  199. package/dist/profiles/activitySummary.js +87 -0
  200. package/dist/profiles/blocks.d.ts +12 -0
  201. package/dist/profiles/blocks.js +73 -0
  202. package/dist/profiles/cache.d.ts +4 -1
  203. package/dist/profiles/cache.js +28 -7
  204. package/dist/profiles/finders.d.ts +2 -1
  205. package/dist/profiles/finders.js +8 -3
  206. package/dist/profiles/helpers.d.ts +7 -5
  207. package/dist/profiles/index.d.ts +3 -1
  208. package/dist/profiles/index.js +3 -1
  209. package/dist/profiles/mapping.d.ts +10 -5
  210. package/dist/profiles/mapping.js +13 -1
  211. package/dist/profiles/mutations.d.ts +8 -4
  212. package/dist/profiles/mutations.js +42 -15
  213. package/dist/pushSubscriptions/helpers.d.ts +2 -2
  214. package/dist/pushSubscriptions/mutations.js +13 -1
  215. package/dist/redis/connection.d.ts +2 -0
  216. package/dist/redis/connection.js +25 -6
  217. package/dist/reports/helpers.d.ts +6 -6
  218. package/dist/roles/index.d.ts +1 -1
  219. package/dist/roles/index.js +1 -1
  220. package/dist/roles/mapping.d.ts +1 -0
  221. package/dist/roles/mutations.js +86 -3
  222. package/dist/search/mapping.d.ts +1 -1
  223. package/dist/search/mapping.js +6 -2
  224. package/dist/server/index.d.ts +19 -1
  225. package/dist/server/index.js +37 -18
  226. package/dist/server/stablePublicServerInfo.d.ts +17 -0
  227. package/dist/server/stablePublicServerInfo.js +37 -0
  228. package/dist/server/status.d.ts +25 -0
  229. package/dist/server/status.js +98 -0
  230. package/dist/stats/finders.d.ts +1 -16131
  231. package/dist/stats/finders.js +9 -5
  232. package/dist/stats/mapping.d.ts +21 -1
  233. package/dist/stats/mapping.js +0 -3
  234. package/package.json +6 -12
  235. package/dist/db/arango.d.ts +0 -2
  236. package/dist/db/arango.js +0 -110
  237. package/dist/db/migration/autoMigrate.d.ts +0 -2
  238. package/dist/db/migration/autoMigrate.js +0 -111
  239. package/dist/db/migration/cli.d.ts +0 -1
  240. package/dist/db/migration/cli.js +0 -56
  241. package/dist/db/migration/detect.d.ts +0 -6
  242. package/dist/db/migration/detect.js +0 -87
  243. package/dist/db/migration/exportArango.d.ts +0 -4
  244. package/dist/db/migration/exportArango.js +0 -80
  245. package/dist/db/migration/importPostgres.d.ts +0 -3
  246. package/dist/db/migration/importPostgres.js +0 -18
  247. package/dist/db/migration/transform.d.ts +0 -18
  248. package/dist/db/migration/transform.js +0 -209
  249. package/dist/db/migration/validate.d.ts +0 -18
  250. package/dist/db/migration/validate.js +0 -69
  251. package/dist/db/pg/sql/meta/0000_snapshot.json +0 -3380
  252. package/dist/db/pg/sql/meta/0004_snapshot.json +0 -4114
  253. package/dist/db/pg/sql/meta/0005_snapshot.json +0 -4179
  254. package/dist/mastodon/index.d.ts +0 -4
  255. package/dist/mastodon/index.js +0 -51
  256. package/dist/mastodon/types.d.ts +0 -7579
  257. package/dist/mastodon/types.js +0 -523
  258. package/dist/mastodon/typescript.d.ts +0 -1578
  259. package/dist/mastodon/typescript.js +0 -1
  260. package/dist/roles/defaults.d.ts +0 -2
  261. package/dist/roles/defaults.js +0 -94
@@ -1,3 +1,4 @@
1
+ import { getUniqueBy, pushSubscriptionDeliveryKey, } from '@openpeepshq/common/lib';
1
2
  import { communityConfig, config } from '../config/index.js';
2
3
  import webPush from 'web-push';
3
4
  import { logger } from '../log/index.js';
@@ -178,10 +179,16 @@ export const doPush = async (notification, notificationStats, account, jobLog) =
178
179
  notificationStats,
179
180
  };
180
181
  const subscriptions = await listPushSubscriptionsByAccount(account);
181
- const webSubscriptions = subscriptions.filter((sub) => sub.type === 'web');
182
- const webhookSubscriptions = subscriptions.filter((sub) => sub.type === 'webhook');
183
- const apnSubscriptions = subscriptions.filter((sub) => sub.type === 'apn');
184
- const fcmSubscriptions = subscriptions.filter((sub) => sub.type === 'fcm');
182
+ const uniqueSubscriptions = getUniqueBy(subscriptions, pushSubscriptionDeliveryKey);
183
+ const duplicateSubscriptions = subscriptions.filter((subscription) => !uniqueSubscriptions.some((unique) => unique.id === subscription.id));
184
+ if (duplicateSubscriptions.length > 0) {
185
+ await logStep(jobLog, log, `Removing ${duplicateSubscriptions.length} duplicate push subscription(s) for account ${account.id}`);
186
+ await Promise.all(duplicateSubscriptions.map((subscription) => deletePushSubscription(subscription.id).catch((error) => logFailure(jobLog, log, `failed to remove duplicate subscription ${subscription.id}`, error))));
187
+ }
188
+ const webSubscriptions = uniqueSubscriptions.filter((sub) => sub.type === 'web');
189
+ const webhookSubscriptions = uniqueSubscriptions.filter((sub) => sub.type === 'webhook');
190
+ const apnSubscriptions = uniqueSubscriptions.filter((sub) => sub.type === 'apn');
191
+ const fcmSubscriptions = uniqueSubscriptions.filter((sub) => sub.type === 'fcm');
185
192
  await logStep(jobLog, log, `Delivering push "${notification.title}" to account ${account.id} (${account.email}); ` +
186
193
  `subscriptions: web=${webSubscriptions.length} webhook=${webhookSubscriptions.length} ` +
187
194
  `apn=${apnSubscriptions.length} fcm=${fcmSubscriptions.length}`);
@@ -1,4 +1,5 @@
1
1
  import { PackageJson } from 'type-fest';
2
+ export declare const isPluginEnabled: (info: PackageJson) => boolean;
2
3
  type PluginInfo = [string, PackageJson, string];
3
4
  export declare const sortByDependencies: (pluginInfos: PluginInfo[]) => PluginInfo[];
4
5
  export declare const enumeratePluginInfos: (pluginsPath: string) => Promise<PluginInfo[]>;
@@ -2,7 +2,7 @@ import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { logger } from '../log/index.js';
4
4
  const log = logger('core:plugins');
5
- const isPluginEnabled = (info) => {
5
+ export const isPluginEnabled = (info) => {
6
6
  var _a;
7
7
  return ((_a = info.openpeeps) === null || _a === void 0 ? void 0 : _a.enabled) !== false;
8
8
  };
@@ -49,13 +49,6 @@ const enumeratePluginsForNamespace = (pluginsPath, namespace) => {
49
49
  const pluginPath = path.join(pluginsPath, key);
50
50
  const info = JSON.parse(fs.readFileSync(path.join(pluginPath, 'package.json'), 'utf-8'));
51
51
  return [key, info, pluginPath];
52
- })
53
- .filter(([key, info]) => {
54
- if (isPluginEnabled(info)) {
55
- return true;
56
- }
57
- log.info(`Skipping disabled plugin ${key}.`);
58
- return false;
59
52
  });
60
53
  };
61
54
  export const enumeratePluginInfos = async (pluginsPath) => {
@@ -1,6 +1,8 @@
1
1
  import type { PackageJson } from 'type-fest';
2
2
  import type { Plugin, PluginManifest } from '@openpeepshq/common';
3
3
  export * from './pluginAuth';
4
+ export * from './state';
5
+ export * from './install';
4
6
  export declare const getPlugins: () => Plugin[];
5
7
  export declare const getPluginModule: (key: string) => unknown | undefined;
6
8
  export declare const getPluginManifests: () => Record<string, PluginManifest>;
@@ -8,3 +10,6 @@ export declare const initializePlugins: () => Promise<{
8
10
  [k: string]: Plugin;
9
11
  } | undefined>;
10
12
  export declare const sortedPluginInfos: () => Promise<[string, PackageJson, string][]>;
13
+ export declare const reloadPlugins: () => Promise<{
14
+ [k: string]: Plugin;
15
+ } | undefined>;
@@ -1,29 +1,60 @@
1
1
  import { hub, VALID_EVENT_KEYS } from '../events/index.js';
2
2
  import { defaultConfig, registerConfigSchema } from '../config/index.js';
3
- import { pluginManifestSchema } from '@openpeepshq/common';
4
- import { enumeratePluginInfos, enumerateReferencedPluginInfos, sortByDependencies, } from './helpers.js';
3
+ import { i18nResourceSchema, pluginManifestSchema } from '@openpeepshq/common';
4
+ import path from 'node:path';
5
+ import { enumeratePluginInfos, enumerateReferencedPluginInfos, isPluginEnabled, sortByDependencies, } from './helpers.js';
6
+ import { getPluginStateOverrides } from './state.js';
7
+ import { selfHealInstalledPlugins } from './install.js';
5
8
  import { logger } from '../log/index.js';
9
+ import { clearPluginLocales, registerPluginLocales } from '../i18n/index.js';
6
10
  export * from './pluginAuth.js';
11
+ export * from './state.js';
12
+ export * from './install.js';
7
13
  const log = logger('core:plugins');
8
14
  let initialized = false;
9
15
  const loadedPlugins = new Map();
10
16
  const loadedModules = new Map();
11
17
  const pluginManifests = new Map();
18
+ const pluginUnsubscribers = new Map();
12
19
  export const getPlugins = () => Array.from(loadedPlugins.values());
13
20
  export const getPluginModule = (key) => loadedModules.get(key);
14
21
  export const getPluginManifests = () => Object.fromEntries(pluginManifests.entries());
22
+ const clearPluginState = () => {
23
+ for (const unsubscribers of pluginUnsubscribers.values()) {
24
+ for (const unsub of unsubscribers) {
25
+ unsub();
26
+ }
27
+ }
28
+ loadedPlugins.clear();
29
+ loadedModules.clear();
30
+ pluginManifests.clear();
31
+ pluginUnsubscribers.clear();
32
+ clearPluginLocales();
33
+ initialized = false;
34
+ };
15
35
  export const initializePlugins = async () => {
16
36
  if (initialized) {
17
37
  return;
18
38
  }
19
39
  const { plugins: { path: pluginsPath, rootPackageJsonPath }, } = await defaultConfig;
40
+ const stateOverrides = await getPluginStateOverrides();
41
+ // Re-fetch admin-installed plugins whose files are missing (e.g. the
42
+ // plugins path is not a persistent volume and the container was recreated).
43
+ // Never let a failed heal take the boot down — the plugin is surfaced as a
44
+ // failed entry below so an admin can see why and re-install it.
45
+ let healFailures = {};
46
+ try {
47
+ healFailures = await selfHealInstalledPlugins();
48
+ }
49
+ catch (e) {
50
+ log.error(e, 'Plugin self-heal failed; continuing without it.');
51
+ }
20
52
  const loadPlugin = async (key, info, pluginPath) => {
21
- var _a;
53
+ var _a, _b;
22
54
  const [namespace, name] = key.split('/');
23
55
  const displayName = typeof ((_a = info === null || info === void 0 ? void 0 : info.config) === null || _a === void 0 ? void 0 : _a.displayName) === 'string'
24
56
  ? info.config.displayName
25
57
  : key;
26
- log.info(`Loading plugin "${displayName}" (key: ${key}) from path ${pluginPath}.`);
27
58
  const plugin = {
28
59
  key,
29
60
  namespace,
@@ -31,19 +62,31 @@ export const initializePlugins = async () => {
31
62
  info,
32
63
  path: pluginPath,
33
64
  };
65
+ // DB override (set via the admin toggle) takes precedence over the
66
+ // static `openpeeps.enabled` package.json gate; a missing override
67
+ // falls back to the static gate.
68
+ const enabled = (_b = stateOverrides[key]) !== null && _b !== void 0 ? _b : isPluginEnabled(info);
69
+ if (!enabled) {
70
+ log.info(`Skipping disabled plugin "${displayName}" (key: ${key}).`);
71
+ plugin.status = 'disabled';
72
+ loadedPlugins.set(key, plugin);
73
+ return;
74
+ }
75
+ log.info(`Loading plugin "${displayName}" (key: ${key}) from path ${pluginPath}.`);
34
76
  try {
35
77
  const pluginModule = await import(
36
78
  /* @vite-ignore */ `${pluginPath}/dist/index.js`);
37
79
  loadedModules.set(key, pluginModule);
38
80
  if ('interceptors' in pluginModule) {
39
81
  const interceptors = await pluginModule.interceptors();
82
+ const unsubscribers = [];
40
83
  for (const [eventKey, handler] of Object.entries(interceptors)) {
41
84
  if (!VALID_EVENT_KEYS.includes(eventKey)) {
42
85
  log.warn(`${plugin.key} registered handler for unknown event ${eventKey}. Skipping.`);
43
86
  continue;
44
87
  }
45
88
  log.info(`${plugin.key} listening for event ${eventKey}`);
46
- hub.on(eventKey, async (...args) => {
89
+ const unsub = hub.on(eventKey, async (...args) => {
47
90
  try {
48
91
  await handler(...args);
49
92
  }
@@ -51,7 +94,9 @@ export const initializePlugins = async () => {
51
94
  log.error(e, `${plugin.key} handler for event ${eventKey} failed.`);
52
95
  }
53
96
  });
97
+ unsubscribers.push(unsub);
54
98
  }
99
+ pluginUnsubscribers.set(key, unsubscribers);
55
100
  }
56
101
  if ('configSchema' in pluginModule) {
57
102
  registerConfigSchema(namespace, name, pluginModule.configSchema.schema, pluginModule.configSchema.defaults);
@@ -59,6 +104,15 @@ export const initializePlugins = async () => {
59
104
  if ('manifest' in pluginModule) {
60
105
  pluginManifests.set(key, pluginManifestSchema.parse(pluginModule.manifest));
61
106
  }
107
+ if ('locales' in pluginModule) {
108
+ const parsed = i18nResourceSchema.safeParse(pluginModule.locales);
109
+ if (parsed.success) {
110
+ registerPluginLocales(key, parsed.data);
111
+ }
112
+ else {
113
+ log.warn(`${plugin.key} locales export is invalid. Skipping translations.`);
114
+ }
115
+ }
62
116
  plugin.status = 'loaded';
63
117
  }
64
118
  catch (e) {
@@ -76,6 +130,18 @@ export const initializePlugins = async () => {
76
130
  for (const [key, info, pluginPath] of sortedInfos) {
77
131
  await loadPlugin(key, info, pluginPath);
78
132
  }
133
+ for (const [key, reason] of Object.entries(healFailures)) {
134
+ const [namespace, name] = key.split('/');
135
+ loadedPlugins.set(key, {
136
+ key,
137
+ namespace,
138
+ name,
139
+ info: { name: key },
140
+ path: path.join(pluginsPath, key),
141
+ status: 'failed',
142
+ error: reason,
143
+ });
144
+ }
79
145
  initialized = true;
80
146
  return Object.fromEntries(loadedPlugins.entries());
81
147
  };
@@ -86,3 +152,10 @@ export const sortedPluginInfos = async () => {
86
152
  ...enumerateReferencedPluginInfos(rootPackageJsonPath),
87
153
  ]);
88
154
  };
155
+ export const reloadPlugins = async () => {
156
+ log.info('Reloading all plugins...');
157
+ clearPluginState();
158
+ const result = await initializePlugins();
159
+ log.info('Plugin reload complete.');
160
+ return result;
161
+ };
@@ -0,0 +1,39 @@
1
+ import type { PluginInstallSource } from '@openpeepshq/common/types';
2
+ type InstalledPluginRecord = {
3
+ /** Redacted source label (npm:pkg@ver or git:url#ref); never the credentials. */
4
+ source: string;
5
+ /** True when the install required credentials that are not stored. */
6
+ requiresAuth: boolean;
7
+ installedAt: string;
8
+ installedBy?: string;
9
+ };
10
+ type InstalledPluginsBody = Record<string, InstalledPluginRecord>;
11
+ export declare const getInstalledPlugins: () => Promise<InstalledPluginsBody>;
12
+ export declare const linkHostPeerDependencies: (installDir: string, names: string[]) => Promise<{
13
+ success: true;
14
+ } | {
15
+ success: false;
16
+ error: string;
17
+ }>;
18
+ export declare const installPlugin: (source: PluginInstallSource, installedBy?: string, options?: {
19
+ selfHeal?: boolean;
20
+ }) => Promise<{
21
+ success: boolean;
22
+ pluginKey?: string;
23
+ error?: string;
24
+ }>;
25
+ export declare const uninstallPlugin: (pluginKey: string, uninstalledBy?: string) => Promise<{
26
+ success: boolean;
27
+ error?: string;
28
+ }>;
29
+ /**
30
+ * Re-downloads admin-installed plugins whose files are missing from the
31
+ * plugins directory (e.g. after a container recreate whose plugins path was
32
+ * not a persistent volume). Credentials are not stored, so plugins installed
33
+ * from private sources cannot be re-fetched — they are reported for manual
34
+ * re-install instead. Returns pluginKey -> reason for every plugin that is
35
+ * still unavailable after the attempt.
36
+ */
37
+ export declare const selfHealInstalledPlugins: () => Promise<Record<string, string>>;
38
+ export declare const getInstalledPluginKeys: () => Promise<string[]>;
39
+ export {};