@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.
- package/dist/accessTokens/helpers.d.ts +2 -2
- package/dist/accessTokens/tokens.js +14 -7
- package/dist/accounts/mutations.d.ts +2 -2
- package/dist/accounts/mutations.js +33 -35
- package/dist/analytics/cache.js +12 -7
- package/dist/analytics/compile.js +16 -10
- package/dist/analytics/pdfReport.d.ts +1 -0
- package/dist/analytics/pdfReport.js +5 -4
- package/dist/analytics/privacy.d.ts +18 -0
- package/dist/analytics/privacy.js +10 -0
- package/dist/analytics/read.js +75 -19
- package/dist/analytics/report.d.ts +21 -1
- package/dist/analytics/report.js +9 -2
- package/dist/backups/index.js +78 -15
- package/dist/backups/metadata.d.ts +8 -2
- package/dist/backups/metadata.js +6 -2
- package/dist/config/defaults/capabilities.js +13 -2
- package/dist/config/defaults/community.js +7 -9
- package/dist/config/defaults/core.d.ts +1 -1
- package/dist/config/defaults/core.js +3 -0
- package/dist/config/defaults/db.d.ts +0 -2
- package/dist/config/defaults/db.js +0 -2
- package/dist/config/index.d.ts +25 -3
- package/dist/config/index.js +7 -1
- package/dist/db/helpers.d.ts +7 -28
- package/dist/db/helpers.js +30 -152
- package/dist/db/index.d.ts +3 -1
- package/dist/db/index.js +5 -0
- package/dist/db/init.js +2 -2
- package/dist/db/migration/importCollections.d.ts +15 -10
- package/dist/db/migration/importCollections.js +121 -155
- package/dist/db/migration/shared.d.ts +2 -37
- package/dist/db/migration/shared.js +2 -59
- package/dist/db/pg/client.js +4 -0
- package/dist/db/pg/collections.d.ts +2 -2
- package/dist/db/pg/collections.js +2 -2
- package/dist/db/pg/filters/edges.d.ts +1 -1
- package/dist/db/pg/filters/edges.js +1 -1
- package/dist/db/pg/filters/posts.d.ts +11 -0
- package/dist/db/pg/filters/posts.js +37 -3
- package/dist/db/pg/filters/profiles.d.ts +1 -0
- package/dist/db/pg/filters/profiles.js +2 -1
- package/dist/db/pg/map/filters.js +37 -2
- package/dist/db/pg/map/mutations.js +13 -8
- package/dist/db/pg/map/registry.d.ts +5 -0
- package/dist/db/pg/map/registry.js +64 -24
- package/dist/db/pg/map/relations.d.ts +1 -1
- package/dist/db/pg/map/relations.js +98 -46
- package/dist/db/pg/migrate.d.ts +22 -0
- package/dist/db/pg/migrate.js +88 -2
- package/dist/db/pg/queries/activity.js +3 -3
- package/dist/db/pg/queries/sorts.d.ts +1 -0
- package/dist/db/pg/queries/sorts.js +4 -0
- package/dist/db/pg/schema/documents.d.ts +422 -41
- package/dist/db/pg/schema/documents.js +43 -9
- package/dist/db/pg/schema/edges.d.ts +117 -7
- package/dist/db/pg/schema/edges.js +4 -2
- package/dist/db/pg/schema/index.d.ts +505 -15
- package/dist/db/pg/sql/0007_shallow_oracle.sql +3 -0
- package/dist/db/pg/sql/0008_group_owner_roles.sql +31 -0
- package/dist/db/pg/sql/0009_event_occurrences.sql +26 -0
- package/dist/db/pg/sql/0010_user_group_membership_roles.sql +16 -0
- package/dist/db/pg/sql/0011_drop_data_migrations.sql +1 -0
- package/dist/db/pg/sql/0012_posts_last_activity_at.sql +5 -0
- package/dist/db/pg/sql/0013_add_blocks_edge.sql +12 -0
- package/dist/db/pg/sql/0014_federation_datamodel.sql +59 -0
- package/dist/db/pg/sql/0015_profile_hashtags.sql +12 -0
- package/dist/db/pg/sql/meta/{0006_snapshot.json → 0015_snapshot.json} +393 -39
- package/dist/db/pg/sql/meta/_journal.json +64 -1
- package/dist/db/replaceOrigin.js +6 -0
- package/dist/db/types.d.ts +0 -4
- package/dist/email/render.js +11 -3
- package/dist/events/index.d.ts +6 -1
- package/dist/events/index.js +55 -33
- package/dist/federation/activities.d.ts +17 -0
- package/dist/federation/activities.js +26 -0
- package/dist/federation/identity.d.ts +16 -0
- package/dist/federation/identity.js +52 -0
- package/dist/federation/index.d.ts +4 -0
- package/dist/federation/index.js +3 -0
- package/dist/federation/profiles.d.ts +3 -0
- package/dist/federation/profiles.js +14 -0
- package/dist/groups/finders.d.ts +3 -2
- package/dist/groups/helpers.d.ts +24 -6
- package/dist/groups/mapping.d.ts +6 -4
- package/dist/groups/mapping.js +2 -2
- package/dist/groups/mutations.js +1 -1
- package/dist/hashtags/finders.d.ts +6 -3
- package/dist/hashtags/finders.js +2 -0
- package/dist/hashtags/helpers.d.ts +8 -0
- package/dist/hashtags/helpers.js +4 -0
- package/dist/hashtags/index.d.ts +2 -0
- package/dist/hashtags/index.js +2 -0
- package/dist/hashtags/mutations.d.ts +3 -0
- package/dist/hashtags/mutations.js +13 -1
- package/dist/i18n/index.d.ts +1 -1
- package/dist/i18n/index.js +3 -1
- package/dist/i18n/pluginLocales.d.ts +6 -0
- package/dist/i18n/pluginLocales.js +15 -0
- package/dist/inviteLinks/helpers.d.ts +4 -4
- package/dist/jams/cache.d.ts +1 -1
- package/dist/jams/cache.js +2 -1
- package/dist/jams/export.d.ts +19 -0
- package/dist/jams/export.js +60 -0
- package/dist/jams/finders.d.ts +2 -1
- package/dist/jams/finders.js +18 -7
- package/dist/jams/health.d.ts +8 -0
- package/dist/jams/health.js +46 -0
- package/dist/jams/helpers.d.ts +6 -2
- package/dist/jams/index.d.ts +6 -3
- package/dist/jams/index.js +41 -27
- package/dist/jams/jobs.js +1 -1
- package/dist/jams/livekit.d.ts +93 -10
- package/dist/jams/livekit.js +151 -52
- package/dist/jams/mapping.d.ts +17 -7
- package/dist/jams/mutations.d.ts +3 -1
- package/dist/jams/recording.d.ts +10 -0
- package/dist/jams/recording.js +32 -0
- package/dist/jams/rtmp.d.ts +5 -0
- package/dist/jams/rtmp.js +8 -0
- package/dist/jams/token.d.ts +15 -3
- package/dist/jams/token.js +30 -16
- package/dist/jams/waitingRoom.d.ts +6 -6
- package/dist/jams/waitingRoom.js +24 -23
- package/dist/jobs/index.d.ts +1 -0
- package/dist/jobs/index.js +6 -1
- package/dist/jobs/jobDetail.js +1 -6
- package/dist/media/index.d.ts +1 -1
- package/dist/media/index.js +23 -8
- package/dist/media/processing.js +18 -7
- package/dist/notifications/defaultNotifications/follow/index.js +2 -2
- package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +3 -1
- package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +3 -1
- package/dist/notifications/defaultNotifications/index.js +4 -0
- package/dist/notifications/defaultNotifications/newGroupPost/index.js +12 -6
- package/dist/notifications/defaultNotifications/pollEnded/index.d.ts +19 -0
- package/dist/notifications/defaultNotifications/pollEnded/index.js +39 -0
- package/dist/notifications/defaultNotifications/pollEnded/recipients.d.ts +3 -0
- package/dist/notifications/defaultNotifications/pollEnded/recipients.js +18 -0
- package/dist/notifications/defaultNotifications/rsvp/index.d.ts +6 -1
- package/dist/notifications/defaultNotifications/rsvp/index.js +7 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/index.d.ts +24 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +75 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.d.ts +4 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.js +11 -0
- package/dist/notifications/helpers.js +6 -2
- package/dist/notifications/jobs.js +3 -1
- package/dist/notifications/mutations.js +4 -0
- package/dist/notifications/push.js +11 -4
- package/dist/plugins/helpers.d.ts +1 -0
- package/dist/plugins/helpers.js +1 -8
- package/dist/plugins/index.d.ts +5 -0
- package/dist/plugins/index.js +78 -5
- package/dist/plugins/install.d.ts +39 -0
- package/dist/plugins/install.js +455 -0
- package/dist/plugins/pluginAuth.d.ts +1 -1
- package/dist/plugins/pluginAuth.js +10 -6
- package/dist/plugins/state.d.ts +4 -0
- package/dist/plugins/state.js +29 -0
- package/dist/posts/activity.d.ts +9 -0
- package/dist/posts/activity.js +35 -0
- package/dist/posts/contextClosure.d.ts +1 -9
- package/dist/posts/contextClosure.js +15 -44
- package/dist/posts/conversationQueries.d.ts +7 -0
- package/dist/posts/conversationQueries.js +76 -2
- package/dist/posts/eventAgenda.d.ts +166 -0
- package/dist/posts/eventAgenda.js +126 -0
- package/dist/posts/eventOccurrenceJobs.d.ts +4 -0
- package/dist/posts/eventOccurrenceJobs.js +28 -0
- package/dist/posts/eventOccurrences.d.ts +10 -0
- package/dist/posts/eventOccurrences.js +61 -0
- package/dist/posts/finders.d.ts +47 -16
- package/dist/posts/finders.js +93 -62
- package/dist/posts/helpers/filters.js +14 -9
- package/dist/posts/helpers/index.d.ts +129 -30
- package/dist/posts/helpers/index.js +66 -33
- package/dist/posts/index.d.ts +7 -1
- package/dist/posts/index.js +7 -1
- package/dist/posts/mapping.d.ts +491 -13
- package/dist/posts/mapping.js +45 -10
- package/dist/posts/mutations.d.ts +441 -4
- package/dist/posts/mutations.js +177 -43
- package/dist/posts/pollEnd.d.ts +3 -0
- package/dist/posts/pollEnd.js +7 -0
- package/dist/posts/pollEndJobs.d.ts +8 -0
- package/dist/posts/pollEndJobs.js +49 -0
- package/dist/posts/replyClosure.d.ts +10 -0
- package/dist/posts/replyClosure.js +43 -0
- package/dist/posts/rsvpConfirmationEmail.js +14 -15
- package/dist/posts/threadPreview.d.ts +8 -0
- package/dist/posts/threadPreview.js +44 -0
- package/dist/posts/unseenCounts.d.ts +2 -0
- package/dist/posts/unseenCounts.js +28 -8
- package/dist/profileSettings/cache.js +22 -5
- package/dist/profileSettings/mapping.d.ts +2 -0
- package/dist/profiles/activityQueries.d.ts +5 -0
- package/dist/profiles/activityQueries.js +85 -0
- package/dist/profiles/activitySummary.d.ts +3 -0
- package/dist/profiles/activitySummary.js +87 -0
- package/dist/profiles/blocks.d.ts +12 -0
- package/dist/profiles/blocks.js +73 -0
- package/dist/profiles/cache.d.ts +4 -1
- package/dist/profiles/cache.js +28 -7
- package/dist/profiles/finders.d.ts +2 -1
- package/dist/profiles/finders.js +8 -3
- package/dist/profiles/helpers.d.ts +7 -5
- package/dist/profiles/index.d.ts +3 -1
- package/dist/profiles/index.js +3 -1
- package/dist/profiles/mapping.d.ts +10 -5
- package/dist/profiles/mapping.js +13 -1
- package/dist/profiles/mutations.d.ts +8 -4
- package/dist/profiles/mutations.js +42 -15
- package/dist/pushSubscriptions/helpers.d.ts +2 -2
- package/dist/pushSubscriptions/mutations.js +13 -1
- package/dist/redis/connection.d.ts +2 -0
- package/dist/redis/connection.js +25 -6
- package/dist/reports/helpers.d.ts +6 -6
- package/dist/roles/index.d.ts +1 -1
- package/dist/roles/index.js +1 -1
- package/dist/roles/mapping.d.ts +1 -0
- package/dist/roles/mutations.js +86 -3
- package/dist/search/mapping.d.ts +1 -1
- package/dist/search/mapping.js +6 -2
- package/dist/server/index.d.ts +19 -1
- package/dist/server/index.js +37 -18
- package/dist/server/stablePublicServerInfo.d.ts +17 -0
- package/dist/server/stablePublicServerInfo.js +37 -0
- package/dist/server/status.d.ts +25 -0
- package/dist/server/status.js +98 -0
- package/dist/stats/finders.d.ts +1 -16131
- package/dist/stats/finders.js +9 -5
- package/dist/stats/mapping.d.ts +21 -1
- package/dist/stats/mapping.js +0 -3
- package/package.json +6 -12
- package/dist/db/arango.d.ts +0 -2
- package/dist/db/arango.js +0 -110
- package/dist/db/migration/autoMigrate.d.ts +0 -2
- package/dist/db/migration/autoMigrate.js +0 -111
- package/dist/db/migration/cli.d.ts +0 -1
- package/dist/db/migration/cli.js +0 -56
- package/dist/db/migration/detect.d.ts +0 -6
- package/dist/db/migration/detect.js +0 -87
- package/dist/db/migration/exportArango.d.ts +0 -4
- package/dist/db/migration/exportArango.js +0 -80
- package/dist/db/migration/importPostgres.d.ts +0 -3
- package/dist/db/migration/importPostgres.js +0 -18
- package/dist/db/migration/transform.d.ts +0 -18
- package/dist/db/migration/transform.js +0 -209
- package/dist/db/migration/validate.d.ts +0 -18
- package/dist/db/migration/validate.js +0 -69
- package/dist/db/pg/sql/meta/0000_snapshot.json +0 -3380
- package/dist/db/pg/sql/meta/0004_snapshot.json +0 -4114
- package/dist/db/pg/sql/meta/0005_snapshot.json +0 -4179
- package/dist/mastodon/index.d.ts +0 -4
- package/dist/mastodon/index.js +0 -51
- package/dist/mastodon/types.d.ts +0 -7579
- package/dist/mastodon/types.js +0 -523
- package/dist/mastodon/typescript.d.ts +0 -1578
- package/dist/mastodon/typescript.js +0 -1
- package/dist/roles/defaults.d.ts +0 -2
- 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
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
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[]>;
|
package/dist/plugins/helpers.js
CHANGED
|
@@ -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) => {
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -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>;
|
package/dist/plugins/index.js
CHANGED
|
@@ -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
|
|
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 {};
|