@openpeepshq/core 0.1.32 → 0.1.33
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/analytics/cache.js +12 -7
- 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 +24 -11
- package/dist/analytics/report.d.ts +1 -1
- package/dist/analytics/report.js +9 -2
- package/dist/backups/index.js +6 -3
- package/dist/backups/metadata.d.ts +7 -0
- package/dist/config/defaults/community.js +0 -6
- package/dist/config/defaults/db.d.ts +0 -2
- package/dist/config/defaults/db.js +0 -2
- package/dist/config/index.d.ts +10 -9
- package/dist/db/helpers.d.ts +6 -28
- package/dist/db/helpers.js +19 -149
- package/dist/db/index.d.ts +2 -0
- package/dist/db/index.js +4 -0
- package/dist/db/init.js +3 -2
- package/dist/db/migration/detect.d.ts +0 -3
- package/dist/db/migration/detect.js +0 -54
- package/dist/db/migration/importCollections.d.ts +1 -1
- package/dist/db/migration/importCollections.js +22 -6
- package/dist/db/migration/shared.d.ts +0 -4
- package/dist/db/migration/shared.js +0 -7
- package/dist/db/migration/transform.d.ts +2 -0
- package/dist/db/migration/transform.js +23 -0
- package/dist/db/pg/client.js +4 -0
- 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 +1 -0
- package/dist/db/pg/filters/posts.js +11 -1
- package/dist/db/pg/map/filters.js +5 -0
- package/dist/db/pg/map/relations.d.ts +1 -1
- package/dist/db/pg/map/relations.js +89 -41
- package/dist/db/pg/migrate.d.ts +23 -0
- package/dist/db/pg/migrate.js +87 -1
- package/dist/db/pg/schema/documents.d.ts +143 -0
- package/dist/db/pg/schema/documents.js +22 -1
- package/dist/db/pg/schema/edges.d.ts +1 -0
- package/dist/db/pg/schema/edges.js +2 -1
- package/dist/db/pg/schema/index.d.ts +143 -0
- 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/meta/0007_snapshot.json +4179 -0
- package/dist/db/pg/sql/meta/0009_snapshot.json +4299 -0
- package/dist/db/pg/sql/meta/_journal.json +21 -0
- package/dist/db/replaceOrigin.js +6 -0
- package/dist/db/types.d.ts +0 -4
- package/dist/events/index.d.ts +2 -1
- package/dist/events/index.js +54 -33
- package/dist/groups/finders.d.ts +2 -2
- package/dist/groups/helpers.d.ts +6 -6
- package/dist/groups/mapping.d.ts +4 -4
- package/dist/groups/mapping.js +2 -2
- package/dist/groups/mutations.js +1 -1
- 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/finders.d.ts +2 -1
- package/dist/jams/finders.js +18 -7
- package/dist/jams/helpers.d.ts +4 -0
- package/dist/jams/index.d.ts +4 -3
- package/dist/jams/index.js +20 -13
- package/dist/jams/livekit.d.ts +46 -8
- package/dist/jams/livekit.js +103 -21
- package/dist/jams/mapping.d.ts +14 -4
- package/dist/jams/mutations.d.ts +2 -0
- package/dist/jams/rtmp.d.ts +5 -0
- package/dist/jams/rtmp.js +8 -0
- package/dist/jams/token.d.ts +3 -3
- package/dist/jams/token.js +15 -12
- package/dist/jams/waitingRoom.d.ts +6 -6
- package/dist/jams/waitingRoom.js +24 -23
- package/dist/migration/index.d.ts +4 -0
- package/dist/migration/index.js +4 -0
- package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +3 -1
- package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +3 -1
- package/dist/notifications/helpers.js +6 -2
- 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 +41 -4
- package/dist/plugins/install.d.ts +20 -0
- package/dist/plugins/install.js +223 -0
- package/dist/plugins/state.d.ts +4 -0
- package/dist/plugins/state.js +29 -0
- package/dist/posts/eventAgenda.d.ts +165 -0
- package/dist/posts/eventAgenda.js +120 -0
- package/dist/posts/eventOccurrenceJobs.d.ts +4 -0
- package/dist/posts/eventOccurrenceJobs.js +23 -0
- package/dist/posts/eventOccurrences.d.ts +4 -0
- package/dist/posts/eventOccurrences.js +40 -0
- package/dist/posts/finders.d.ts +32 -8
- package/dist/posts/finders.js +27 -45
- package/dist/posts/helpers/filters.js +1 -1
- package/dist/posts/helpers/index.d.ts +102 -16
- package/dist/posts/helpers/index.js +33 -20
- package/dist/posts/index.d.ts +3 -0
- package/dist/posts/index.js +3 -0
- package/dist/posts/mapping.d.ts +275 -0
- package/dist/posts/mapping.js +37 -3
- package/dist/posts/mutations.d.ts +1 -1
- package/dist/posts/mutations.js +29 -18
- package/dist/posts/rsvpConfirmationEmail.js +2 -1
- package/dist/posts/unseenCounts.d.ts +2 -0
- package/dist/posts/unseenCounts.js +25 -8
- package/dist/profiles/cache.d.ts +3 -1
- package/dist/profiles/cache.js +9 -1
- package/dist/profiles/helpers.d.ts +5 -5
- package/dist/profiles/index.d.ts +1 -1
- package/dist/profiles/index.js +1 -1
- package/dist/profiles/mapping.d.ts +5 -5
- package/dist/profiles/mutations.js +12 -14
- package/dist/pushSubscriptions/helpers.d.ts +2 -2
- package/dist/pushSubscriptions/mutations.js +13 -1
- package/dist/reports/helpers.d.ts +6 -6
- package/dist/roles/defaults.js +1 -0
- package/dist/server/index.d.ts +7 -7
- package/dist/server/index.js +15 -8
- package/dist/stats/finders.d.ts +1692 -142
- package/dist/stats/mapping.d.ts +21 -0
- package/package.json +4 -9
- 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/exportArango.d.ts +0 -4
- package/dist/db/migration/exportArango.js +0 -80
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,45 @@
|
|
|
1
1
|
import { hub, VALID_EVENT_KEYS } from '../events/index.js';
|
|
2
2
|
import { defaultConfig, registerConfigSchema } from '../config/index.js';
|
|
3
3
|
import { pluginManifestSchema } from '@openpeepshq/common';
|
|
4
|
-
import { enumeratePluginInfos, enumerateReferencedPluginInfos, sortByDependencies, } from './helpers.js';
|
|
4
|
+
import { enumeratePluginInfos, enumerateReferencedPluginInfos, isPluginEnabled, sortByDependencies, } from './helpers.js';
|
|
5
|
+
import { getPluginStateOverrides } from './state.js';
|
|
5
6
|
import { logger } from '../log/index.js';
|
|
6
7
|
export * from './pluginAuth.js';
|
|
8
|
+
export * from './state.js';
|
|
9
|
+
export * from './install.js';
|
|
7
10
|
const log = logger('core:plugins');
|
|
8
11
|
let initialized = false;
|
|
9
12
|
const loadedPlugins = new Map();
|
|
10
13
|
const loadedModules = new Map();
|
|
11
14
|
const pluginManifests = new Map();
|
|
15
|
+
const pluginUnsubscribers = new Map();
|
|
12
16
|
export const getPlugins = () => Array.from(loadedPlugins.values());
|
|
13
17
|
export const getPluginModule = (key) => loadedModules.get(key);
|
|
14
18
|
export const getPluginManifests = () => Object.fromEntries(pluginManifests.entries());
|
|
19
|
+
const clearPluginState = () => {
|
|
20
|
+
for (const unsubscribers of pluginUnsubscribers.values()) {
|
|
21
|
+
for (const unsub of unsubscribers) {
|
|
22
|
+
unsub();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
loadedPlugins.clear();
|
|
26
|
+
loadedModules.clear();
|
|
27
|
+
pluginManifests.clear();
|
|
28
|
+
pluginUnsubscribers.clear();
|
|
29
|
+
initialized = false;
|
|
30
|
+
};
|
|
15
31
|
export const initializePlugins = async () => {
|
|
16
32
|
if (initialized) {
|
|
17
33
|
return;
|
|
18
34
|
}
|
|
19
35
|
const { plugins: { path: pluginsPath, rootPackageJsonPath }, } = await defaultConfig;
|
|
36
|
+
const stateOverrides = await getPluginStateOverrides();
|
|
20
37
|
const loadPlugin = async (key, info, pluginPath) => {
|
|
21
|
-
var _a;
|
|
38
|
+
var _a, _b;
|
|
22
39
|
const [namespace, name] = key.split('/');
|
|
23
40
|
const displayName = typeof ((_a = info === null || info === void 0 ? void 0 : info.config) === null || _a === void 0 ? void 0 : _a.displayName) === 'string'
|
|
24
41
|
? info.config.displayName
|
|
25
42
|
: key;
|
|
26
|
-
log.info(`Loading plugin "${displayName}" (key: ${key}) from path ${pluginPath}.`);
|
|
27
43
|
const plugin = {
|
|
28
44
|
key,
|
|
29
45
|
namespace,
|
|
@@ -31,19 +47,31 @@ export const initializePlugins = async () => {
|
|
|
31
47
|
info,
|
|
32
48
|
path: pluginPath,
|
|
33
49
|
};
|
|
50
|
+
// DB override (set via the admin toggle) takes precedence over the
|
|
51
|
+
// static `openpeeps.enabled` package.json gate; a missing override
|
|
52
|
+
// falls back to the static gate.
|
|
53
|
+
const enabled = (_b = stateOverrides[key]) !== null && _b !== void 0 ? _b : isPluginEnabled(info);
|
|
54
|
+
if (!enabled) {
|
|
55
|
+
log.info(`Skipping disabled plugin "${displayName}" (key: ${key}).`);
|
|
56
|
+
plugin.status = 'disabled';
|
|
57
|
+
loadedPlugins.set(key, plugin);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
log.info(`Loading plugin "${displayName}" (key: ${key}) from path ${pluginPath}.`);
|
|
34
61
|
try {
|
|
35
62
|
const pluginModule = await import(
|
|
36
63
|
/* @vite-ignore */ `${pluginPath}/dist/index.js`);
|
|
37
64
|
loadedModules.set(key, pluginModule);
|
|
38
65
|
if ('interceptors' in pluginModule) {
|
|
39
66
|
const interceptors = await pluginModule.interceptors();
|
|
67
|
+
const unsubscribers = [];
|
|
40
68
|
for (const [eventKey, handler] of Object.entries(interceptors)) {
|
|
41
69
|
if (!VALID_EVENT_KEYS.includes(eventKey)) {
|
|
42
70
|
log.warn(`${plugin.key} registered handler for unknown event ${eventKey}. Skipping.`);
|
|
43
71
|
continue;
|
|
44
72
|
}
|
|
45
73
|
log.info(`${plugin.key} listening for event ${eventKey}`);
|
|
46
|
-
hub.on(eventKey, async (...args) => {
|
|
74
|
+
const unsub = hub.on(eventKey, async (...args) => {
|
|
47
75
|
try {
|
|
48
76
|
await handler(...args);
|
|
49
77
|
}
|
|
@@ -51,7 +79,9 @@ export const initializePlugins = async () => {
|
|
|
51
79
|
log.error(e, `${plugin.key} handler for event ${eventKey} failed.`);
|
|
52
80
|
}
|
|
53
81
|
});
|
|
82
|
+
unsubscribers.push(unsub);
|
|
54
83
|
}
|
|
84
|
+
pluginUnsubscribers.set(key, unsubscribers);
|
|
55
85
|
}
|
|
56
86
|
if ('configSchema' in pluginModule) {
|
|
57
87
|
registerConfigSchema(namespace, name, pluginModule.configSchema.schema, pluginModule.configSchema.defaults);
|
|
@@ -86,3 +116,10 @@ export const sortedPluginInfos = async () => {
|
|
|
86
116
|
...enumerateReferencedPluginInfos(rootPackageJsonPath),
|
|
87
117
|
]);
|
|
88
118
|
};
|
|
119
|
+
export const reloadPlugins = async () => {
|
|
120
|
+
log.info('Reloading all plugins...');
|
|
121
|
+
clearPluginState();
|
|
122
|
+
const result = await initializePlugins();
|
|
123
|
+
log.info('Plugin reload complete.');
|
|
124
|
+
return result;
|
|
125
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type InstallSource = {
|
|
2
|
+
type: 'npm';
|
|
3
|
+
package: string;
|
|
4
|
+
version?: string;
|
|
5
|
+
} | {
|
|
6
|
+
type: 'git';
|
|
7
|
+
url: string;
|
|
8
|
+
ref?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const installPlugin: (source: InstallSource, installedBy?: string) => Promise<{
|
|
11
|
+
success: boolean;
|
|
12
|
+
pluginKey?: string;
|
|
13
|
+
error?: string;
|
|
14
|
+
}>;
|
|
15
|
+
export declare const uninstallPlugin: (pluginKey: string, uninstalledBy?: string) => Promise<{
|
|
16
|
+
success: boolean;
|
|
17
|
+
error?: string;
|
|
18
|
+
}>;
|
|
19
|
+
export declare const getInstalledPluginKeys: () => Promise<string[]>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { spawn } from 'node:child_process';
|
|
13
|
+
import fs from 'node:fs/promises';
|
|
14
|
+
import path from 'node:path';
|
|
15
|
+
import { defaultConfig } from '../config/index.js';
|
|
16
|
+
import { logger } from '../log/index.js';
|
|
17
|
+
import { allpeepDb } from '../db/index.js';
|
|
18
|
+
import { configs } from '../db/pg/schema/documents.js';
|
|
19
|
+
import { nowIso } from '../db/pg/mappers.js';
|
|
20
|
+
import { eq } from 'drizzle-orm';
|
|
21
|
+
import { setPluginEnabledOverride } from './state.js';
|
|
22
|
+
const log = logger('core:plugins:install');
|
|
23
|
+
const INSTALLED_PLUGINS_KEY = 'openpeeps-installed-plugins';
|
|
24
|
+
const getInstalledPlugins = async () => {
|
|
25
|
+
var _a, _b;
|
|
26
|
+
const { db } = await allpeepDb();
|
|
27
|
+
const rows = await db
|
|
28
|
+
.select()
|
|
29
|
+
.from(configs)
|
|
30
|
+
.where(eq(configs.key, INSTALLED_PLUGINS_KEY))
|
|
31
|
+
.limit(1);
|
|
32
|
+
return (_b = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.body) !== null && _b !== void 0 ? _b : {};
|
|
33
|
+
};
|
|
34
|
+
const setInstalledPlugin = async (pluginKey, source, installedBy) => {
|
|
35
|
+
const installed = await getInstalledPlugins();
|
|
36
|
+
const body = Object.assign(Object.assign({}, installed), { [pluginKey]: { source, installedAt: nowIso(), installedBy } });
|
|
37
|
+
const ts = nowIso();
|
|
38
|
+
const { db } = await allpeepDb();
|
|
39
|
+
await db
|
|
40
|
+
.insert(configs)
|
|
41
|
+
.values({ key: INSTALLED_PLUGINS_KEY, body, createdAt: ts, updatedAt: ts })
|
|
42
|
+
.onConflictDoUpdate({
|
|
43
|
+
target: configs.key,
|
|
44
|
+
set: { body, updatedAt: ts },
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
const removeInstalledPlugin = async (pluginKey) => {
|
|
48
|
+
const installed = await getInstalledPlugins();
|
|
49
|
+
const _a = installed, _b = pluginKey, _removed = _a[_b], rest = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
|
|
50
|
+
const ts = nowIso();
|
|
51
|
+
const { db } = await allpeepDb();
|
|
52
|
+
await db
|
|
53
|
+
.insert(configs)
|
|
54
|
+
.values({
|
|
55
|
+
key: INSTALLED_PLUGINS_KEY,
|
|
56
|
+
body: rest,
|
|
57
|
+
createdAt: ts,
|
|
58
|
+
updatedAt: ts,
|
|
59
|
+
})
|
|
60
|
+
.onConflictDoUpdate({
|
|
61
|
+
target: configs.key,
|
|
62
|
+
set: { body: rest, updatedAt: ts },
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
const runCommand = (command, args, cwd) => new Promise((resolve) => {
|
|
66
|
+
const child = spawn(command, args, { cwd, shell: true });
|
|
67
|
+
let stdout = '';
|
|
68
|
+
let stderr = '';
|
|
69
|
+
child.stdout.on('data', (chunk) => {
|
|
70
|
+
stdout += chunk.toString();
|
|
71
|
+
});
|
|
72
|
+
child.stderr.on('data', (chunk) => {
|
|
73
|
+
stderr += chunk.toString();
|
|
74
|
+
});
|
|
75
|
+
child.on('close', (exitCode) => {
|
|
76
|
+
resolve({ exitCode: exitCode !== null && exitCode !== void 0 ? exitCode : 1, stdout, stderr });
|
|
77
|
+
});
|
|
78
|
+
child.on('error', (err) => {
|
|
79
|
+
resolve({ exitCode: 1, stdout, stderr: String(err) });
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
const getPluginDir = async () => {
|
|
83
|
+
const { plugins } = await defaultConfig;
|
|
84
|
+
return plugins.path;
|
|
85
|
+
};
|
|
86
|
+
const sourceLabel = (source) => source.type === 'npm'
|
|
87
|
+
? `npm:${source.package}${source.version ? `@${source.version}` : ''}`
|
|
88
|
+
: `git:${source.url}${source.ref ? `#${source.ref}` : ''}`;
|
|
89
|
+
export const installPlugin = async (source, installedBy) => {
|
|
90
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
91
|
+
const pluginsDir = await getPluginDir();
|
|
92
|
+
const label = sourceLabel(source);
|
|
93
|
+
let tempDir;
|
|
94
|
+
try {
|
|
95
|
+
tempDir = await fs.mkdtemp(path.join(pluginsDir, '.install-'));
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
log.error(e, `Failed to create temp dir in ${pluginsDir}`);
|
|
99
|
+
return { success: false, error: `Cannot write to plugins directory: ${e}` };
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
let installDir;
|
|
103
|
+
if (source.type === 'npm') {
|
|
104
|
+
const pkg = source.version
|
|
105
|
+
? `${source.package}@${source.version}`
|
|
106
|
+
: source.package;
|
|
107
|
+
log.info(`Installing npm package ${pkg} to temp dir ${tempDir}`);
|
|
108
|
+
const init = await runCommand('npm', ['init', '-y'], tempDir);
|
|
109
|
+
if (init.exitCode !== 0) {
|
|
110
|
+
return { success: false, error: `npm init failed: ${init.stderr}` };
|
|
111
|
+
}
|
|
112
|
+
const install = await runCommand('npm', ['install', pkg], tempDir);
|
|
113
|
+
if (install.exitCode !== 0) {
|
|
114
|
+
return {
|
|
115
|
+
success: false,
|
|
116
|
+
error: `npm install failed: ${install.stderr}`,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
installDir = path.join(tempDir, 'node_modules', source.package);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
log.info(`Cloning git repo ${source.url} to temp dir ${tempDir}`);
|
|
123
|
+
const cloneArgs = ['clone', '--depth', '1'];
|
|
124
|
+
if (source.ref) {
|
|
125
|
+
cloneArgs.push('--branch', source.ref);
|
|
126
|
+
}
|
|
127
|
+
cloneArgs.push(source.url, path.join(tempDir, 'repo'));
|
|
128
|
+
const clone = await runCommand('git', cloneArgs, tempDir);
|
|
129
|
+
if (clone.exitCode !== 0) {
|
|
130
|
+
return { success: false, error: `git clone failed: ${clone.stderr}` };
|
|
131
|
+
}
|
|
132
|
+
installDir = path.join(tempDir, 'repo');
|
|
133
|
+
}
|
|
134
|
+
// Read package.json to determine namespace/name
|
|
135
|
+
const pkgJsonRaw = await fs.readFile(path.join(installDir, 'package.json'), 'utf-8');
|
|
136
|
+
const pkgJson = JSON.parse(pkgJsonRaw);
|
|
137
|
+
const namespace = (_e = (_b = (_a = pkgJson.openpeeps) === null || _a === void 0 ? void 0 : _a.namespace) !== null && _b !== void 0 ? _b : (_d = (_c = pkgJson.name) === null || _c === void 0 ? void 0 : _c.split('/')[0]) === null || _d === void 0 ? void 0 : _d.replace(/^@/, '')) !== null && _e !== void 0 ? _e : 'custom';
|
|
138
|
+
const name = (_l = (_j = (_g = (_f = pkgJson.openpeeps) === null || _f === void 0 ? void 0 : _f.name) !== null && _g !== void 0 ? _g : (_h = pkgJson.name) === null || _h === void 0 ? void 0 : _h.split('/')[1]) !== null && _j !== void 0 ? _j : (_k = pkgJson.name) === null || _k === void 0 ? void 0 : _k.replace(/^@[^/]+\//, '')) !== null && _l !== void 0 ? _l : 'plugin';
|
|
139
|
+
const pluginKey = `${namespace}/${name}`;
|
|
140
|
+
const destDir = path.join(pluginsDir, namespace, name);
|
|
141
|
+
// Check if already exists in the plugins dir (built-in)
|
|
142
|
+
const existingEntries = await fs
|
|
143
|
+
.readdir(pluginsDir)
|
|
144
|
+
.catch(() => []);
|
|
145
|
+
const nsEntries = existingEntries.includes(namespace)
|
|
146
|
+
? await fs
|
|
147
|
+
.readdir(path.join(pluginsDir, namespace))
|
|
148
|
+
.catch(() => [])
|
|
149
|
+
: [];
|
|
150
|
+
if (nsEntries.includes(name)) {
|
|
151
|
+
// Check if this is a built-in plugin (not in installed list)
|
|
152
|
+
const installed = await getInstalledPlugins();
|
|
153
|
+
if (!installed[pluginKey]) {
|
|
154
|
+
return {
|
|
155
|
+
success: false,
|
|
156
|
+
error: `Plugin "${pluginKey}" is a built-in plugin and cannot be overwritten.`,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
// Build the plugin if it has a build script
|
|
161
|
+
if ((_m = pkgJson.scripts) === null || _m === void 0 ? void 0 : _m.build) {
|
|
162
|
+
log.info(`Building plugin ${pluginKey}...`);
|
|
163
|
+
const buildDeps = await runCommand('npm', ['install'], installDir);
|
|
164
|
+
if (buildDeps.exitCode !== 0) {
|
|
165
|
+
return {
|
|
166
|
+
success: false,
|
|
167
|
+
error: `Dependency install failed: ${buildDeps.stderr}`,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
const build = await runCommand('npm', ['run', 'build'], installDir);
|
|
171
|
+
if (build.exitCode !== 0) {
|
|
172
|
+
return {
|
|
173
|
+
success: false,
|
|
174
|
+
error: `Build failed: ${build.stderr}`,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
// Move to final location
|
|
179
|
+
await fs.mkdir(path.join(pluginsDir, namespace), { recursive: true });
|
|
180
|
+
await fs.rm(destDir, { recursive: true, force: true });
|
|
181
|
+
await fs.cp(installDir, destDir, { recursive: true });
|
|
182
|
+
await fs.rm(tempDir, { recursive: true, force: true });
|
|
183
|
+
await setInstalledPlugin(pluginKey, label, installedBy);
|
|
184
|
+
// Installed plugins never auto-enable — an admin must explicitly
|
|
185
|
+
// activate them via the enable toggle (Phase B) after reviewing them.
|
|
186
|
+
await setPluginEnabledOverride(pluginKey, false);
|
|
187
|
+
log.info(`Plugin ${pluginKey} installed successfully from ${label}${installedBy ? ` by ${installedBy}` : ''}. Disabled by default — activate it explicitly to load it.`);
|
|
188
|
+
return { success: true, pluginKey };
|
|
189
|
+
}
|
|
190
|
+
catch (e) {
|
|
191
|
+
// Cleanup on any error
|
|
192
|
+
await fs.rm(tempDir, { recursive: true, force: true }).catch(() => { });
|
|
193
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
194
|
+
log.error(e, `Failed to install plugin from ${label}.`);
|
|
195
|
+
return { success: false, error: message };
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
export const uninstallPlugin = async (pluginKey, uninstalledBy) => {
|
|
199
|
+
const installed = await getInstalledPlugins();
|
|
200
|
+
if (!installed[pluginKey]) {
|
|
201
|
+
return {
|
|
202
|
+
success: false,
|
|
203
|
+
error: `Plugin "${pluginKey}" was not installed via the admin UI.`,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
const pluginsDir = await getPluginDir();
|
|
207
|
+
const pluginDir = path.join(pluginsDir, pluginKey);
|
|
208
|
+
try {
|
|
209
|
+
await fs.rm(pluginDir, { recursive: true, force: true });
|
|
210
|
+
await removeInstalledPlugin(pluginKey);
|
|
211
|
+
log.info(`Plugin ${pluginKey} uninstalled${uninstalledBy ? ` by ${uninstalledBy}` : ''}.`);
|
|
212
|
+
return { success: true };
|
|
213
|
+
}
|
|
214
|
+
catch (e) {
|
|
215
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
216
|
+
log.error(e, `Failed to uninstall plugin ${pluginKey}.`);
|
|
217
|
+
return { success: false, error: message };
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
export const getInstalledPluginKeys = async () => {
|
|
221
|
+
const installed = await getInstalledPlugins();
|
|
222
|
+
return Object.keys(installed);
|
|
223
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { eq } from 'drizzle-orm';
|
|
2
|
+
import { allpeepDb } from '../db/index.js';
|
|
3
|
+
import { configs } from '../db/pg/schema/documents.js';
|
|
4
|
+
import { nowIso } from '../db/pg/mappers.js';
|
|
5
|
+
// Single JSONB row keyed by plugin key -> desired enabled state. A missing
|
|
6
|
+
// entry means "no override"; the static `openpeeps.enabled` package.json
|
|
7
|
+
// gate decides. Reuses the generic `configs` table rather than a dedicated
|
|
8
|
+
// one — this is a small, boot-time-read key/value document, not a relation.
|
|
9
|
+
const PLUGIN_STATE_KEY = 'openpeeps-plugin-state';
|
|
10
|
+
export const getPluginStateOverrides = () => allpeepDb().then(async ({ db }) => {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
const rows = await db
|
|
13
|
+
.select()
|
|
14
|
+
.from(configs)
|
|
15
|
+
.where(eq(configs.key, PLUGIN_STATE_KEY))
|
|
16
|
+
.limit(1);
|
|
17
|
+
return (_b = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.body) !== null && _b !== void 0 ? _b : {};
|
|
18
|
+
});
|
|
19
|
+
export const setPluginEnabledOverride = (pluginKey, enabled) => getPluginStateOverrides().then((overrides) => {
|
|
20
|
+
const body = Object.assign(Object.assign({}, overrides), { [pluginKey]: enabled });
|
|
21
|
+
const ts = nowIso();
|
|
22
|
+
return allpeepDb().then(({ db }) => db
|
|
23
|
+
.insert(configs)
|
|
24
|
+
.values({ key: PLUGIN_STATE_KEY, body, createdAt: ts, updatedAt: ts })
|
|
25
|
+
.onConflictDoUpdate({
|
|
26
|
+
target: configs.key,
|
|
27
|
+
set: { body, updatedAt: ts },
|
|
28
|
+
}));
|
|
29
|
+
});
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type { AuthorizationData, PostWithMeta } from '@openpeepshq/common/types';
|
|
2
|
+
import { type PgDb } from '../db';
|
|
3
|
+
export type EventAgendaWindow = 'upcoming' | 'current' | 'past';
|
|
4
|
+
export type EventAgendaOptions = {
|
|
5
|
+
offset?: number;
|
|
6
|
+
limit?: number;
|
|
7
|
+
jamOnly?: boolean;
|
|
8
|
+
mine?: boolean;
|
|
9
|
+
groupId?: string;
|
|
10
|
+
};
|
|
11
|
+
export type EventAgendaQueryArgs = {
|
|
12
|
+
window: EventAgendaWindow;
|
|
13
|
+
now: string;
|
|
14
|
+
offset: number;
|
|
15
|
+
limit: number;
|
|
16
|
+
jamOnly?: boolean;
|
|
17
|
+
mine?: boolean;
|
|
18
|
+
groupId?: string;
|
|
19
|
+
profileId?: string;
|
|
20
|
+
};
|
|
21
|
+
export declare const eventAgendaOccurrenceQuery: (db: Pick<PgDb, "select" | "selectDistinctOn">, args: EventAgendaQueryArgs) => Omit<import("drizzle-orm/pg-core").PgSelectBase<"event_agenda", {
|
|
22
|
+
postId: import("drizzle-orm/pg-core").PgColumn<{
|
|
23
|
+
name: "post_id";
|
|
24
|
+
tableName: "event_agenda";
|
|
25
|
+
dataType: "string";
|
|
26
|
+
columnType: "PgUUID";
|
|
27
|
+
data: string;
|
|
28
|
+
driverParam: string;
|
|
29
|
+
notNull: true;
|
|
30
|
+
hasDefault: false;
|
|
31
|
+
isPrimaryKey: false;
|
|
32
|
+
isAutoincrement: false;
|
|
33
|
+
hasRuntimeDefault: false;
|
|
34
|
+
enumValues: undefined;
|
|
35
|
+
baseColumn: never;
|
|
36
|
+
identity: undefined;
|
|
37
|
+
generated: undefined;
|
|
38
|
+
}, {}, {}>;
|
|
39
|
+
recurrenceId: import("drizzle-orm/pg-core").PgColumn<{
|
|
40
|
+
name: "recurrence_id";
|
|
41
|
+
tableName: "event_agenda";
|
|
42
|
+
dataType: "string";
|
|
43
|
+
columnType: "PgTimestampString";
|
|
44
|
+
data: string;
|
|
45
|
+
driverParam: string;
|
|
46
|
+
notNull: true;
|
|
47
|
+
hasDefault: false;
|
|
48
|
+
isPrimaryKey: false;
|
|
49
|
+
isAutoincrement: false;
|
|
50
|
+
hasRuntimeDefault: false;
|
|
51
|
+
enumValues: undefined;
|
|
52
|
+
baseColumn: never;
|
|
53
|
+
identity: undefined;
|
|
54
|
+
generated: undefined;
|
|
55
|
+
}, {}, {}>;
|
|
56
|
+
start: import("drizzle-orm/pg-core").PgColumn<{
|
|
57
|
+
name: "start";
|
|
58
|
+
tableName: "event_agenda";
|
|
59
|
+
dataType: "string";
|
|
60
|
+
columnType: "PgTimestampString";
|
|
61
|
+
data: string;
|
|
62
|
+
driverParam: string;
|
|
63
|
+
notNull: true;
|
|
64
|
+
hasDefault: false;
|
|
65
|
+
isPrimaryKey: false;
|
|
66
|
+
isAutoincrement: false;
|
|
67
|
+
hasRuntimeDefault: false;
|
|
68
|
+
enumValues: undefined;
|
|
69
|
+
baseColumn: never;
|
|
70
|
+
identity: undefined;
|
|
71
|
+
generated: undefined;
|
|
72
|
+
}, {}, {}>;
|
|
73
|
+
end: import("drizzle-orm/pg-core").PgColumn<{
|
|
74
|
+
name: "end";
|
|
75
|
+
tableName: "event_agenda";
|
|
76
|
+
dataType: "string";
|
|
77
|
+
columnType: "PgTimestampString";
|
|
78
|
+
data: string;
|
|
79
|
+
driverParam: string;
|
|
80
|
+
notNull: false;
|
|
81
|
+
hasDefault: false;
|
|
82
|
+
isPrimaryKey: false;
|
|
83
|
+
isAutoincrement: false;
|
|
84
|
+
hasRuntimeDefault: false;
|
|
85
|
+
enumValues: undefined;
|
|
86
|
+
baseColumn: never;
|
|
87
|
+
identity: undefined;
|
|
88
|
+
generated: undefined;
|
|
89
|
+
}, {}, {}>;
|
|
90
|
+
}, "partial", Record<"event_agenda", "not-null">, false, "limit" | "offset" | "orderBy", {
|
|
91
|
+
postId: string;
|
|
92
|
+
recurrenceId: string;
|
|
93
|
+
start: string;
|
|
94
|
+
end: string | null;
|
|
95
|
+
}[], {
|
|
96
|
+
postId: import("drizzle-orm/pg-core").PgColumn<{
|
|
97
|
+
name: "post_id";
|
|
98
|
+
tableName: "event_agenda";
|
|
99
|
+
dataType: "string";
|
|
100
|
+
columnType: "PgUUID";
|
|
101
|
+
data: string;
|
|
102
|
+
driverParam: string;
|
|
103
|
+
notNull: true;
|
|
104
|
+
hasDefault: false;
|
|
105
|
+
isPrimaryKey: false;
|
|
106
|
+
isAutoincrement: false;
|
|
107
|
+
hasRuntimeDefault: false;
|
|
108
|
+
enumValues: undefined;
|
|
109
|
+
baseColumn: never;
|
|
110
|
+
identity: undefined;
|
|
111
|
+
generated: undefined;
|
|
112
|
+
}, {}, {}>;
|
|
113
|
+
recurrenceId: import("drizzle-orm/pg-core").PgColumn<{
|
|
114
|
+
name: "recurrence_id";
|
|
115
|
+
tableName: "event_agenda";
|
|
116
|
+
dataType: "string";
|
|
117
|
+
columnType: "PgTimestampString";
|
|
118
|
+
data: string;
|
|
119
|
+
driverParam: string;
|
|
120
|
+
notNull: true;
|
|
121
|
+
hasDefault: false;
|
|
122
|
+
isPrimaryKey: false;
|
|
123
|
+
isAutoincrement: false;
|
|
124
|
+
hasRuntimeDefault: false;
|
|
125
|
+
enumValues: undefined;
|
|
126
|
+
baseColumn: never;
|
|
127
|
+
identity: undefined;
|
|
128
|
+
generated: undefined;
|
|
129
|
+
}, {}, {}>;
|
|
130
|
+
start: import("drizzle-orm/pg-core").PgColumn<{
|
|
131
|
+
name: "start";
|
|
132
|
+
tableName: "event_agenda";
|
|
133
|
+
dataType: "string";
|
|
134
|
+
columnType: "PgTimestampString";
|
|
135
|
+
data: string;
|
|
136
|
+
driverParam: string;
|
|
137
|
+
notNull: true;
|
|
138
|
+
hasDefault: false;
|
|
139
|
+
isPrimaryKey: false;
|
|
140
|
+
isAutoincrement: false;
|
|
141
|
+
hasRuntimeDefault: false;
|
|
142
|
+
enumValues: undefined;
|
|
143
|
+
baseColumn: never;
|
|
144
|
+
identity: undefined;
|
|
145
|
+
generated: undefined;
|
|
146
|
+
}, {}, {}>;
|
|
147
|
+
end: import("drizzle-orm/pg-core").PgColumn<{
|
|
148
|
+
name: "end";
|
|
149
|
+
tableName: "event_agenda";
|
|
150
|
+
dataType: "string";
|
|
151
|
+
columnType: "PgTimestampString";
|
|
152
|
+
data: string;
|
|
153
|
+
driverParam: string;
|
|
154
|
+
notNull: false;
|
|
155
|
+
hasDefault: false;
|
|
156
|
+
isPrimaryKey: false;
|
|
157
|
+
isAutoincrement: false;
|
|
158
|
+
hasRuntimeDefault: false;
|
|
159
|
+
enumValues: undefined;
|
|
160
|
+
baseColumn: never;
|
|
161
|
+
identity: undefined;
|
|
162
|
+
generated: undefined;
|
|
163
|
+
}, {}, {}>;
|
|
164
|
+
}>, "limit" | "offset" | "orderBy">;
|
|
165
|
+
export declare const listEventAgenda: (authData: AuthorizationData, window: EventAgendaWindow, { offset, limit, jamOnly, mine, groupId, }?: EventAgendaOptions) => Promise<PostWithMeta[]>;
|