openadminjs 0.1.2 → 0.1.4

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 (34) hide show
  1. package/README.md +40 -88
  2. package/apps/admin/app/plugins/page.tsx +60 -1
  3. package/apps/api/plugins.manifest.example.json +12 -0
  4. package/apps/api/src/admin/admin-ai.service.ts +36 -3
  5. package/apps/api/src/admin/admin-plugins.service.ts +18 -4
  6. package/apps/api/src/admin/dto/plugins.dto.ts +19 -1
  7. package/apps/api/src/app.module.ts +9 -1
  8. package/apps/api/src/plugins/bootstrap.ts +2 -2
  9. package/apps/api/src/plugins/bundled/admin-widget.plugin.ts +25 -0
  10. package/apps/api/src/plugins/bundled/image-optimizer.plugin.ts +22 -0
  11. package/apps/api/src/plugins/bundled/registry.ts +7 -1
  12. package/apps/api/src/plugins/bundled/seo.plugin.ts +25 -0
  13. package/apps/api/src/plugins/manifest.schema.test.ts +9 -1
  14. package/apps/api/src/plugins/manifest.schema.ts +20 -0
  15. package/apps/api/src/plugins/plugin-api.interceptor.ts +47 -0
  16. package/apps/api/src/plugins/plugin-loader.ts +34 -9
  17. package/apps/api/src/plugins/plugin-runtime.test.ts +24 -0
  18. package/apps/api/src/plugins/plugin-runtime.ts +85 -0
  19. package/apps/api/src/resources/resource-hooks.runner.ts +13 -6
  20. package/examples/README.md +2 -2
  21. package/examples/basic-admin/README.md +1 -1
  22. package/package.json +1 -1
  23. package/packages/cli/package.json +1 -1
  24. package/packages/cli/src/create-project.ts +99 -10
  25. package/packages/cli/src/index.ts +64 -5
  26. package/packages/cli/template/.env.example +5 -3
  27. package/packages/create-openadminjs/package.json +1 -1
  28. package/packages/create-openadminjs/src/index.ts +56 -4
  29. package/packages/create-openadminjs/src/render-files.ts +1 -1
  30. package/packages/create-openadminjs/template/.env.example +5 -2
  31. package/packages/plugin-sdk/src/hooks.ts +91 -0
  32. package/packages/plugin-sdk/src/index.ts +6 -1
  33. package/site/docs.html +63 -56
  34. package/site/index.html +1 -1
@@ -13,6 +13,13 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
13
13
  const { copySync, ensureDirSync } = fsExtra;
14
14
 
15
15
  type PackageManager = "pnpm" | "npm" | "yarn";
16
+ type DatabaseDriver = "postgresql" | "mysql" | "sqlite";
17
+
18
+ function databaseUrl(database: DatabaseDriver, packageName: string): string {
19
+ if (database === "postgresql") return `postgresql://openadminjs:openadminjs@localhost:5432/${packageName}?schema=public`;
20
+ if (database === "mysql") return `mysql://openadminjs:openadminjs@localhost:3306/${packageName}`;
21
+ return "file:./prisma/dev.db";
22
+ }
16
23
 
17
24
  async function main(): Promise<void> {
18
25
  intro(pc.green("Create OpenAdminJS"));
@@ -31,13 +38,53 @@ async function main(): Promise<void> {
31
38
  });
32
39
  if (isCancel(manager)) return cancel("Cancelled");
33
40
 
34
- const database = await select({
41
+ const database = await select<DatabaseDriver>({
35
42
  message: "Database",
36
- options: [{ value: "postgresql", label: "PostgreSQL" }],
43
+ options: [
44
+ { value: "postgresql", label: "PostgreSQL" },
45
+ { value: "mysql", label: "MySQL" },
46
+ { value: "sqlite", label: "SQLite" }
47
+ ],
37
48
  initialValue: "postgresql"
38
49
  });
39
50
  if (isCancel(database)) return cancel("Cancelled");
40
51
 
52
+ const selectedDatabaseUrl = await text({
53
+ message: "Database URL",
54
+ defaultValue: databaseUrl(database, packageName(String(projectName)))
55
+ });
56
+ if (isCancel(selectedDatabaseUrl)) return cancel("Cancelled");
57
+
58
+ const redisUrl = await text({
59
+ message: "Redis URL (optional for queues)",
60
+ defaultValue: "redis://localhost:6379"
61
+ });
62
+ if (isCancel(redisUrl)) return cancel("Cancelled");
63
+
64
+ const jwtSecret = await text({
65
+ message: "JWT secret",
66
+ defaultValue: "change-me-to-a-long-random-secret"
67
+ });
68
+ if (isCancel(jwtSecret)) return cancel("Cancelled");
69
+
70
+ const jwtRefreshSecret = await text({
71
+ message: "JWT refresh secret",
72
+ defaultValue: "change-me-too"
73
+ });
74
+ if (isCancel(jwtRefreshSecret)) return cancel("Cancelled");
75
+
76
+ const adminOrigin = await text({
77
+ message: "Admin origin",
78
+ defaultValue: "http://localhost:3000"
79
+ });
80
+ if (isCancel(adminOrigin)) return cancel("Cancelled");
81
+
82
+ const apiPort = await text({
83
+ message: "API port",
84
+ defaultValue: "4000"
85
+ });
86
+ if (isCancel(apiPort)) return cancel("Cancelled");
87
+
41
88
  const git = await confirm({ message: "Initialize git?", initialValue: true });
42
89
  if (isCancel(git)) return cancel("Cancelled");
43
90
 
@@ -54,8 +101,13 @@ async function main(): Promise<void> {
54
101
  renderFiles(target, {
55
102
  __APP_NAME__: appName,
56
103
  __PACKAGE_NAME__: pkgName,
57
- __DATABASE_PROVIDER__: "postgresql",
58
- __DATABASE_URL__: `postgresql://openadminjs:openadminjs@localhost:5432/${pkgName}?schema=public`
104
+ __DATABASE_PROVIDER__: database,
105
+ __DATABASE_URL__: String(selectedDatabaseUrl),
106
+ __REDIS_URL__: String(redisUrl),
107
+ __JWT_SECRET__: String(jwtSecret),
108
+ __JWT_REFRESH_SECRET__: String(jwtRefreshSecret),
109
+ __ADMIN_ORIGIN__: String(adminOrigin),
110
+ __API_PORT__: String(apiPort)
59
111
  });
60
112
 
61
113
  if (git) spawnSync("git", ["init"], { cwd: target, stdio: "ignore" });
@@ -11,7 +11,7 @@ export function renderFiles(targetDir: string, replacements: Record<string, stri
11
11
  if (entry.isDirectory()) stack.push(file);
12
12
  if (entry.isFile()) {
13
13
  const content = readFileSync(file, "utf8").replace(
14
- /__APP_NAME__|__PACKAGE_NAME__|__DATABASE_URL__|__DATABASE_PROVIDER__/g,
14
+ /__APP_NAME__|__PACKAGE_NAME__|__DATABASE_URL__|__DATABASE_PROVIDER__|__REDIS_URL__|__JWT_SECRET__|__JWT_REFRESH_SECRET__|__ADMIN_ORIGIN__|__API_PORT__/g,
15
15
  (key) => replacements[key] ?? key
16
16
  );
17
17
  writeFileSync(file, content);
@@ -1,4 +1,7 @@
1
1
  DATABASE_URL=__DATABASE_URL__
2
- REDIS_URL=redis://localhost:6379
3
- JWT_SECRET=change-me-to-a-long-random-secret
2
+ REDIS_URL=__REDIS_URL__
3
+ JWT_SECRET=__JWT_SECRET__
4
+ JWT_REFRESH_SECRET=__JWT_REFRESH_SECRET__
5
+ ADMIN_ORIGIN=__ADMIN_ORIGIN__
6
+ API_PORT=__API_PORT__
4
7
  JWT_REFRESH_SECRET=change-me-too
@@ -42,3 +42,94 @@ export type ResourceLifecycleHooks = {
42
42
  beforeDelete?: (ctx: BeforeDeleteCtx) => Promise<void> | void;
43
43
  afterDelete?: (ctx: AfterDeleteCtx) => Promise<void> | void;
44
44
  };
45
+
46
+ export type ApiRouteExtension = {
47
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
48
+ path: string;
49
+ handler: (ctx: {
50
+ body?: unknown;
51
+ query?: Record<string, unknown>;
52
+ params?: Record<string, string>;
53
+ user?: ResourceHookUser;
54
+ prisma: unknown;
55
+ }) => Promise<unknown> | unknown;
56
+ };
57
+
58
+ export type ApiHooks = {
59
+ beforeRequest?: (ctx: {
60
+ method: string;
61
+ path: string;
62
+ body?: unknown;
63
+ query?: Record<string, unknown>;
64
+ user?: ResourceHookUser;
65
+ }) => Promise<void> | void;
66
+ afterRequest?: (ctx: {
67
+ method: string;
68
+ path: string;
69
+ statusCode: number;
70
+ durationMs: number;
71
+ user?: ResourceHookUser;
72
+ }) => Promise<void> | void;
73
+ routes?: ApiRouteExtension[];
74
+ };
75
+
76
+ export type MediaHooks = {
77
+ beforeStore?: (ctx: {
78
+ filename: string;
79
+ mimeType: string;
80
+ size: number;
81
+ contentBase64?: string;
82
+ user?: ResourceHookUser;
83
+ }) => Promise<void> | void;
84
+ transform?: (ctx: {
85
+ filename: string;
86
+ mimeType: string;
87
+ contentBase64: string;
88
+ user?: ResourceHookUser;
89
+ }) => Promise<{ filename?: string; mimeType?: string; contentBase64: string }> | { filename?: string; mimeType?: string; contentBase64: string };
90
+ afterStore?: (ctx: {
91
+ fileId: string;
92
+ filename: string;
93
+ mimeType: string;
94
+ size: number;
95
+ user?: ResourceHookUser;
96
+ }) => Promise<void> | void;
97
+ };
98
+
99
+ export type SeoHooks = {
100
+ metadata?: (ctx: { resourceName: string; record: Record<string, unknown> }) => Promise<Record<string, unknown>> | Record<string, unknown>;
101
+ sitemapEntry?: (ctx: { resourceName: string; record: Record<string, unknown> }) => Promise<{ url: string; lastModified?: string } | null> | { url: string; lastModified?: string } | null;
102
+ };
103
+
104
+ export type JobHandler = {
105
+ name: string;
106
+ handler: (ctx: { payload: unknown; user?: ResourceHookUser; prisma: unknown }) => Promise<unknown> | unknown;
107
+ };
108
+
109
+ export type AdminUiExtension = {
110
+ kind: "menu" | "page" | "widget" | "action";
111
+ id: string;
112
+ title: string;
113
+ route?: string;
114
+ config?: Record<string, unknown>;
115
+ };
116
+
117
+ export type PluginCapability =
118
+ | "db.read"
119
+ | "db.write"
120
+ | "resource.hooks"
121
+ | "api.hooks"
122
+ | "api.routes"
123
+ | "media.pipeline"
124
+ | "seo.extend"
125
+ | "jobs.run"
126
+ | "admin.ui.extend";
127
+
128
+ export type PluginSurfaceRegistry = {
129
+ resource?: ResourceLifecycleHooks;
130
+ api?: ApiHooks;
131
+ media?: MediaHooks;
132
+ seo?: SeoHooks;
133
+ jobs?: JobHandler[];
134
+ adminUi?: AdminUiExtension[];
135
+ };
@@ -1,10 +1,12 @@
1
- import type { ResourceLifecycleHooks } from "./hooks";
1
+ import type { PluginCapability, PluginSurfaceRegistry, ResourceLifecycleHooks } from "./hooks";
2
2
 
3
3
  export type * from "./hooks";
4
4
 
5
5
  export type PluginRegistrationContext<Config extends Record<string, unknown> = Record<string, unknown>> = {
6
6
  readonly pluginId: string;
7
7
  readonly config: Config;
8
+ readonly trustMode: "trusted" | "sandboxed";
9
+ readonly capabilities: PluginCapability[];
8
10
  /**
9
11
  * Register server-only lifecycle hooks for a resource. Multiple plugins (and core code) stack in load order.
10
12
  * Use `{ replace: true }` only when a plugin must fully override prior hooks for that resource.
@@ -14,6 +16,7 @@ export type PluginRegistrationContext<Config extends Record<string, unknown> = R
14
16
  hooks: ResourceLifecycleHooks,
15
17
  options?: { replace?: boolean }
16
18
  ) => void;
19
+ registerSurface: (surface: PluginSurfaceRegistry) => void;
17
20
  };
18
21
 
19
22
  /** Published plugins should export this (named `openAdminPlugin` or default). */
@@ -29,6 +32,8 @@ export type OpenAdminPlugin<Config extends Record<string, unknown> = Record<stri
29
32
  licenseKey?: string;
30
33
  };
31
34
  register: (ctx: PluginRegistrationContext<Config>) => void | Promise<void>;
35
+ onStart?: (ctx: PluginRegistrationContext<Config>) => void | Promise<void>;
36
+ onShutdown?: (ctx: PluginRegistrationContext<Config>) => void | Promise<void>;
32
37
  };
33
38
 
34
39
  export type OpenAdminPluginModule<Config extends Record<string, unknown> = Record<string, unknown>> = {
package/site/docs.html CHANGED
@@ -43,8 +43,7 @@
43
43
  <span>Quick install</span>
44
44
  <div class="docs-code-block docs-code-block--inline" data-language="bash">
45
45
  <div class="docs-code-toolbar"><span class="docs-code-lang">bash</span><button type="button" class="docs-code-copy" data-copy-code>Copy</button></div>
46
- <pre><code>npm install -g openadminjs
47
- openadminjs create my-app</code></pre>
46
+ <pre><code>npx openadminjs create my-app</code></pre>
48
47
  </div>
49
48
  </div>
50
49
  </section>
@@ -160,12 +159,11 @@ openadminjs create my-app</code></pre>
160
159
  <h2>Installation</h2>
161
160
  <p>
162
161
  Prerequisites: <strong>Node.js 20+</strong>, <strong>pnpm</strong> (recommended) or npm/yarn, and the OpenAdminJS CLI.
163
- The flow mirrors a typical Nest.js workspace bootstrap: scaffold, migrate, seed, run. Dependency installation happens automatically when the project is created.
162
+ The flow mirrors a typical Nest.js workspace bootstrap: scaffold, migrate, seed, run. Dependency installation and core env prompts (DB/Redis/JWT/origins) happen automatically during project creation.
164
163
  </p>
165
164
  <div class="docs-code-block" data-language="bash">
166
165
  <div class="docs-code-toolbar"><span class="docs-code-lang">bash</span><button type="button" class="docs-code-copy" data-copy-code>Copy</button></div>
167
- <pre><code>npm install -g openadminjs
168
- openadminjs create my-app
166
+ <pre><code>npx openadminjs create my-app
169
167
  cd my-app
170
168
  pnpm db:migrate
171
169
  pnpm db:seed
@@ -209,6 +207,7 @@ prisma/
209
207
  <section id="configuration">
210
208
  <h2>Configuration</h2>
211
209
  <p>
210
+ During <code>openadminjs create</code>, the wizard asks for DB credentials and key env values, then writes them into <code>.env.example</code>.
212
211
  Copy <code>.env.example</code> to <code>.env</code> at the repo root. Values are read by the Nest API and Next apps through <code>@nestjs/config</code> and
213
212
  <code>NEXT_PUBLIC_*</code> variables—treat secrets like you would in a Nest <code>ConfigModule</code> setup.
214
213
  </p>
@@ -240,30 +239,29 @@ pnpm test # all workspace tests
240
239
  pnpm --filter @openadminjs/api build</code></pre>
241
240
  </div>
242
241
  <p>
243
- The global CLI also prints equivalent commands for <code>openadminjs db migrate</code>, <code>db seed</code>, and <code>db studio</code>; those are thin wrappers that remind you which
244
- <code>pnpm</code> filter to use.
242
+ OpenAdminJS commands are run from your project workspace (for example via <code>pnpm exec openadminjs ...</code>).
243
+ Database shortcuts still map to the same underlying <code>pnpm</code> and Prisma commands.
245
244
  </p>
246
245
  </section>
247
246
 
248
247
  <section id="cli">
249
248
  <h2>CLI reference</h2>
250
- <p>Install <code>openadminjs</code> globally, then use <code>openadminjs</code> (short alias may be <code>oajs</code> depending on your install).</p>
249
+ <p>Use the packaged CLI from your project workspace via <code>pnpm exec openadminjs ...</code> (or through npm scripts).</p>
251
250
 
252
- <h3 id="cli-create">openadminjs create</h3>
251
+ <h3 id="cli-create">Project creation</h3>
253
252
  <p>Scaffolds a monorepo with <code>apps/api</code>, <code>apps/admin</code>, <code>apps/web</code>, shared packages, Prisma schema, and automatically installs dependencies with the selected package manager.</p>
254
253
  <div class="docs-code-block" data-language="bash">
255
254
  <div class="docs-code-toolbar"><span class="docs-code-lang">bash</span><button type="button" class="docs-code-copy" data-copy-code>Copy</button></div>
256
- <pre><code>npm install -g openadminjs
257
- openadminjs create # interactive prompts
258
- openadminjs create my-app # non-interactive project name</code></pre>
255
+ <pre><code>npx openadminjs create my-app
256
+ cd my-app</code></pre>
259
257
  </div>
260
258
 
261
259
  <h3 id="cli-generate-resource">generate resource / make resource</h3>
262
260
  <p>Emits a starter <code>*.resource.ts</code> next to your other resources. Model name is PascalCase (Prisma model); the file uses <code>defineResource</code> with kebab-case <code>name</code> and permission keys.</p>
263
261
  <div class="docs-code-block" data-language="bash">
264
262
  <div class="docs-code-toolbar"><span class="docs-code-lang">bash</span><button type="button" class="docs-code-copy" data-copy-code>Copy</button></div>
265
- <pre><code>openadminjs generate resource Invoice --force
266
- openadminjs make resource Invoice # alias</code></pre>
263
+ <pre><code>pnpm exec openadminjs generate resource Invoice --force
264
+ pnpm exec openadminjs make resource Invoice # alias</code></pre>
267
265
  </div>
268
266
  <p>Always register the new file in <code>registry.ts</code>, extend Prisma if needed, then migrate.</p>
269
267
 
@@ -271,16 +269,16 @@ openadminjs make resource Invoice # alias</code></pre>
271
269
  <p>Runs quick health checks (env files, Prisma generate, lockfile) so CI or onboarding catches misconfiguration early.</p>
272
270
  <div class="docs-code-block" data-language="bash">
273
271
  <div class="docs-code-toolbar"><span class="docs-code-lang">bash</span><button type="button" class="docs-code-copy" data-copy-code>Copy</button></div>
274
- <pre><code>openadminjs doctor</code></pre>
272
+ <pre><code>pnpm exec openadminjs doctor</code></pre>
275
273
  </div>
276
274
 
277
275
  <h3 id="cli-db">db migrate | seed | studio</h3>
278
276
  <p>These commands print the exact <code>pnpm</code> / Prisma invocations to run from your project root so you do not guess package names.</p>
279
277
  <div class="docs-code-block" data-language="bash">
280
278
  <div class="docs-code-toolbar"><span class="docs-code-lang">bash</span><button type="button" class="docs-code-copy" data-copy-code>Copy</button></div>
281
- <pre><code>openadminjs db migrate
282
- openadminjs db seed
283
- openadminjs db studio</code></pre>
279
+ <pre><code>pnpm exec openadminjs db migrate
280
+ pnpm exec openadminjs db seed
281
+ pnpm exec openadminjs db studio</code></pre>
284
282
  </div>
285
283
  </section>
286
284
 
@@ -912,61 +910,70 @@ export const LOCALE_LABELS: Record&lt;string, string&gt; = {
912
910
  <section id="plugins">
913
911
  <h2>Plugin system</h2>
914
912
  <p>
915
- OpenAdminJS exposes a lightweight plugin registry so you can extend resource behavior — add computed fields, inject audit log entries,
916
- attach webhooks, or wrap any action — without forking the core library.
917
- Plugins live in <code>apps/api/src/plugins/</code> and are bootstrapped before the Nest app starts.
913
+ OpenAdminJS Plugin Platform is a broad extension system (WordPress-style) with explicit capability gating.
914
+ Plugins can register resource hooks, API hooks/routes, media pipeline transforms, SEO contributors, job handlers, and admin UI extensions.
915
+ Plugins are loaded from <code>plugins.manifest.json</code> and enforced by trust mode + capabilities.
918
916
  </p>
919
917
  <div class="docs-code-block" data-language="typescript">
920
918
  <div class="docs-code-toolbar"><span class="docs-code-lang">TypeScript</span><button type="button" class="docs-code-copy" data-copy-code>Copy</button></div>
921
- <pre><code>// apps/api/src/plugins/webhook.plugin.ts
922
- import { definePlugin } from "@openadminjs/core";
919
+ <pre><code>import type { OpenAdminPlugin } from "@openadminjs/plugin-sdk";
923
920
 
924
- export default definePlugin({
925
- name: "webhook-notifier",
921
+ export const seoAndMediaPlugin: OpenAdminPlugin = {
922
+ id: "com.example.seo-media",
926
923
  version: "1.0.0",
927
- description: "Send a POST after every resource create/update/delete.",
928
- hooks: {
929
- afterCreate: async ({ resource, record, user }) => {
930
- await fetch(process.env.WEBHOOK_URL!, {
931
- method: "POST",
932
- headers: { "content-type": "application/json" },
933
- body: JSON.stringify({ event: "create", resource: resource.name, record, user: user.email })
934
- });
935
- }
924
+ async register({ registerSurface }) {
925
+ registerSurface({
926
+ seo: {
927
+ metadata({ resourceName, record }) {
928
+ if (resourceName !== "posts") return {};
929
+ return { title: record.title ?? "Untitled" };
930
+ }
931
+ },
932
+ media: {
933
+ transform({ filename, mimeType, contentBase64 }) {
934
+ if (!mimeType.startsWith("image/")) return { filename, mimeType, contentBase64 };
935
+ return { filename: filename.replace(/\\.(png|jpe?g)$/i, ".webp"), mimeType: "image/webp", contentBase64 };
936
+ }
937
+ }
938
+ });
936
939
  }
937
- });</code></pre>
940
+ };</code></pre>
938
941
  </div>
939
- <p>Register plugins in <code>apps/api/src/plugins/bootstrap.ts</code>:</p>
942
+ <p>Register plugin entries in <code>apps/api/plugins.manifest.json</code> with explicit capabilities:</p>
940
943
  <div class="docs-code-block" data-language="typescript">
941
944
  <div class="docs-code-toolbar"><span class="docs-code-lang">TypeScript</span><button type="button" class="docs-code-copy" data-copy-code>Copy</button></div>
942
- <pre><code>import { pluginRegistry } from "@openadminjs/core";
943
- import webhookPlugin from "./webhook.plugin";
944
-
945
- pluginRegistry.register(webhookPlugin);</code></pre>
945
+ <pre><code>{
946
+ "version": 1,
947
+ "plugins": [
948
+ {
949
+ "id": "com.example.seo-media",
950
+ "enabled": true,
951
+ "package": "@example/openadmin-seo-media",
952
+ "trustMode": "sandboxed",
953
+ "capabilities": ["seo.extend", "media.pipeline"]
954
+ }
955
+ ]
956
+ }</code></pre>
946
957
  </div>
958
+ <p class="mt-3">
959
+ Capability matrix: <code>resource.hooks</code>, <code>api.hooks</code>, <code>api.routes</code>,
960
+ <code>media.pipeline</code>, <code>seo.extend</code>, <code>jobs.run</code>, <code>admin.ui.extend</code>.
961
+ Use <code>sandboxed</code> trust mode and request only minimal capabilities by default.
962
+ </p>
947
963
  </section>
948
964
 
949
965
  <section id="hooks">
950
966
  <h2>Resource hooks</h2>
951
967
  <p>
952
- Resource-level hooks let you intercept the CRUD lifecycle per resource, e.g. to hash passwords before a create or invalidate a cache after an update.
953
- Hooks declared in <code>resource-hooks.install.ts</code> are attached to the resource registry at startup.
968
+ Resource lifecycle hooks are now one surface within Plugin Platform. Use capability
969
+ <code>resource.hooks</code> and register through plugin SDK context.
954
970
  </p>
955
971
  <div class="docs-code-block" data-language="typescript">
956
972
  <div class="docs-code-toolbar"><span class="docs-code-lang">TypeScript</span><button type="button" class="docs-code-copy" data-copy-code>Copy</button></div>
957
- <pre><code>// apps/api/src/resources/resource-hooks.install.ts
958
- import bcrypt from "bcryptjs";
959
- import { resourceHooks } from "@openadminjs/core";
960
-
961
- resourceHooks.on("users", "beforeCreate", async (data) => {
962
- if (data.password) {
963
- data.password = await bcrypt.hash(data.password, 12);
973
+ <pre><code>registerResourceHooks("users", {
974
+ async beforeCreate({ data }) {
975
+ if (typeof data.email === "string") data.email = data.email.trim().toLowerCase();
964
976
  }
965
- return data;
966
- });
967
-
968
- resourceHooks.on("posts", "afterUpdate", async (_data, context) => {
969
- await context.cache?.invalidate(`post:${context.id}`);
970
977
  });</code></pre>
971
978
  </div>
972
979
  <p>Available lifecycle events: <code>beforeCreate</code>, <code>afterCreate</code>, <code>beforeUpdate</code>, <code>afterUpdate</code>, <code>beforeDelete</code>, <code>afterDelete</code>.</p>
@@ -1368,7 +1375,7 @@ GET /store/orders/:id/status</code></pre>
1368
1375
  <ul class="docs-list">
1369
1376
  <li><strong>Partner applications</strong> — branding, sponsorship and collaboration requests.</li>
1370
1377
  <li><strong>Financial support</strong> — for direct support options, contact <a href="mailto:openadminjs@proton.me">openadminjs@proton.me</a>.</li>
1371
- <li><strong>Bug reports &amp; feature requests</strong> — open an issue on GitHub; include a reproduction case and the output of <code>openadminjs doctor</code>.</li>
1378
+ <li><strong>Bug reports &amp; feature requests</strong> — open an issue on GitHub; include a reproduction case and the output of <code>pnpm exec openadminjs doctor</code>.</li>
1372
1379
  <li><strong>Pull requests</strong> — all contributions welcome; check the <code>CONTRIBUTING.md</code> at the repo root before opening a PR.</li>
1373
1380
  </ul>
1374
1381
  </section>
@@ -1427,7 +1434,7 @@ GET /store/orders/:id/status</code></pre>
1427
1434
 
1428
1435
  <h3>Developer experience</h3>
1429
1436
  <ul class="docs-list">
1430
- <li>🟢 CLI scaffold with <code>openadminjs create</code></li>
1437
+ <li>🟢 CLI scaffold with <code>npx openadminjs create</code></li>
1431
1438
  <li>🟡 VS Code extension — resource file type support, schema validation</li>
1432
1439
  <li>⚪ <code>openadminjs generate field</code> — append a field to an existing resource and emit a Prisma migration fragment</li>
1433
1440
  <li>⚪ Storybook integration — isolated UI component development</li>
package/site/index.html CHANGED
@@ -53,7 +53,7 @@
53
53
  </ul>
54
54
  <div class="command-chip command-chip-glow">
55
55
  <span>Quick start</span>
56
- <code>npm i -g openadminjs && openadminjs create</code>
56
+ <code>npx openadminjs create my-app</code>
57
57
  </div>
58
58
  </div>
59
59