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.
Files changed (210) hide show
  1. package/README.md +117 -81
  2. package/dist/adapt-package-manager.d.ts +3 -0
  3. package/dist/adapt-package-manager.js +118 -0
  4. package/dist/create-project.d.ts +77 -2
  5. package/dist/create-project.js +685 -224
  6. package/dist/db-commands.d.ts +20 -0
  7. package/dist/db-commands.js +75 -0
  8. package/dist/detect-package-manager.d.ts +8 -0
  9. package/dist/detect-package-manager.js +37 -0
  10. package/dist/doctor.d.ts +26 -0
  11. package/dist/doctor.js +232 -0
  12. package/dist/index.d.ts +3 -1
  13. package/dist/index.js +476 -166
  14. package/dist/render-schema.d.ts +3 -0
  15. package/dist/render-schema.js +33 -0
  16. package/dist/resource-slug.d.ts +1 -0
  17. package/dist/resource-slug.js +7 -0
  18. package/dist/runtime-mode.d.ts +16 -0
  19. package/dist/runtime-mode.js +138 -0
  20. package/dist/secrets.d.ts +24 -0
  21. package/dist/secrets.js +93 -0
  22. package/dist/security.d.ts +13 -0
  23. package/dist/security.js +168 -0
  24. package/dist/upgrade.d.ts +10 -0
  25. package/dist/upgrade.js +133 -0
  26. package/dist/validate-name.d.ts +33 -0
  27. package/dist/validate-name.js +206 -0
  28. package/package.json +39 -11
  29. package/template/.dockerignore +15 -0
  30. package/template/.env.production.example +5 -0
  31. package/template/Dockerfile +12 -0
  32. package/template/README.md +23 -3
  33. package/template/apps/admin/app/api/auth/login/route.ts +9 -9
  34. package/template/apps/admin/app/api/auth/logout/route.ts +11 -3
  35. package/template/apps/admin/app/api/auth/oidc/callback/route.ts +19 -0
  36. package/template/apps/admin/app/api/auth/oidc/start/route.ts +11 -0
  37. package/template/apps/admin/app/api/auth/oidc/status/route.ts +6 -0
  38. package/template/apps/admin/app/api/auth/refresh/route.ts +18 -11
  39. package/template/apps/admin/app/api/backend/[...path]/route.ts +48 -0
  40. package/template/apps/admin/app/api-tokens/page.tsx +39 -39
  41. package/template/apps/admin/app/assistant/page.tsx +11 -0
  42. package/template/apps/admin/app/dashboard/page.tsx +45 -462
  43. package/template/apps/admin/app/globals.css +52 -16
  44. package/template/apps/admin/app/layout.tsx +1 -1
  45. package/template/apps/admin/app/login/page.tsx +13 -145
  46. package/template/apps/admin/app/plugins/page.tsx +16 -402
  47. package/template/apps/admin/app/profile/page.tsx +5 -2
  48. package/template/apps/admin/app/settings/page.tsx +14 -265
  49. package/template/apps/admin/components/ai-assistant-widget.tsx +3 -6
  50. package/template/apps/admin/components/app-shell.tsx +25 -373
  51. package/template/apps/admin/components/auth-guard.tsx +8 -28
  52. package/template/apps/admin/components/logo.tsx +1 -30
  53. package/template/apps/admin/components/resource-form.tsx +3 -3
  54. package/template/apps/admin/components/resource-table.tsx +12 -8
  55. package/template/apps/admin/lib/api.ts +45 -107
  56. package/template/apps/admin/lib/resource-table-prefs.ts +1 -57
  57. package/template/apps/admin/lib/server-api.ts +7 -0
  58. package/template/apps/admin/lib/tokens.ts +9 -81
  59. package/template/apps/admin/middleware.ts +9 -50
  60. package/template/apps/admin/next.config.mjs +4 -0
  61. package/template/apps/admin/package.json +2 -1
  62. package/template/apps/admin/public/brand/favicon.svg +4 -1
  63. package/template/apps/admin/tailwind.config.ts +9 -8
  64. package/template/apps/api/package.json +13 -6
  65. package/template/apps/api/src/access/catalog.ts +4 -0
  66. package/template/apps/api/src/admin/admin-ai.controller.ts +15 -125
  67. package/template/apps/api/src/admin/admin-analytics.service.ts +16 -148
  68. package/template/apps/api/src/admin/admin-logs.controller.ts +4 -1
  69. package/template/apps/api/src/admin/admin-plugins.controller.ts +8 -8
  70. package/template/apps/api/src/admin/admin-plugins.service.ts +15 -259
  71. package/template/apps/api/src/admin/admin-resource.service.ts +105 -254
  72. package/template/apps/api/src/admin/admin.controller.ts +17 -4
  73. package/template/apps/api/src/admin/admin.module.ts +2 -2
  74. package/template/apps/api/src/admin/resource-policy.ts +1 -0
  75. package/template/apps/api/src/admin/resource-query.ts +1 -0
  76. package/template/apps/api/src/admin/safe-ai.service.ts +43 -0
  77. package/template/apps/api/src/admin/validate-resource-payload.ts +2 -0
  78. package/template/apps/api/src/auth/auth.controller.ts +4 -2
  79. package/template/apps/api/src/auth/auth.service.ts +68 -83
  80. package/template/apps/api/src/auth/sso-oidc.controller.ts +12 -74
  81. package/template/apps/api/src/auth/sso-oidc.service.ts +51 -268
  82. package/template/apps/api/src/common/api-exception.filter.ts +1 -0
  83. package/template/apps/api/src/common/auth.guard.ts +66 -39
  84. package/template/apps/api/src/common/json-field-codec.ts +138 -0
  85. package/template/apps/api/src/common/prisma.service.ts +12 -7
  86. package/template/apps/api/src/common/request-logging.interceptor.ts +8 -3
  87. package/template/apps/api/src/graphql/graphql.module.ts +14 -1
  88. package/template/apps/api/src/health/health.controller.ts +6 -0
  89. package/template/apps/api/src/main.ts +11 -2
  90. package/template/apps/api/src/plugins/plugin-loader.ts +5 -3
  91. package/template/apps/api/src/resources/commerce.resource.ts +3 -34
  92. package/template/apps/api/src/resources/operations.resource.ts +1 -0
  93. package/template/apps/api/src/store/payment/payment.controller.ts +15 -92
  94. package/template/apps/api/src/store/payment/payment.module.ts +2 -3
  95. package/template/apps/api/src/store/payment/payment.service.ts +121 -227
  96. package/template/apps/api/webpack.config.cjs +2 -1
  97. package/template/apps/web/next.config.mjs +4 -0
  98. package/template/apps/web/public/brand/favicon.svg +4 -1
  99. package/template/compose.yaml +56 -0
  100. package/template/examples/crm-admin/README.md +31 -0
  101. package/template/examples/crm-admin/package.json +17 -0
  102. package/template/examples/crm-admin/prisma/models.fragment.prisma +50 -0
  103. package/template/examples/crm-admin/src/index.ts +7 -0
  104. package/template/examples/crm-admin/src/resources/activities.resource.ts +29 -0
  105. package/template/examples/crm-admin/src/resources/companies.resource.ts +21 -0
  106. package/template/examples/crm-admin/src/resources/contacts.resource.ts +24 -0
  107. package/template/examples/crm-admin/src/resources/deals.resource.ts +30 -0
  108. package/template/examples/crm-admin/tsconfig.json +7 -0
  109. package/template/package.json +8 -1
  110. package/template/packages/admin-client/package.json +18 -0
  111. package/template/packages/admin-client/src/contracts.ts +29 -0
  112. package/template/packages/admin-client/src/index.ts +2 -0
  113. package/template/packages/admin-client/src/preferences.ts +57 -0
  114. package/template/packages/admin-client/tsconfig.json +12 -0
  115. package/template/packages/auth/package.json +1 -1
  116. package/template/packages/brand/site/assets/brand/favicon.svg +4 -1
  117. package/template/packages/brand/src/generate-assets.mjs +17 -186
  118. package/template/packages/core/package.json +1 -1
  119. package/template/packages/mail/package.json +1 -1
  120. package/template/packages/nest/package.json +22 -0
  121. package/template/packages/nest/src/api-exception.filter.ts +23 -0
  122. package/template/packages/nest/src/index.ts +3 -0
  123. package/template/packages/nest/src/resource-policy.ts +64 -0
  124. package/template/packages/nest/src/resource-query.ts +103 -0
  125. package/template/packages/nest/tsconfig.json +12 -0
  126. package/template/packages/notifications/package.json +1 -1
  127. package/template/packages/payments/package.json +1 -1
  128. package/template/packages/permissions/package.json +1 -1
  129. package/template/packages/permissions/src/index.ts +2 -2
  130. package/template/packages/plugin-sdk/package.json +1 -1
  131. package/template/packages/plugin-sdk/src/index.ts +2 -2
  132. package/template/packages/prisma/package.json +21 -0
  133. package/template/packages/prisma/schema/ai.prisma +36 -0
  134. package/template/packages/prisma/schema/audit.prisma +13 -0
  135. package/template/packages/prisma/schema/commerce.prisma +79 -0
  136. package/template/packages/prisma/schema/content.prisma +27 -0
  137. package/template/packages/prisma/schema/core.prisma +106 -0
  138. package/template/packages/prisma/schema/header.prisma +8 -0
  139. package/template/packages/prisma/schema/jobs.prisma +9 -0
  140. package/template/packages/prisma/schema/media.prisma +9 -0
  141. package/template/packages/prisma/schema/modules.json +47 -0
  142. package/template/packages/prisma/schema/notifications.prisma +9 -0
  143. package/template/packages/prisma/schema/settings.prisma +8 -0
  144. package/template/packages/prisma/schema/tokens.prisma +10 -0
  145. package/template/packages/prisma/src/index.d.ts +12 -0
  146. package/template/packages/prisma/src/index.mjs +138 -0
  147. package/template/packages/queue/package.json +1 -1
  148. package/template/packages/resource/package.json +1 -1
  149. package/template/packages/resource/src/index.ts +1 -0
  150. package/template/packages/storage/package.json +1 -1
  151. package/template/packages/storage/src/index.ts +37 -0
  152. package/template/prisma/migrations/20260713120000_add_user_oidc_key_and_category_order/migration.sql +11 -0
  153. package/template/prisma/migrations/20261126130000_add_sessions/migration.sql +26 -0
  154. package/template/prisma/migrations/20261126140000_api_token_hash/migration.sql +3 -0
  155. package/template/prisma/migrations/20261126150000_payment_idempotency/migration.sql +6 -0
  156. package/template/prisma/schema.prisma +82 -54
  157. package/template/prisma/seed.ts +14 -38
  158. package/template/runtime-versions.json +15 -0
  159. package/template/scripts/db-init.mjs +33 -0
  160. package/template/scripts/install-crm.mjs +50 -0
  161. package/template/scripts/migrate-existing.mjs +65 -0
  162. package/template/scripts/schema.mjs +48 -0
  163. package/template/tsconfig.base.json +23 -5
  164. package/LICENSE +0 -21
  165. package/dist/create-project.test.d.ts +0 -1
  166. package/dist/create-project.test.js +0 -99
  167. package/dist/index.test.d.ts +0 -1
  168. package/dist/index.test.js +0 -7
  169. package/dist/resource-slug.test.d.ts +0 -1
  170. package/dist/resource-slug.test.js +0 -9
  171. package/template/apps/admin/.storybook/main.ts +0 -12
  172. package/template/apps/admin/.storybook/preview.ts +0 -10
  173. package/template/apps/admin/app/login/page.test.tsx +0 -18
  174. package/template/apps/admin/components/auth-guard.test.tsx +0 -55
  175. package/template/apps/admin/components/logo.stories.tsx +0 -24
  176. package/template/apps/admin/lib/api.test.ts +0 -118
  177. package/template/apps/admin/lib/auth-flow.e2e.test.ts +0 -79
  178. package/template/apps/admin/vitest.config.ts +0 -7
  179. package/template/apps/api/src/access/derive-permissions.test.ts +0 -26
  180. package/template/apps/api/src/admin/admin-resource.service.test.ts +0 -118
  181. package/template/apps/api/src/admin/validate-resource-payload.test.ts +0 -44
  182. package/template/apps/api/src/app.module.test.ts +0 -12
  183. package/template/apps/api/src/auth/auth.service.test.ts +0 -78
  184. package/template/apps/api/src/auth/sso-oidc.service.test.ts +0 -84
  185. package/template/apps/api/src/common/auth.guard.test.ts +0 -62
  186. package/template/apps/api/src/common/casl-ability.factory.test.ts +0 -33
  187. package/template/apps/api/src/common/request-logging.interceptor.test.ts +0 -39
  188. package/template/apps/api/src/graphql/admin-resources.resolver.test.ts +0 -45
  189. package/template/apps/api/src/graphql/ensure-gql-paramtypes.test.ts +0 -44
  190. package/template/apps/api/src/graphql/graphql-schema.test.ts +0 -26
  191. package/template/apps/api/src/plugins/manifest.schema.test.ts +0 -36
  192. package/template/apps/api/src/plugins/plugin-runtime.test.ts +0 -24
  193. package/template/apps/api/src/queue/queue.service.test.ts +0 -33
  194. package/template/apps/api/src/resources/resource-hooks.registry.test.ts +0 -72
  195. package/template/apps/api/vitest.config.ts +0 -21
  196. package/template/apps/web/lib/seo.test.ts +0 -41
  197. package/template/apps/web/vitest.config.ts +0 -19
  198. package/template/packages/auth/src/index.test.ts +0 -10
  199. package/template/packages/brand/src/index.test.ts +0 -9
  200. package/template/packages/core/src/index.test.ts +0 -27
  201. package/template/packages/core/vitest.config.ts +0 -9
  202. package/template/packages/mail/src/index.test.ts +0 -23
  203. package/template/packages/notifications/src/index.test.ts +0 -9
  204. package/template/packages/permissions/src/blueprints.test.ts +0 -62
  205. package/template/packages/permissions/src/index.test.ts +0 -34
  206. package/template/packages/plugin-sdk/src/sdk.test.ts +0 -13
  207. package/template/packages/plugin-sdk/vitest.config.ts +0 -5
  208. package/template/packages/queue/src/index.test.ts +0 -12
  209. package/template/packages/resource/src/index.test.ts +0 -196
  210. package/template/packages/storage/src/index.test.ts +0 -10
@@ -1,286 +1,42 @@
1
- import { execFile } from "node:child_process";
2
- import { existsSync, readFileSync, writeFileSync } from "node:fs";
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
- applyManifestPluginEntry,
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 emptyManifest();
13
+ if (!existsSync(path)) return { version: 1, plugins: [] };
45
14
  try {
46
- const raw = JSON.parse(readFileSync(path, "utf8")) as unknown;
47
- const parsed = pluginManifestSchema.safeParse(raw);
48
- if (!parsed.success) {
49
- log.warn(`Invalid manifest at ${path}, treating as empty`);
50
- return emptyManifest();
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
- .getAdminUiExtensions()
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
  }