openadminjs 0.1.24 → 0.3.0-rc.1
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/README.md +117 -81
- package/dist/adapt-package-manager.d.ts +3 -0
- package/dist/adapt-package-manager.js +118 -0
- package/dist/create-project.d.ts +77 -2
- package/dist/create-project.js +685 -224
- package/dist/db-commands.d.ts +20 -0
- package/dist/db-commands.js +75 -0
- package/dist/detect-package-manager.d.ts +8 -0
- package/dist/detect-package-manager.js +37 -0
- package/dist/doctor.d.ts +26 -0
- package/dist/doctor.js +232 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +476 -166
- package/dist/render-schema.d.ts +3 -0
- package/dist/render-schema.js +33 -0
- package/dist/resource-slug.d.ts +1 -0
- package/dist/resource-slug.js +7 -0
- package/dist/runtime-mode.d.ts +16 -0
- package/dist/runtime-mode.js +138 -0
- package/dist/secrets.d.ts +24 -0
- package/dist/secrets.js +93 -0
- package/dist/security.d.ts +13 -0
- package/dist/security.js +168 -0
- package/dist/upgrade.d.ts +10 -0
- package/dist/upgrade.js +133 -0
- package/dist/validate-name.d.ts +33 -0
- package/dist/validate-name.js +206 -0
- package/package.json +39 -11
- package/template/.dockerignore +15 -0
- package/template/.env.production.example +5 -0
- package/template/Dockerfile +12 -0
- package/template/README.md +23 -3
- package/template/apps/admin/app/api/auth/login/route.ts +9 -9
- package/template/apps/admin/app/api/auth/logout/route.ts +11 -3
- package/template/apps/admin/app/api/auth/oidc/callback/route.ts +19 -0
- package/template/apps/admin/app/api/auth/oidc/start/route.ts +11 -0
- package/template/apps/admin/app/api/auth/oidc/status/route.ts +6 -0
- package/template/apps/admin/app/api/auth/refresh/route.ts +18 -11
- package/template/apps/admin/app/api/backend/[...path]/route.ts +48 -0
- package/template/apps/admin/app/api-tokens/page.tsx +39 -39
- package/template/apps/admin/app/assistant/page.tsx +11 -0
- package/template/apps/admin/app/dashboard/page.tsx +45 -462
- package/template/apps/admin/app/globals.css +52 -16
- package/template/apps/admin/app/layout.tsx +1 -1
- package/template/apps/admin/app/login/page.tsx +13 -145
- package/template/apps/admin/app/plugins/page.tsx +16 -402
- package/template/apps/admin/app/profile/page.tsx +5 -2
- package/template/apps/admin/app/settings/page.tsx +14 -265
- package/template/apps/admin/components/ai-assistant-widget.tsx +3 -6
- package/template/apps/admin/components/app-shell.tsx +25 -373
- package/template/apps/admin/components/auth-guard.tsx +8 -28
- package/template/apps/admin/components/logo.tsx +1 -30
- package/template/apps/admin/components/resource-form.tsx +3 -3
- package/template/apps/admin/components/resource-table.tsx +12 -8
- package/template/apps/admin/lib/api.ts +45 -107
- package/template/apps/admin/lib/resource-table-prefs.ts +1 -57
- package/template/apps/admin/lib/server-api.ts +7 -0
- package/template/apps/admin/lib/tokens.ts +9 -81
- package/template/apps/admin/middleware.ts +9 -50
- package/template/apps/admin/next.config.mjs +4 -0
- package/template/apps/admin/package.json +2 -1
- package/template/apps/admin/public/brand/favicon.svg +4 -1
- package/template/apps/admin/tailwind.config.ts +9 -8
- package/template/apps/api/package.json +13 -6
- package/template/apps/api/src/access/catalog.ts +4 -0
- package/template/apps/api/src/admin/admin-ai.controller.ts +15 -125
- package/template/apps/api/src/admin/admin-analytics.service.ts +16 -148
- package/template/apps/api/src/admin/admin-logs.controller.ts +4 -1
- package/template/apps/api/src/admin/admin-plugins.controller.ts +8 -8
- package/template/apps/api/src/admin/admin-plugins.service.ts +15 -259
- package/template/apps/api/src/admin/admin-resource.service.ts +105 -254
- package/template/apps/api/src/admin/admin.controller.ts +17 -4
- package/template/apps/api/src/admin/admin.module.ts +2 -2
- package/template/apps/api/src/admin/resource-policy.ts +1 -0
- package/template/apps/api/src/admin/resource-query.ts +1 -0
- package/template/apps/api/src/admin/safe-ai.service.ts +43 -0
- package/template/apps/api/src/admin/validate-resource-payload.ts +2 -0
- package/template/apps/api/src/auth/auth.controller.ts +4 -2
- package/template/apps/api/src/auth/auth.service.ts +68 -83
- package/template/apps/api/src/auth/sso-oidc.controller.ts +12 -74
- package/template/apps/api/src/auth/sso-oidc.service.ts +51 -268
- package/template/apps/api/src/common/api-exception.filter.ts +1 -0
- package/template/apps/api/src/common/auth.guard.ts +66 -39
- package/template/apps/api/src/common/json-field-codec.ts +138 -0
- package/template/apps/api/src/common/prisma.service.ts +12 -7
- package/template/apps/api/src/common/request-logging.interceptor.ts +8 -3
- package/template/apps/api/src/graphql/graphql.module.ts +14 -1
- package/template/apps/api/src/health/health.controller.ts +6 -0
- package/template/apps/api/src/main.ts +11 -2
- package/template/apps/api/src/plugins/plugin-loader.ts +5 -3
- package/template/apps/api/src/resources/commerce.resource.ts +3 -34
- package/template/apps/api/src/resources/operations.resource.ts +1 -0
- package/template/apps/api/src/store/payment/payment.controller.ts +15 -92
- package/template/apps/api/src/store/payment/payment.module.ts +2 -3
- package/template/apps/api/src/store/payment/payment.service.ts +121 -227
- package/template/apps/api/webpack.config.cjs +2 -1
- package/template/apps/web/next.config.mjs +4 -0
- package/template/apps/web/public/brand/favicon.svg +4 -1
- package/template/compose.yaml +56 -0
- package/template/examples/crm-admin/README.md +31 -0
- package/template/examples/crm-admin/package.json +17 -0
- package/template/examples/crm-admin/prisma/models.fragment.prisma +50 -0
- package/template/examples/crm-admin/src/index.ts +7 -0
- package/template/examples/crm-admin/src/resources/activities.resource.ts +29 -0
- package/template/examples/crm-admin/src/resources/companies.resource.ts +21 -0
- package/template/examples/crm-admin/src/resources/contacts.resource.ts +24 -0
- package/template/examples/crm-admin/src/resources/deals.resource.ts +30 -0
- package/template/examples/crm-admin/tsconfig.json +7 -0
- package/template/package.json +8 -1
- package/template/packages/admin-client/package.json +18 -0
- package/template/packages/admin-client/src/contracts.ts +29 -0
- package/template/packages/admin-client/src/index.ts +2 -0
- package/template/packages/admin-client/src/preferences.ts +57 -0
- package/template/packages/admin-client/tsconfig.json +12 -0
- package/template/packages/auth/package.json +1 -1
- package/template/packages/brand/site/assets/brand/favicon.svg +4 -1
- package/template/packages/brand/src/generate-assets.mjs +17 -186
- package/template/packages/core/package.json +1 -1
- package/template/packages/mail/package.json +1 -1
- package/template/packages/nest/package.json +22 -0
- package/template/packages/nest/src/api-exception.filter.ts +23 -0
- package/template/packages/nest/src/index.ts +3 -0
- package/template/packages/nest/src/resource-policy.ts +64 -0
- package/template/packages/nest/src/resource-query.ts +103 -0
- package/template/packages/nest/tsconfig.json +12 -0
- package/template/packages/notifications/package.json +1 -1
- package/template/packages/payments/package.json +1 -1
- package/template/packages/permissions/package.json +1 -1
- package/template/packages/permissions/src/index.ts +2 -2
- package/template/packages/plugin-sdk/package.json +1 -1
- package/template/packages/plugin-sdk/src/index.ts +2 -2
- package/template/packages/prisma/package.json +21 -0
- package/template/packages/prisma/schema/ai.prisma +36 -0
- package/template/packages/prisma/schema/audit.prisma +13 -0
- package/template/packages/prisma/schema/commerce.prisma +79 -0
- package/template/packages/prisma/schema/content.prisma +27 -0
- package/template/packages/prisma/schema/core.prisma +106 -0
- package/template/packages/prisma/schema/header.prisma +8 -0
- package/template/packages/prisma/schema/jobs.prisma +9 -0
- package/template/packages/prisma/schema/media.prisma +9 -0
- package/template/packages/prisma/schema/modules.json +47 -0
- package/template/packages/prisma/schema/notifications.prisma +9 -0
- package/template/packages/prisma/schema/settings.prisma +8 -0
- package/template/packages/prisma/schema/tokens.prisma +10 -0
- package/template/packages/prisma/src/index.d.ts +12 -0
- package/template/packages/prisma/src/index.mjs +138 -0
- package/template/packages/queue/package.json +1 -1
- package/template/packages/resource/package.json +1 -1
- package/template/packages/resource/src/index.ts +1 -0
- package/template/packages/storage/package.json +1 -1
- package/template/packages/storage/src/index.ts +37 -0
- package/template/prisma/migrations/20260713120000_add_user_oidc_key_and_category_order/migration.sql +11 -0
- package/template/prisma/migrations/20261126130000_add_sessions/migration.sql +26 -0
- package/template/prisma/migrations/20261126140000_api_token_hash/migration.sql +3 -0
- package/template/prisma/migrations/20261126150000_payment_idempotency/migration.sql +6 -0
- package/template/prisma/schema.prisma +82 -54
- package/template/prisma/seed.ts +14 -38
- package/template/runtime-versions.json +15 -0
- package/template/scripts/db-init.mjs +33 -0
- package/template/scripts/install-crm.mjs +50 -0
- package/template/scripts/migrate-existing.mjs +65 -0
- package/template/scripts/schema.mjs +48 -0
- package/template/tsconfig.base.json +23 -5
- package/LICENSE +0 -21
- package/dist/create-project.test.d.ts +0 -1
- package/dist/create-project.test.js +0 -99
- package/dist/index.test.d.ts +0 -1
- package/dist/index.test.js +0 -7
- package/dist/resource-slug.test.d.ts +0 -1
- package/dist/resource-slug.test.js +0 -9
- package/template/apps/admin/.storybook/main.ts +0 -12
- package/template/apps/admin/.storybook/preview.ts +0 -10
- package/template/apps/admin/app/login/page.test.tsx +0 -18
- package/template/apps/admin/components/auth-guard.test.tsx +0 -55
- package/template/apps/admin/components/logo.stories.tsx +0 -24
- package/template/apps/admin/lib/api.test.ts +0 -118
- package/template/apps/admin/lib/auth-flow.e2e.test.ts +0 -79
- package/template/apps/admin/vitest.config.ts +0 -7
- package/template/apps/api/src/access/derive-permissions.test.ts +0 -26
- package/template/apps/api/src/admin/admin-resource.service.test.ts +0 -118
- package/template/apps/api/src/admin/validate-resource-payload.test.ts +0 -44
- package/template/apps/api/src/app.module.test.ts +0 -12
- package/template/apps/api/src/auth/auth.service.test.ts +0 -78
- package/template/apps/api/src/auth/sso-oidc.service.test.ts +0 -84
- package/template/apps/api/src/common/auth.guard.test.ts +0 -62
- package/template/apps/api/src/common/casl-ability.factory.test.ts +0 -33
- package/template/apps/api/src/common/request-logging.interceptor.test.ts +0 -39
- package/template/apps/api/src/graphql/admin-resources.resolver.test.ts +0 -45
- package/template/apps/api/src/graphql/ensure-gql-paramtypes.test.ts +0 -44
- package/template/apps/api/src/graphql/graphql-schema.test.ts +0 -26
- package/template/apps/api/src/plugins/manifest.schema.test.ts +0 -36
- package/template/apps/api/src/plugins/plugin-runtime.test.ts +0 -24
- package/template/apps/api/src/queue/queue.service.test.ts +0 -33
- package/template/apps/api/src/resources/resource-hooks.registry.test.ts +0 -72
- package/template/apps/api/vitest.config.ts +0 -21
- package/template/apps/web/lib/seo.test.ts +0 -41
- package/template/apps/web/vitest.config.ts +0 -19
- package/template/packages/auth/src/index.test.ts +0 -10
- package/template/packages/brand/src/index.test.ts +0 -9
- package/template/packages/core/src/index.test.ts +0 -27
- package/template/packages/core/vitest.config.ts +0 -9
- package/template/packages/mail/src/index.test.ts +0 -23
- package/template/packages/notifications/src/index.test.ts +0 -9
- package/template/packages/permissions/src/blueprints.test.ts +0 -62
- package/template/packages/permissions/src/index.test.ts +0 -34
- package/template/packages/plugin-sdk/src/sdk.test.ts +0 -13
- package/template/packages/plugin-sdk/vitest.config.ts +0 -5
- package/template/packages/queue/src/index.test.ts +0 -12
- package/template/packages/resource/src/index.test.ts +0 -196
- package/template/packages/storage/src/index.test.ts +0 -10
|
@@ -1,286 +1,42 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { dirname, join, resolve } from "node:path";
|
|
4
|
-
import { promisify } from "node:util";
|
|
5
|
-
import { fileURLToPath } from "node:url";
|
|
6
|
-
import { BadRequestException, Injectable, InternalServerErrorException, Logger } from "@nestjs/common";
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { Injectable, Logger } from "@nestjs/common";
|
|
7
3
|
import { bundledOpenAdminPlugins } from "../plugins/bundled/registry";
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
invalidateNpmPluginMainModule,
|
|
11
|
-
removeManifestPluginHooks
|
|
12
|
-
} from "../plugins/plugin-loader";
|
|
13
|
-
import { defaultWritableManifestPath, resolveWritableManifestPath } from "../plugins/manifest-path";
|
|
14
|
-
import {
|
|
15
|
-
pluginManifestEntrySchema,
|
|
16
|
-
pluginManifestSchema,
|
|
17
|
-
type PluginManifest,
|
|
18
|
-
type PluginManifestEntry
|
|
19
|
-
} from "../plugins/manifest.schema";
|
|
4
|
+
import { resolveWritableManifestPath } from "../plugins/manifest-path";
|
|
5
|
+
import { pluginManifestSchema, type PluginManifest } from "../plugins/manifest.schema";
|
|
20
6
|
import { pluginRuntime } from "../plugins/plugin-runtime";
|
|
21
7
|
|
|
22
|
-
const execFileAsync = promisify(execFile);
|
|
23
|
-
|
|
24
8
|
const log = new Logger("AdminPlugins");
|
|
25
|
-
|
|
26
|
-
const emptyManifest = (): PluginManifest => ({ version: 1, plugins: [] });
|
|
27
|
-
|
|
28
|
-
function sleep(ms: number): Promise<void> {
|
|
29
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function isModuleNotFoundError(e: unknown): boolean {
|
|
33
|
-
if (!e || typeof e !== "object") return false;
|
|
34
|
-
const err = e as NodeJS.ErrnoException & { code?: string };
|
|
35
|
-
if (err.code === "MODULE_NOT_FOUND") return true;
|
|
36
|
-
const msg = typeof (e as Error).message === "string" ? (e as Error).message : "";
|
|
37
|
-
return msg.includes("Cannot find module") || msg.includes("MODULE_NOT_FOUND");
|
|
38
|
-
}
|
|
39
|
-
|
|
40
9
|
@Injectable()
|
|
41
10
|
export class AdminPluginsService {
|
|
42
11
|
readManifestOrEmpty(): PluginManifest {
|
|
43
12
|
const path = resolveWritableManifestPath();
|
|
44
|
-
if (!existsSync(path)) return
|
|
13
|
+
if (!existsSync(path)) return { version: 1, plugins: [] };
|
|
45
14
|
try {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
return parsed.data;
|
|
53
|
-
} catch {
|
|
54
|
-
return emptyManifest();
|
|
55
|
-
}
|
|
15
|
+
const result = pluginManifestSchema.safeParse(JSON.parse(readFileSync(path, "utf8")));
|
|
16
|
+
if (result.success) return result.data;
|
|
17
|
+
} catch { /* report a safe diagnostic */ }
|
|
18
|
+
log.warn("Invalid plugin manifest");
|
|
19
|
+
return { version: 1, plugins: [] };
|
|
56
20
|
}
|
|
57
21
|
|
|
58
22
|
getState() {
|
|
59
|
-
const path = existsSync(resolveWritableManifestPath())
|
|
60
|
-
? resolveWritableManifestPath()
|
|
61
|
-
: defaultWritableManifestPath();
|
|
62
23
|
const manifest = this.readManifestOrEmpty();
|
|
63
24
|
return {
|
|
64
|
-
manifestPath: path,
|
|
65
25
|
bundledAvailable: Object.keys(bundledOpenAdminPlugins),
|
|
66
|
-
plugins: manifest.plugins,
|
|
26
|
+
plugins: manifest.plugins.map(({ id, enabled, bundled, package: pkg, trustMode, capabilities }) => ({ id, enabled, bundled, package: pkg, trustMode, capabilities })),
|
|
67
27
|
runtime: {
|
|
68
28
|
adminUiExtensions: pluginRuntime.getAdminUiExtensions().length,
|
|
69
29
|
jobs: pluginRuntime.getJobs().length,
|
|
70
30
|
apiHooks: pluginRuntime.getApiHooks().length,
|
|
71
31
|
mediaHooks: pluginRuntime.getMediaHooks().length,
|
|
72
32
|
seoHooks: pluginRuntime.getSeoHooks().length
|
|
73
|
-
}
|
|
33
|
+
},
|
|
34
|
+
management: "deployment-only"
|
|
74
35
|
};
|
|
75
36
|
}
|
|
76
37
|
|
|
77
38
|
getDashboardWidgets() {
|
|
78
|
-
return pluginRuntime
|
|
79
|
-
.
|
|
80
|
-
.filter((item) => item.kind === "widget")
|
|
81
|
-
.map((item) => ({
|
|
82
|
-
id: item.id,
|
|
83
|
-
title: item.title,
|
|
84
|
-
config: item.config ?? {}
|
|
85
|
-
}));
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
private writeManifest(manifest: PluginManifest) {
|
|
89
|
-
const path = resolveWritableManifestPath();
|
|
90
|
-
const parsed = pluginManifestSchema.safeParse(manifest);
|
|
91
|
-
if (!parsed.success) {
|
|
92
|
-
throw new BadRequestException(parsed.error.message);
|
|
93
|
-
}
|
|
94
|
-
writeFileSync(path, `${JSON.stringify(parsed.data, null, 2)}\n`, "utf8");
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
async add(dto: {
|
|
98
|
-
id: string;
|
|
99
|
-
bundled?: string;
|
|
100
|
-
package?: string;
|
|
101
|
-
enabled?: boolean;
|
|
102
|
-
config?: Record<string, unknown>;
|
|
103
|
-
trustMode?: "trusted" | "sandboxed";
|
|
104
|
-
capabilities?: PluginManifestEntry["capabilities"];
|
|
105
|
-
runPnpmInstall?: boolean;
|
|
106
|
-
}) {
|
|
107
|
-
const hasBundled = Boolean(dto.bundled);
|
|
108
|
-
const hasPackage = Boolean(dto.package);
|
|
109
|
-
if (hasBundled === hasPackage) {
|
|
110
|
-
throw new BadRequestException("Provide exactly one of: bundled or package");
|
|
111
|
-
}
|
|
112
|
-
if (dto.bundled && !bundledOpenAdminPlugins[dto.bundled]) {
|
|
113
|
-
throw new BadRequestException(
|
|
114
|
-
`Unknown bundled plugin "${dto.bundled}". Available: ${Object.keys(bundledOpenAdminPlugins).join(", ")}`
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const manifest = this.readManifestOrEmpty();
|
|
119
|
-
if (manifest.plugins.some((p) => p.id === dto.id)) {
|
|
120
|
-
throw new BadRequestException(`Plugin id already exists: ${dto.id}`);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const entry = {
|
|
124
|
-
id: dto.id,
|
|
125
|
-
enabled: dto.enabled ?? true,
|
|
126
|
-
...(dto.bundled ? { bundled: dto.bundled } : { package: dto.package! }),
|
|
127
|
-
config: dto.config ?? {},
|
|
128
|
-
trustMode: dto.trustMode ?? "trusted",
|
|
129
|
-
capabilities: dto.capabilities ?? []
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
const entryParsed = pluginManifestEntrySchema.safeParse(entry);
|
|
133
|
-
if (!entryParsed.success) {
|
|
134
|
-
throw new BadRequestException(entryParsed.error.message);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
manifest.plugins.push(entryParsed.data);
|
|
138
|
-
this.writeManifest(manifest);
|
|
139
|
-
|
|
140
|
-
let pnpmMessage: string | undefined;
|
|
141
|
-
if (dto.package) {
|
|
142
|
-
const allowPnpm =
|
|
143
|
-
process.env.NODE_ENV !== "production"
|
|
144
|
-
? dto.runPnpmInstall !== false
|
|
145
|
-
: dto.runPnpmInstall === true && process.env.OPENADMIN_PLUGIN_PNPM_INSTALL === "1";
|
|
146
|
-
if (allowPnpm) {
|
|
147
|
-
pnpmMessage = await this.runPnpmAdd(dto.package);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
try {
|
|
152
|
-
if (entryParsed.data.enabled !== false) {
|
|
153
|
-
await this.applyEntryRuntime(entryParsed.data, { afterPnpm: Boolean(pnpmMessage) });
|
|
154
|
-
}
|
|
155
|
-
} catch (e) {
|
|
156
|
-
manifest.plugins = manifest.plugins.filter((p) => p.id !== dto.id);
|
|
157
|
-
this.writeManifest(manifest);
|
|
158
|
-
throw new BadRequestException(
|
|
159
|
-
`Plugin was not activated: ${(e as Error).message}. Manifest entry was rolled back.`
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return {
|
|
164
|
-
ok: true as const,
|
|
165
|
-
restartRequired: false as const,
|
|
166
|
-
pnpm: pnpmMessage
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
async patch(
|
|
171
|
-
id: string,
|
|
172
|
-
dto: {
|
|
173
|
-
enabled?: boolean;
|
|
174
|
-
config?: Record<string, unknown>;
|
|
175
|
-
trustMode?: "trusted" | "sandboxed";
|
|
176
|
-
capabilities?: PluginManifestEntry["capabilities"];
|
|
177
|
-
}
|
|
178
|
-
) {
|
|
179
|
-
const manifest = this.readManifestOrEmpty();
|
|
180
|
-
const idx = manifest.plugins.findIndex((p) => p.id === id);
|
|
181
|
-
if (idx === -1) {
|
|
182
|
-
throw new BadRequestException(`Plugin not found: ${id}`);
|
|
183
|
-
}
|
|
184
|
-
const cur = { ...manifest.plugins[idx]! };
|
|
185
|
-
if (dto.enabled !== undefined) cur.enabled = dto.enabled;
|
|
186
|
-
if (dto.config !== undefined) cur.config = dto.config;
|
|
187
|
-
if (dto.trustMode !== undefined) cur.trustMode = dto.trustMode;
|
|
188
|
-
if (dto.capabilities !== undefined) cur.capabilities = dto.capabilities;
|
|
189
|
-
|
|
190
|
-
const entryParsed = pluginManifestEntrySchema.safeParse(cur);
|
|
191
|
-
if (!entryParsed.success) {
|
|
192
|
-
throw new BadRequestException(entryParsed.error.message);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
manifest.plugins[idx] = entryParsed.data;
|
|
196
|
-
this.writeManifest(manifest);
|
|
197
|
-
|
|
198
|
-
try {
|
|
199
|
-
removeManifestPluginHooks(id);
|
|
200
|
-
if (entryParsed.data.enabled !== false) {
|
|
201
|
-
await this.applyEntryRuntime(entryParsed.data, { afterPnpm: false });
|
|
202
|
-
}
|
|
203
|
-
} catch (e) {
|
|
204
|
-
throw new InternalServerErrorException(
|
|
205
|
-
`Manifest saved but runtime sync failed: ${(e as Error).message}. Try toggling the plugin off and on, or restart the API.`
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return { ok: true as const, restartRequired: false as const };
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
remove(id: string) {
|
|
213
|
-
const manifest = this.readManifestOrEmpty();
|
|
214
|
-
const next = manifest.plugins.filter((p) => p.id !== id);
|
|
215
|
-
if (next.length === manifest.plugins.length) {
|
|
216
|
-
throw new BadRequestException(`Plugin not found: ${id}`);
|
|
217
|
-
}
|
|
218
|
-
manifest.plugins = next;
|
|
219
|
-
this.writeManifest(manifest);
|
|
220
|
-
removeManifestPluginHooks(id);
|
|
221
|
-
return { ok: true as const, restartRequired: false as const };
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
private async runPnpmAdd(packageName: string): Promise<string> {
|
|
225
|
-
const repoRoot = findPnpmWorkspaceRoot();
|
|
226
|
-
try {
|
|
227
|
-
const { stdout, stderr } = await execFileAsync(
|
|
228
|
-
"pnpm",
|
|
229
|
-
["add", packageName, "--filter", "@openadminjs/api"],
|
|
230
|
-
{
|
|
231
|
-
cwd: repoRoot,
|
|
232
|
-
timeout: 180_000,
|
|
233
|
-
maxBuffer: 10 * 1024 * 1024,
|
|
234
|
-
env: process.env as NodeJS.ProcessEnv
|
|
235
|
-
}
|
|
236
|
-
);
|
|
237
|
-
const out = [stdout, stderr].filter(Boolean).join("\n").trim();
|
|
238
|
-
return out || "pnpm add completed";
|
|
239
|
-
} catch (e) {
|
|
240
|
-
const err = e as Error & { stderr?: string };
|
|
241
|
-
log.error(err.message);
|
|
242
|
-
throw new InternalServerErrorException(
|
|
243
|
-
`pnpm add failed: ${err.stderr ?? err.message}. Install the package in @openadminjs/api, then add the plugin again from the admin.`
|
|
244
|
-
);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* Load plugin hooks in the running process. Retries on MODULE_NOT_FOUND so `pnpm add` can settle on disk.
|
|
250
|
-
* No full app restart: Node resolves a package the first time it is `require`d after it appears under node_modules.
|
|
251
|
-
*/
|
|
252
|
-
private async applyEntryRuntime(entry: PluginManifestEntry, opts: { afterPnpm: boolean }): Promise<void> {
|
|
253
|
-
const attempts = entry.package ? (opts.afterPnpm ? 12 : 6) : 1;
|
|
254
|
-
let last: Error | undefined;
|
|
255
|
-
for (let i = 0; i < attempts; i++) {
|
|
256
|
-
if (entry.package) {
|
|
257
|
-
invalidateNpmPluginMainModule(entry.package);
|
|
258
|
-
}
|
|
259
|
-
try {
|
|
260
|
-
await applyManifestPluginEntry(entry);
|
|
261
|
-
return;
|
|
262
|
-
} catch (e) {
|
|
263
|
-
last = e instanceof Error ? e : new Error(String(e));
|
|
264
|
-
const retryable = entry.package && isModuleNotFoundError(last);
|
|
265
|
-
if (!retryable || i === attempts - 1) {
|
|
266
|
-
throw last;
|
|
267
|
-
}
|
|
268
|
-
const delay = 120 + i * 100;
|
|
269
|
-
log.warn(`Plugin ${entry.id} not yet resolvable (${last.message}), retry in ${delay}ms (${i + 1}/${attempts})`);
|
|
270
|
-
await sleep(delay);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
throw last ?? new Error("applyEntryRuntime failed");
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
function findPnpmWorkspaceRoot(): string {
|
|
278
|
-
let dir = resolve(dirname(fileURLToPath(import.meta.url)), "..", "..");
|
|
279
|
-
for (let i = 0; i < 12; i++) {
|
|
280
|
-
if (existsSync(join(dir, "pnpm-workspace.yaml"))) return dir;
|
|
281
|
-
const parent = dirname(dir);
|
|
282
|
-
if (parent === dir) break;
|
|
283
|
-
dir = parent;
|
|
39
|
+
return pluginRuntime.getAdminUiExtensions().filter(item => item.kind === "widget")
|
|
40
|
+
.map(item => ({ id: item.id, title: item.title, config: item.config ?? {} }));
|
|
284
41
|
}
|
|
285
|
-
throw new InternalServerErrorException("Could not find pnpm-workspace.yaml — run pnpm from the monorepo root");
|
|
286
42
|
}
|