openadminjs 0.1.6 → 0.1.8

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 (216) hide show
  1. package/dist/create-project.js +38 -6
  2. package/dist/create-project.test.js +69 -24
  3. package/dist/index.js +16 -5
  4. package/package.json +4 -2
  5. package/template/.env.example +2 -2
  6. package/template/README.md +24 -3
  7. package/template/apps/admin/app/api/auth/login/route.ts +51 -0
  8. package/template/apps/admin/app/api/auth/logout/route.ts +11 -0
  9. package/template/apps/admin/app/api/auth/refresh/route.ts +46 -0
  10. package/template/apps/admin/app/api-tokens/page.tsx +253 -0
  11. package/template/apps/admin/app/audit-logs/page.tsx +5 -0
  12. package/template/apps/admin/app/dashboard/page.tsx +392 -0
  13. package/template/apps/admin/app/files/page.tsx +5 -0
  14. package/template/apps/admin/app/globals.css +206 -0
  15. package/template/apps/admin/app/jobs/page.tsx +19 -0
  16. package/template/apps/admin/app/layout.tsx +57 -0
  17. package/template/apps/admin/app/login/page.test.tsx +18 -0
  18. package/template/apps/admin/app/login/page.tsx +161 -0
  19. package/template/apps/admin/app/login/safe-next-param.ts +4 -0
  20. package/template/apps/admin/app/notifications/page.tsx +146 -0
  21. package/template/apps/admin/app/page.tsx +5 -0
  22. package/template/apps/admin/app/plugins/page.tsx +407 -0
  23. package/template/apps/admin/app/profile/page.tsx +116 -0
  24. package/template/apps/admin/app/resources/[resource]/[id]/edit/page.tsx +45 -0
  25. package/template/apps/admin/app/resources/[resource]/[id]/page.tsx +449 -0
  26. package/template/apps/admin/app/resources/[resource]/create/page.tsx +34 -0
  27. package/template/apps/admin/app/resources/[resource]/page.tsx +100 -0
  28. package/template/apps/admin/app/settings/page.tsx +233 -0
  29. package/template/apps/admin/components/ai-assistant-widget.tsx +684 -0
  30. package/template/apps/admin/components/app-shell.tsx +305 -0
  31. package/template/apps/admin/components/auth-guard.test.tsx +55 -0
  32. package/template/apps/admin/components/auth-guard.tsx +39 -0
  33. package/template/apps/admin/components/jobs-panel.tsx +103 -0
  34. package/template/apps/admin/components/logo.tsx +30 -0
  35. package/template/apps/admin/components/resource-form.tsx +349 -0
  36. package/template/apps/admin/components/resource-table.tsx +277 -0
  37. package/template/apps/admin/lib/ai-events.ts +23 -0
  38. package/template/apps/admin/lib/api.test.ts +118 -0
  39. package/template/apps/admin/lib/api.ts +135 -0
  40. package/template/apps/admin/lib/auth-flow.e2e.test.ts +79 -0
  41. package/template/apps/admin/lib/brand.ts +14 -0
  42. package/template/apps/admin/lib/locale.ts +49 -0
  43. package/template/apps/admin/lib/tokens.ts +93 -0
  44. package/template/apps/admin/middleware.ts +58 -0
  45. package/template/apps/admin/next-env.d.ts +6 -0
  46. package/template/apps/admin/next.config.mjs +7 -0
  47. package/template/apps/admin/package.json +44 -0
  48. package/template/apps/admin/postcss.config.mjs +6 -0
  49. package/template/apps/admin/public/brand/apple-touch-icon.png +0 -0
  50. package/template/apps/admin/public/brand/favicon.svg +1 -0
  51. package/template/apps/admin/public/brand/og-image.png +0 -0
  52. package/template/apps/admin/public/brand/openadminjs-icon-new.png +0 -0
  53. package/template/apps/admin/public/brand/openadminjs-logo-monochrome.png +0 -0
  54. package/template/apps/admin/public/brand/openadminjs-logo-new.png +0 -0
  55. package/template/apps/admin/tailwind.config.ts +37 -0
  56. package/template/apps/admin/tsconfig.json +23 -0
  57. package/template/apps/admin/vitest.config.ts +7 -0
  58. package/template/apps/api/package.json +56 -0
  59. package/template/apps/api/plugins.manifest.example.json +34 -0
  60. package/template/apps/api/plugins.manifest.json +4 -0
  61. package/template/apps/api/src/access/catalog.ts +112 -0
  62. package/template/apps/api/src/access/derive-permissions.test.ts +26 -0
  63. package/template/apps/api/src/access/derive-permissions.ts +36 -0
  64. package/template/apps/api/src/access/public-catalog.ts +28 -0
  65. package/template/apps/api/src/admin/admin-ai.controller.ts +125 -0
  66. package/template/apps/api/src/admin/admin-ai.events.ts +23 -0
  67. package/template/apps/api/src/admin/admin-ai.service.ts +1271 -0
  68. package/template/apps/api/src/admin/admin-analytics.service.ts +164 -0
  69. package/template/apps/api/src/admin/admin-plugins.controller.ts +32 -0
  70. package/template/apps/api/src/admin/admin-plugins.service.ts +267 -0
  71. package/template/apps/api/src/admin/admin-resource.service.test.ts +118 -0
  72. package/template/apps/api/src/admin/admin-resource.service.ts +375 -0
  73. package/template/apps/api/src/admin/admin.controller.ts +72 -0
  74. package/template/apps/api/src/admin/admin.module.ts +30 -0
  75. package/template/apps/api/src/admin/dto/plugins.dto.ts +55 -0
  76. package/template/apps/api/src/admin/validate-resource-payload.test.ts +44 -0
  77. package/template/apps/api/src/admin/validate-resource-payload.ts +103 -0
  78. package/template/apps/api/src/app.module.ts +45 -0
  79. package/template/apps/api/src/auth/auth.controller.ts +70 -0
  80. package/template/apps/api/src/auth/auth.dto.ts +49 -0
  81. package/template/apps/api/src/auth/auth.module.ts +30 -0
  82. package/template/apps/api/src/auth/auth.service.test.ts +75 -0
  83. package/template/apps/api/src/auth/auth.service.ts +231 -0
  84. package/template/apps/api/src/common/auth-realm.decorator.ts +6 -0
  85. package/template/apps/api/src/common/auth.guard.test.ts +61 -0
  86. package/template/apps/api/src/common/auth.guard.ts +78 -0
  87. package/template/apps/api/src/common/casl-ability.factory.test.ts +33 -0
  88. package/template/apps/api/src/common/casl-ability.factory.ts +41 -0
  89. package/template/apps/api/src/common/current-user.decorator.ts +6 -0
  90. package/template/apps/api/src/common/permission.decorator.ts +7 -0
  91. package/template/apps/api/src/common/permissions.guard.ts +31 -0
  92. package/template/apps/api/src/common/prisma.service.ts +13 -0
  93. package/template/apps/api/src/health/health.controller.ts +25 -0
  94. package/template/apps/api/src/mail/mail.module.ts +9 -0
  95. package/template/apps/api/src/mail/mail.service.ts +115 -0
  96. package/template/apps/api/src/main.ts +37 -0
  97. package/template/apps/api/src/plugins/bootstrap.ts +4 -0
  98. package/template/apps/api/src/plugins/bundled/admin-widget.plugin.ts +25 -0
  99. package/template/apps/api/src/plugins/bundled/hello.plugin.ts +19 -0
  100. package/template/apps/api/src/plugins/bundled/image-optimizer.plugin.ts +22 -0
  101. package/template/apps/api/src/plugins/bundled/registry.ts +13 -0
  102. package/template/apps/api/src/plugins/bundled/seo.plugin.ts +25 -0
  103. package/template/apps/api/src/plugins/manifest-path.ts +35 -0
  104. package/template/apps/api/src/plugins/manifest.schema.test.ts +36 -0
  105. package/template/apps/api/src/plugins/manifest.schema.ts +58 -0
  106. package/template/apps/api/src/plugins/plugin-api.interceptor.ts +47 -0
  107. package/template/apps/api/src/plugins/plugin-loader.ts +134 -0
  108. package/template/apps/api/src/plugins/plugin-runtime.test.ts +24 -0
  109. package/template/apps/api/src/plugins/plugin-runtime.ts +85 -0
  110. package/template/apps/api/src/queue/queue.controller.ts +28 -0
  111. package/template/apps/api/src/queue/queue.module.ts +23 -0
  112. package/template/apps/api/src/queue/queue.processor.ts +47 -0
  113. package/template/apps/api/src/queue/queue.service.ts +50 -0
  114. package/template/apps/api/src/resources/categories.resource.ts +21 -0
  115. package/template/apps/api/src/resources/commerce.resource.ts +157 -0
  116. package/template/apps/api/src/resources/operations.resource.ts +111 -0
  117. package/template/apps/api/src/resources/posts.resource.ts +88 -0
  118. package/template/apps/api/src/resources/registry.ts +27 -0
  119. package/template/apps/api/src/resources/resource-hooks.install.ts +18 -0
  120. package/template/apps/api/src/resources/resource-hooks.registry.test.ts +72 -0
  121. package/template/apps/api/src/resources/resource-hooks.registry.ts +66 -0
  122. package/template/apps/api/src/resources/resource-hooks.runner.ts +93 -0
  123. package/template/apps/api/src/resources/system.resource.ts +51 -0
  124. package/template/apps/api/src/resources/users.resource.ts +19 -0
  125. package/template/apps/api/src/store/payment/payment.controller.ts +98 -0
  126. package/template/apps/api/src/store/payment/payment.module.ts +14 -0
  127. package/template/apps/api/src/store/payment/payment.provider.ts +38 -0
  128. package/template/apps/api/src/store/payment/payment.service.ts +235 -0
  129. package/template/apps/api/src/store/store.controller.ts +26 -0
  130. package/template/apps/api/src/store/store.module.ts +12 -0
  131. package/template/apps/api/src/test-setup.ts +1 -0
  132. package/template/apps/api/tsconfig.json +11 -0
  133. package/template/apps/api/vitest.config.ts +21 -0
  134. package/template/apps/web/lib/openadmin-client.ts +11 -0
  135. package/template/apps/web/lib/seo.test.ts +41 -0
  136. package/template/apps/web/lib/seo.ts +24 -13
  137. package/template/apps/web/next-env.d.ts +4 -0
  138. package/template/apps/web/package.json +2 -1
  139. package/template/apps/web/test/next-stub.ts +7 -0
  140. package/template/apps/web/vitest.config.ts +19 -0
  141. package/template/package.json +18 -11
  142. package/template/packages/auth/package.json +17 -0
  143. package/template/packages/auth/src/index.test.ts +10 -0
  144. package/template/packages/auth/src/index.ts +17 -0
  145. package/template/packages/auth/tsconfig.json +8 -0
  146. package/template/packages/brand/apps/admin/public/brand/apple-touch-icon.png +0 -0
  147. package/template/packages/brand/apps/admin/public/brand/favicon.svg +1 -0
  148. package/template/packages/brand/apps/admin/public/brand/og-image.png +0 -0
  149. package/template/packages/brand/apps/admin/public/brand/openadminjs-icon-new.png +0 -0
  150. package/template/packages/brand/apps/admin/public/brand/openadminjs-logo-monochrome.png +0 -0
  151. package/template/packages/brand/apps/admin/public/brand/openadminjs-logo-new.png +0 -0
  152. package/template/packages/brand/apps/web/public/brand/apple-touch-icon.png +0 -0
  153. package/template/packages/brand/apps/web/public/brand/favicon.svg +1 -0
  154. package/template/packages/brand/apps/web/public/brand/og-image.png +0 -0
  155. package/template/packages/brand/apps/web/public/brand/openadminjs-icon-new.png +0 -0
  156. package/template/packages/brand/apps/web/public/brand/openadminjs-logo-monochrome.png +0 -0
  157. package/template/packages/brand/apps/web/public/brand/openadminjs-logo-new.png +0 -0
  158. package/template/packages/brand/package.json +19 -0
  159. package/template/packages/brand/site/assets/brand/favicon.svg +1 -0
  160. package/template/packages/brand/site/assets/brand/og-image.svg +1 -0
  161. package/template/packages/brand/site/assets/brand/openadminjs-icon.svg +1 -0
  162. package/template/packages/brand/site/assets/brand/openadminjs-logo-dark.svg +1 -0
  163. package/template/packages/brand/site/assets/brand/openadminjs-logo-horizontal.svg +1 -0
  164. package/template/packages/brand/site/assets/brand/openadminjs-logo-monochrome.svg +1 -0
  165. package/template/packages/brand/site/assets/brand/openadminjs-logo.svg +1 -0
  166. package/template/packages/brand/src/generate-assets.mjs +182 -0
  167. package/template/packages/brand/src/index.test.ts +9 -0
  168. package/template/packages/brand/src/index.ts +7 -0
  169. package/template/packages/brand/tsconfig.json +7 -0
  170. package/template/packages/core/package.json +20 -0
  171. package/template/packages/core/src/index.js +1 -0
  172. package/template/packages/core/src/index.test.ts +27 -0
  173. package/template/packages/core/src/index.ts +61 -0
  174. package/template/packages/core/tsconfig.json +8 -0
  175. package/template/packages/mail/package.json +18 -0
  176. package/template/packages/mail/src/index.test.ts +23 -0
  177. package/template/packages/mail/src/index.ts +246 -0
  178. package/template/packages/mail/tsconfig.json +5 -0
  179. package/template/packages/notifications/package.json +16 -0
  180. package/template/packages/notifications/src/index.test.ts +9 -0
  181. package/template/packages/notifications/src/index.ts +5 -0
  182. package/template/packages/notifications/tsconfig.json +5 -0
  183. package/template/packages/payments/package.json +15 -0
  184. package/template/packages/payments/src/index.ts +256 -0
  185. package/template/packages/payments/tsconfig.json +9 -0
  186. package/template/packages/permissions/package.json +17 -0
  187. package/template/packages/permissions/src/blueprints.js +57 -0
  188. package/template/packages/permissions/src/blueprints.test.ts +62 -0
  189. package/template/packages/permissions/src/blueprints.ts +89 -0
  190. package/template/packages/permissions/src/index.js +11 -0
  191. package/template/packages/permissions/src/index.test.ts +34 -0
  192. package/template/packages/permissions/src/index.ts +22 -0
  193. package/template/packages/permissions/tsconfig.json +8 -0
  194. package/template/packages/plugin-sdk/package.json +26 -0
  195. package/template/packages/plugin-sdk/src/hooks.ts +135 -0
  196. package/template/packages/plugin-sdk/src/index.ts +42 -0
  197. package/template/packages/plugin-sdk/src/sdk.test.ts +13 -0
  198. package/template/packages/plugin-sdk/tsconfig.json +8 -0
  199. package/template/packages/plugin-sdk/vitest.config.ts +5 -0
  200. package/template/packages/queue/package.json +16 -0
  201. package/template/packages/queue/src/index.test.ts +12 -0
  202. package/template/packages/queue/src/index.ts +6 -0
  203. package/template/packages/queue/tsconfig.json +5 -0
  204. package/template/packages/resource/package.json +17 -0
  205. package/template/packages/resource/src/index.js +177 -0
  206. package/template/packages/resource/src/index.test.ts +151 -0
  207. package/template/packages/resource/src/index.ts +344 -0
  208. package/template/packages/resource/tsconfig.json +8 -0
  209. package/template/packages/storage/package.json +16 -0
  210. package/template/packages/storage/src/index.test.ts +10 -0
  211. package/template/packages/storage/src/index.ts +23 -0
  212. package/template/packages/storage/tsconfig.json +5 -0
  213. package/template/prisma/migrations/20260505151751_baseline_init_all_tables/migration.sql +371 -0
  214. package/template/prisma/migrations/migration_lock.toml +3 -0
  215. package/template/prisma/schema.prisma +291 -0
  216. package/template/prisma/seed.ts +217 -0
@@ -1,5 +1,5 @@
1
- import { existsSync, readdirSync } from "node:fs";
2
- import { dirname, resolve } from "node:path";
1
+ import { existsSync, mkdirSync, readdirSync } from "node:fs";
2
+ import { dirname, extname, join, relative, resolve, sep } from "node:path";
3
3
  import { spawnSync } from "node:child_process";
4
4
  import { fileURLToPath } from "node:url";
5
5
  import { cancel, confirm, intro, isCancel, outro, select, text } from "@clack/prompts";
@@ -7,6 +7,7 @@ import fsExtra from "fs-extra";
7
7
  import pc from "picocolors";
8
8
  const __dirname = dirname(fileURLToPath(import.meta.url));
9
9
  const { copySync, ensureDirSync, readFileSync, writeFileSync } = fsExtra;
10
+ const BINARY_EXTENSIONS = new Set([".png", ".jpg", ".jpeg", ".gif", ".webp", ".svg", ".ico", ".woff", ".woff2", ".ttf", ".eot"]);
10
11
  const placeholderPattern = /__APP_NAME__|__PACKAGE_NAME__|__DATABASE_URL__|__DATABASE_PROVIDER__|__REDIS_URL__|__JWT_SECRET__|__JWT_REFRESH_SECRET__|__ADMIN_ORIGIN__|__API_PORT__/g;
11
12
  export function toPackageName(input) {
12
13
  return input
@@ -28,6 +29,8 @@ function databaseUrl(packageName, database) {
28
29
  return "file:./prisma/dev.db";
29
30
  }
30
31
  function renderFile(file, replacements) {
32
+ if (BINARY_EXTENSIONS.has(extname(file).toLowerCase()))
33
+ return;
31
34
  const content = readFileSync(file, "utf8");
32
35
  writeFileSync(file, content.replace(placeholderPattern, (key) => replacements[key] ?? key));
33
36
  }
@@ -60,8 +63,14 @@ export function createProject(options) {
60
63
  copySync(options.templateDir, targetDir, {
61
64
  overwrite: false,
62
65
  errorOnExist: true,
63
- filter: (source) => !source.includes("node_modules") && !source.includes(".next") && !source.includes("dist")
66
+ filter: (source) => {
67
+ const segments = relative(options.templateDir, source).split(sep);
68
+ return !segments.some((segment) => segment === "node_modules" || segment === ".next" || segment === "dist");
69
+ }
64
70
  });
71
+ if (!existsSync(join(targetDir, "package.json"))) {
72
+ throw new Error(`Template copy failed: package.json not found in ${targetDir}`);
73
+ }
65
74
  renderTemplateFiles(targetDir, {
66
75
  __APP_NAME__: appName,
67
76
  __PACKAGE_NAME__: packageName,
@@ -73,12 +82,35 @@ export function createProject(options) {
73
82
  __ADMIN_ORIGIN__: options.adminOrigin,
74
83
  __API_PORT__: options.apiPort
75
84
  });
85
+ // Write the real .env for apps/api so the app starts and seed runs without
86
+ // manual intervention. Superadmin credentials are picked up by prisma/seed.ts
87
+ // via the SUPERADMIN_EMAIL / SUPERADMIN_PASSWORD env vars.
88
+ const apiEnvDir = join(targetDir, "apps", "api");
89
+ if (existsSync(apiEnvDir)) {
90
+ mkdirSync(apiEnvDir, { recursive: true });
91
+ writeFileSync(join(apiEnvDir, ".env"), [
92
+ `DATABASE_URL=${options.databaseUrl}`,
93
+ `REDIS_URL=${options.redisUrl}`,
94
+ `JWT_SECRET=${options.jwtSecret}`,
95
+ `JWT_REFRESH_SECRET=${options.jwtRefreshSecret}`,
96
+ `ADMIN_ORIGIN=${options.adminOrigin}`,
97
+ `API_PORT=${options.apiPort}`,
98
+ `SUPERADMIN_EMAIL=${options.superadminEmail}`,
99
+ `SUPERADMIN_PASSWORD=${options.superadminPassword}`
100
+ ].join("\n") + "\n");
101
+ }
76
102
  if (options.git) {
77
- spawnSync("git", ["init"], { cwd: targetDir, stdio: "ignore" });
103
+ const gitResult = spawnSync("git", ["init"], { cwd: targetDir, stdio: "ignore" });
104
+ if (gitResult.status !== 0 || gitResult.error) {
105
+ throw new Error("Failed to initialize git repository.");
106
+ }
78
107
  }
79
108
  if (options.install) {
80
109
  const installArgs = options.packageManager === "yarn" ? [] : ["install"];
81
- spawnSync(options.packageManager, installArgs, { cwd: targetDir, stdio: "inherit" });
110
+ const installResult = spawnSync(options.packageManager, installArgs, { cwd: targetDir, stdio: "inherit" });
111
+ if (installResult.status !== 0 || installResult.error) {
112
+ throw new Error(`Dependency installation failed. Run "${options.packageManager} ${installArgs.join(" ")}" inside ${targetDir}.`);
113
+ }
82
114
  }
83
115
  return {
84
116
  appName,
@@ -94,7 +126,7 @@ export function createProject(options) {
94
126
  export function printNextSteps(result) {
95
127
  const pm = result.packageManager;
96
128
  const installStep = result.install ? "" : `\n ${pm} install`;
97
- outro(`${pc.green("Project created.")}\n\nNext steps:\n cd ${result.appName}${installStep}\n docker compose up -d\n ${pm} db:migrate\n ${pm} db:seed\n ${pm} dev\n\nAdmin: http://localhost:3000\nAPI: http://localhost:4000\nDocs: http://localhost:4000/api/docs\n\nSuperadmin: ${result.superadminEmail} / <your password>`);
129
+ outro(`${pc.green("Project created.")}\n\nNext steps:\n cd ${result.appName}${installStep}\n ${pm} db:migrate\n ${pm} db:seed\n ${pm} dev\n\nAdmin: http://localhost:3000\nAPI: http://localhost:4000\nSwagger: http://localhost:4000/api/docs\nWeb: http://localhost:3001\n\nSuperadmin: ${result.superadminEmail} / <your password>`);
98
130
  }
99
131
  export async function createProjectInteractive(options = {}) {
100
132
  intro(pc.green("Create OpenAdminJS"));
@@ -1,36 +1,33 @@
1
- import { mkdtempSync, readFileSync, rmSync } from "node:fs";
1
+ import { existsSync, mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { tmpdir } from "node:os";
4
4
  import { describe, expect, it } from "vitest";
5
5
  import { createProject, defaultTemplateDir } from "./create-project.js";
6
+ const BASE_OPTIONS = {
7
+ packageManager: "pnpm",
8
+ database: "postgresql",
9
+ superadminEmail: "admin@localhost.dev",
10
+ superadminPassword: "password1234",
11
+ databaseUrl: "postgresql://localhost:5432/my-app?schema=public",
12
+ redisUrl: "redis://localhost:6379",
13
+ jwtSecret: "test-jwt-secret",
14
+ jwtRefreshSecret: "test-jwt-refresh-secret",
15
+ adminOrigin: "http://localhost:3000",
16
+ apiPort: "4000",
17
+ git: false,
18
+ install: false
19
+ };
6
20
  describe("create project", () => {
7
- it("ships template env defaults for admin origin and api port", () => {
21
+ it("template .env.example contains placeholder keys for every secret", () => {
8
22
  const envExample = readFileSync(join(defaultTemplateDir(), ".env.example"), "utf8");
9
- expect(envExample).toContain("ADMIN_ORIGIN=http://localhost:3000");
10
- expect(envExample).toContain("API_PORT=4000");
11
- expect(envExample).not.toContain("__ADMIN_ORIGIN__");
12
- expect(envExample).not.toContain("__API_PORT__");
23
+ for (const key of ["__DATABASE_URL__", "__REDIS_URL__", "__JWT_SECRET__", "__JWT_REFRESH_SECRET__", "__ADMIN_ORIGIN__", "__API_PORT__"]) {
24
+ expect(envExample, `missing placeholder ${key}`).toContain(key);
25
+ }
13
26
  });
14
- it("creates project with rendered env values", () => {
27
+ it("creates project with rendered .env.example values", () => {
15
28
  const cwd = mkdtempSync(join(tmpdir(), "openadminjs-cli-test-"));
16
29
  try {
17
- const result = createProject({
18
- projectName: "my-app",
19
- cwd,
20
- packageManager: "pnpm",
21
- database: "postgresql",
22
- superadminEmail: "admin@localhost.dev",
23
- superadminPassword: "12345678",
24
- databaseUrl: "postgresql://localhost:5432/my-app?schema=public",
25
- redisUrl: "redis://localhost:6379",
26
- jwtSecret: "test-jwt-secret",
27
- jwtRefreshSecret: "test-jwt-refresh-secret",
28
- adminOrigin: "http://localhost:3000",
29
- apiPort: "4000",
30
- git: false,
31
- install: false,
32
- templateDir: defaultTemplateDir()
33
- });
30
+ const result = createProject({ ...BASE_OPTIONS, projectName: "my-app", cwd, templateDir: defaultTemplateDir() });
34
31
  const envExample = readFileSync(join(result.targetDir, ".env.example"), "utf8");
35
32
  expect(envExample).toContain("DATABASE_URL=postgresql://localhost:5432/my-app?schema=public");
36
33
  expect(envExample).toContain("REDIS_URL=redis://localhost:6379");
@@ -43,4 +40,52 @@ describe("create project", () => {
43
40
  rmSync(cwd, { recursive: true, force: true });
44
41
  }
45
42
  });
43
+ it("writes apps/api/.env with real secrets and superadmin credentials", () => {
44
+ const cwd = mkdtempSync(join(tmpdir(), "openadminjs-cli-test-"));
45
+ try {
46
+ const result = createProject({ ...BASE_OPTIONS, projectName: "my-app", cwd, templateDir: defaultTemplateDir() });
47
+ const apiEnv = readFileSync(join(result.targetDir, "apps", "api", ".env"), "utf8");
48
+ expect(apiEnv).toContain("DATABASE_URL=postgresql://localhost:5432/my-app?schema=public");
49
+ expect(apiEnv).toContain("JWT_SECRET=test-jwt-secret");
50
+ expect(apiEnv).toContain("SUPERADMIN_EMAIL=admin@localhost.dev");
51
+ expect(apiEnv).toContain("SUPERADMIN_PASSWORD=password1234");
52
+ }
53
+ finally {
54
+ rmSync(cwd, { recursive: true, force: true });
55
+ }
56
+ });
57
+ it("fails fast when template package.json is missing", () => {
58
+ const cwd = mkdtempSync(join(tmpdir(), "openadminjs-cli-test-"));
59
+ const badTemplate = mkdtempSync(join(tmpdir(), "openadminjs-cli-template-"));
60
+ try {
61
+ writeFileSync(join(badTemplate, ".env.example"), "DATABASE_URL=__DATABASE_URL__\n");
62
+ mkdirSync(join(badTemplate, "apps"), { recursive: true });
63
+ expect(() => createProject({ ...BASE_OPTIONS, projectName: "broken-app", cwd, templateDir: badTemplate })).toThrow(/package\.json not found/);
64
+ }
65
+ finally {
66
+ rmSync(cwd, { recursive: true, force: true });
67
+ rmSync(badTemplate, { recursive: true, force: true });
68
+ }
69
+ });
70
+ it("copies template when installed inside node_modules (npx scenario)", () => {
71
+ // The old filter `source.includes("node_modules")` matched the entire absolute path when the
72
+ // package was installed via npx (~/.npm/_npx/.../node_modules/openadminjs/template/...) and
73
+ // blocked every file, so package.json never landed in the target.
74
+ const cwd = mkdtempSync(join(tmpdir(), "openadminjs-cli-test-"));
75
+ const fakeNpx = mkdtempSync(join(tmpdir(), "openadminjs-npx-"));
76
+ const templateDir = join(fakeNpx, "node_modules", "openadminjs", "template");
77
+ try {
78
+ mkdirSync(templateDir, { recursive: true });
79
+ writeFileSync(join(templateDir, "package.json"), JSON.stringify({ name: "__APP_NAME__", private: true }, null, 2) + "\n");
80
+ writeFileSync(join(templateDir, ".env.example"), "DATABASE_URL=__DATABASE_URL__\n");
81
+ const result = createProject({ ...BASE_OPTIONS, projectName: "npx-app", cwd, templateDir });
82
+ const packageJson = readFileSync(join(result.targetDir, "package.json"), "utf8");
83
+ expect(packageJson).toContain('"name": "npx-app"');
84
+ expect(existsSync(join(result.targetDir, "apps", "api", ".env"))).toBe(false);
85
+ }
86
+ finally {
87
+ rmSync(cwd, { recursive: true, force: true });
88
+ rmSync(fakeNpx, { recursive: true, force: true });
89
+ }
90
+ });
46
91
  });
package/dist/index.js CHANGED
@@ -1,18 +1,29 @@
1
1
  #!/usr/bin/env node
2
2
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
3
  import { join } from "node:path";
4
+ import { spawnSync } from "node:child_process";
4
5
  import { cac } from "cac";
5
6
  import pc from "picocolors";
6
7
  import { createProjectInteractive } from "./create-project.js";
7
8
  import { modelNameToResourceSlug } from "./resource-slug.js";
8
9
  const cli = cac("openadminjs");
9
10
  function runScript(name) {
10
- const scripts = {
11
- dev: "pnpm --parallel --filter @openadminjs/api --filter @openadminjs/admin dev",
12
- build: "pnpm -r build",
13
- start: "pnpm --parallel --filter @openadminjs/api --filter @openadminjs/admin start"
11
+ const commands = {
12
+ dev: ["pnpm", ["--parallel", "--filter", "@openadminjs/api", "--filter", "@openadminjs/admin", "dev"]],
13
+ build: ["pnpm", ["-r", "build"]],
14
+ start: ["pnpm", ["--parallel", "--filter", "@openadminjs/api", "--filter", "@openadminjs/admin", "start"]]
14
15
  };
15
- console.log(pc.cyan(`Run: ${scripts[name]}`));
16
+ const entry = commands[name];
17
+ if (!entry) {
18
+ console.error(pc.red(`Unknown script: ${name}`));
19
+ process.exitCode = 1;
20
+ return;
21
+ }
22
+ const [cmd, args] = entry;
23
+ const result = spawnSync(cmd, args, { stdio: "inherit", cwd: process.cwd() });
24
+ if (result.status !== 0 || result.error) {
25
+ process.exitCode = result.status ?? 1;
26
+ }
16
27
  }
17
28
  function doctor() {
18
29
  const required = ["package.json", "pnpm-workspace.yaml", ".env.example", "prisma/schema.prisma"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openadminjs",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "openadminjs": "dist/index.js"
@@ -26,7 +26,9 @@
26
26
  "README.md"
27
27
  ],
28
28
  "scripts": {
29
- "build": "tsc -p tsconfig.json && node ../../scripts/make-executable.mjs dist/index.js",
29
+ "sync-template": "node ../../scripts/sync-template.mjs",
30
+ "prepack": "node ../../scripts/sync-template.mjs",
31
+ "build": "node ../../scripts/sync-template.mjs && tsc -p tsconfig.json && node ../../scripts/make-executable.mjs dist/index.js",
30
32
  "lint": "tsc -p tsconfig.json --noEmit",
31
33
  "typecheck": "tsc -p tsconfig.json --noEmit",
32
34
  "test": "vitest run"
@@ -2,5 +2,5 @@ DATABASE_URL=__DATABASE_URL__
2
2
  REDIS_URL=__REDIS_URL__
3
3
  JWT_SECRET=__JWT_SECRET__
4
4
  JWT_REFRESH_SECRET=__JWT_REFRESH_SECRET__
5
- ADMIN_ORIGIN=http://localhost:3000
6
- API_PORT=4000
5
+ ADMIN_ORIGIN=__ADMIN_ORIGIN__
6
+ API_PORT=__API_PORT__
@@ -1,13 +1,34 @@
1
1
  # __APP_NAME__
2
2
 
3
- Generated by OpenAdminJS.
3
+ Generated by [OpenAdminJS](https://openadminjs.dev).
4
+
5
+ ## Stack
6
+
7
+ - **API** — Nest.js 10 + Prisma 6 (port 4000)
8
+ - **Admin** — Next.js 15 back-office (port 3000)
9
+ - **Web** — Next.js 15 public site (port 3001)
10
+
11
+ ## Getting started
4
12
 
5
13
  ```bash
6
14
  pnpm install
7
- docker compose up -d
8
15
  pnpm db:migrate
9
16
  pnpm db:seed
10
17
  pnpm dev
11
18
  ```
12
19
 
13
- Superadmin credentials are created during `pnpm db:seed`.
20
+ Admin panel → http://localhost:3000
21
+ API + Swagger → http://localhost:4000/api/docs
22
+ Public site → http://localhost:3001
23
+
24
+ ## Useful commands
25
+
26
+ | Command | Description |
27
+ |---|---|
28
+ | `pnpm dev` | Start API + admin in parallel |
29
+ | `pnpm db:migrate` | Run Prisma migrations |
30
+ | `pnpm db:seed` | Seed database (creates superadmin) |
31
+ | `pnpm db:studio` | Open Prisma Studio |
32
+ | `pnpm build` | Build all workspaces |
33
+ | `pnpm test` | Run all tests |
34
+ | `pnpm lint` | Type-check all workspaces |
@@ -0,0 +1,51 @@
1
+ import { NextRequest, NextResponse } from "next/server";
2
+ import { TOKEN_COOKIE_AT, TOKEN_COOKIE_RT } from "../../../../lib/tokens";
3
+
4
+ const API_URL =
5
+ typeof process !== "undefined" && process.env.NEXT_PUBLIC_API_URL
6
+ ? process.env.NEXT_PUBLIC_API_URL
7
+ : "http://localhost:4000";
8
+
9
+ const COOKIE_OPTS = {
10
+ path: "/",
11
+ maxAge: 60 * 60 * 24 * 7,
12
+ sameSite: "lax" as const,
13
+ secure: process.env.NODE_ENV === "production",
14
+ httpOnly: false
15
+ } as const;
16
+
17
+ export async function POST(req: NextRequest) {
18
+ const body = await req.json().catch(() => null);
19
+ if (!body) return NextResponse.json({ message: "Invalid request body" }, { status: 400 });
20
+
21
+ const upstream = await fetch(`${API_URL}/auth/login`, {
22
+ method: "POST",
23
+ headers: { "content-type": "application/json" },
24
+ body: JSON.stringify(body)
25
+ }).catch(() => null);
26
+
27
+ if (!upstream) {
28
+ return NextResponse.json(
29
+ { message: "Server error while signing in. Check that the API is running." },
30
+ { status: 502 }
31
+ );
32
+ }
33
+
34
+ const data = (await upstream.json().catch(() => ({}))) as {
35
+ accessToken?: string;
36
+ refreshToken?: string;
37
+ message?: string;
38
+ };
39
+
40
+ if (!upstream.ok || !data.accessToken || !data.refreshToken) {
41
+ return NextResponse.json(
42
+ { message: data.message ?? "Invalid credentials" },
43
+ { status: upstream.status }
44
+ );
45
+ }
46
+
47
+ const res = NextResponse.json({ ok: true });
48
+ res.cookies.set(TOKEN_COOKIE_AT, data.accessToken, COOKIE_OPTS);
49
+ res.cookies.set(TOKEN_COOKIE_RT, data.refreshToken, COOKIE_OPTS);
50
+ return res;
51
+ }
@@ -0,0 +1,11 @@
1
+ import { NextResponse } from "next/server";
2
+ import { TOKEN_COOKIE_AT, TOKEN_COOKIE_RT } from "../../../../lib/tokens";
3
+
4
+ const CLEAR_OPTS = { path: "/", maxAge: 0, sameSite: "lax" as const, httpOnly: false } as const;
5
+
6
+ export async function POST() {
7
+ const res = NextResponse.json({ ok: true });
8
+ res.cookies.set(TOKEN_COOKIE_AT, "", CLEAR_OPTS);
9
+ res.cookies.set(TOKEN_COOKIE_RT, "", CLEAR_OPTS);
10
+ return res;
11
+ }
@@ -0,0 +1,46 @@
1
+ import { NextRequest, NextResponse } from "next/server";
2
+ import { TOKEN_COOKIE_AT, TOKEN_COOKIE_RT } from "../../../../lib/tokens";
3
+
4
+ const API_URL =
5
+ typeof process !== "undefined" && process.env.NEXT_PUBLIC_API_URL
6
+ ? process.env.NEXT_PUBLIC_API_URL
7
+ : "http://localhost:4000";
8
+
9
+ const COOKIE_OPTS = {
10
+ path: "/",
11
+ maxAge: 60 * 60 * 24 * 7,
12
+ sameSite: "lax" as const,
13
+ secure: process.env.NODE_ENV === "production",
14
+ httpOnly: false
15
+ } as const;
16
+
17
+ export async function POST(req: NextRequest) {
18
+ const rt = req.cookies.get(TOKEN_COOKIE_RT)?.value;
19
+ if (!rt) return NextResponse.json({ message: "No refresh token" }, { status: 401 });
20
+
21
+ const upstream = await fetch(`${API_URL}/auth/refresh`, {
22
+ method: "POST",
23
+ headers: { "content-type": "application/json" },
24
+ body: JSON.stringify({ refreshToken: rt, realm: "admin" })
25
+ }).catch(() => null);
26
+
27
+ if (!upstream) return NextResponse.json({ message: "API unavailable" }, { status: 502 });
28
+
29
+ const data = (await upstream.json().catch(() => ({}))) as {
30
+ accessToken?: string;
31
+ refreshToken?: string;
32
+ message?: string;
33
+ };
34
+
35
+ if (!upstream.ok || !data.accessToken || !data.refreshToken) {
36
+ const res = NextResponse.json({ message: data.message ?? "Refresh failed" }, { status: 401 });
37
+ res.cookies.set(TOKEN_COOKIE_AT, "", { ...COOKIE_OPTS, maxAge: 0 });
38
+ res.cookies.set(TOKEN_COOKIE_RT, "", { ...COOKIE_OPTS, maxAge: 0 });
39
+ return res;
40
+ }
41
+
42
+ const res = NextResponse.json({ ok: true });
43
+ res.cookies.set(TOKEN_COOKIE_AT, data.accessToken, COOKIE_OPTS);
44
+ res.cookies.set(TOKEN_COOKIE_RT, data.refreshToken, COOKIE_OPTS);
45
+ return res;
46
+ }
@@ -0,0 +1,253 @@
1
+ "use client";
2
+
3
+ import { useEffect, useMemo, useState } from "react";
4
+ import { AppShell } from "../../components/app-shell";
5
+ import { api } from "../../lib/api";
6
+
7
+ type ApiTokenRecord = {
8
+ id: string;
9
+ name: string;
10
+ scopes: string[];
11
+ revokedAt: string | null;
12
+ createdAt: string;
13
+ };
14
+
15
+ type AuditLogRecord = {
16
+ id: string;
17
+ action: string;
18
+ resourceId: string | null;
19
+ userId: string | null;
20
+ createdAt: string;
21
+ };
22
+
23
+ type ListResponse<T> = {
24
+ data: T[];
25
+ meta: { total: number };
26
+ };
27
+
28
+ function maskTokenId(id: string) {
29
+ return `${id.slice(0, 6)}••••${id.slice(-4)}`;
30
+ }
31
+
32
+ export default function ApiTokensPage() {
33
+ const [tokens, setTokens] = useState<ApiTokenRecord[]>([]);
34
+ const [history, setHistory] = useState<AuditLogRecord[]>([]);
35
+ const [name, setName] = useState("");
36
+ const [scopes, setScopes] = useState("read:all,write:posts");
37
+ const [plainToken, setPlainToken] = useState<string | null>(null);
38
+ const [copied, setCopied] = useState(false);
39
+ const [error, setError] = useState<string | null>(null);
40
+ const [submitting, setSubmitting] = useState(false);
41
+ const [busyTokenId, setBusyTokenId] = useState<string | null>(null);
42
+
43
+ const parsedScopes = useMemo(
44
+ () =>
45
+ scopes
46
+ .split(",")
47
+ .map((scope) => scope.trim())
48
+ .filter(Boolean),
49
+ [scopes]
50
+ );
51
+
52
+ async function loadData() {
53
+ try {
54
+ const [tokenRes, auditRes] = await Promise.all([
55
+ api<ListResponse<ApiTokenRecord>>("/admin/resources/api-tokens?sort=createdAt:desc&limit=50"),
56
+ api<ListResponse<AuditLogRecord>>("/admin/resources/audit-logs?filter[resource]=api-tokens&sort=createdAt:desc&limit=15")
57
+ ]);
58
+ setTokens(tokenRes.data ?? []);
59
+ setHistory(auditRes.data ?? []);
60
+ setError(null);
61
+ } catch (loadError) {
62
+ setError(loadError instanceof Error ? loadError.message : "Failed to load API token data");
63
+ }
64
+ }
65
+
66
+ useEffect(() => {
67
+ loadData();
68
+ }, []);
69
+
70
+ async function createToken(event: React.FormEvent<HTMLFormElement>) {
71
+ event.preventDefault();
72
+ setSubmitting(true);
73
+ setError(null);
74
+ setCopied(false);
75
+ try {
76
+ const created = await api<{ plainToken?: string }>("/admin/resources/api-tokens", {
77
+ method: "POST",
78
+ body: JSON.stringify({ name: name || "Token", scopes: parsedScopes })
79
+ });
80
+ setPlainToken(created.plainToken ?? null);
81
+ setName("");
82
+ await loadData();
83
+ } catch (createError) {
84
+ setError(createError instanceof Error ? createError.message : "Failed to create token");
85
+ } finally {
86
+ setSubmitting(false);
87
+ }
88
+ }
89
+
90
+ async function revokeToken(id: string) {
91
+ setBusyTokenId(id);
92
+ setError(null);
93
+ try {
94
+ await api(`/admin/resources/api-tokens/${id}/actions/revoke`, { method: "POST" });
95
+ await loadData();
96
+ } catch (revokeError) {
97
+ setError(revokeError instanceof Error ? revokeError.message : "Failed to revoke token");
98
+ } finally {
99
+ setBusyTokenId(null);
100
+ }
101
+ }
102
+
103
+ async function copyPlainToken() {
104
+ if (!plainToken) return;
105
+ try {
106
+ await navigator.clipboard.writeText(plainToken);
107
+ setCopied(true);
108
+ } catch {
109
+ setCopied(false);
110
+ }
111
+ }
112
+
113
+ return (
114
+ <AppShell>
115
+ <div className="space-y-5">
116
+ <div>
117
+ <p className="text-xs font-bold uppercase tracking-wide text-[#0b8585]">Security</p>
118
+ <h1 className="mt-1 text-3xl font-bold tracking-normal text-[#24324b]">API Tokens</h1>
119
+ <p className="text-sm text-[#637083]">Issue scoped tokens, reveal once, and revoke instantly.</p>
120
+ </div>
121
+
122
+ {error ? <p className="rounded-xl bg-red-50 px-3 py-2 text-sm text-red-700">{error}</p> : null}
123
+
124
+ {plainToken ? (
125
+ <div className="rounded-2xl border border-amber-200 bg-amber-50 p-4">
126
+ <p className="text-sm font-semibold text-amber-900">Token generated successfully. Copy it now: it will never be shown again.</p>
127
+ <code className="mt-2 block overflow-auto rounded-xl bg-white p-3 text-xs text-amber-900">{plainToken}</code>
128
+ <button
129
+ type="button"
130
+ onClick={copyPlainToken}
131
+ className="mt-3 rounded-lg border border-amber-300 bg-white px-3 py-1.5 text-xs font-semibold text-amber-900"
132
+ >
133
+ {copied ? "Copied" : "Copy token"}
134
+ </button>
135
+ </div>
136
+ ) : null}
137
+
138
+ <div className="grid gap-4 lg:grid-cols-3">
139
+ <section className="rounded-2xl border border-[#e4e8f0] bg-white p-5 shadow-[0_12px_34px_rgba(36,50,75,0.07)] lg:col-span-2">
140
+ <h2 className="text-lg font-bold text-[#24324b]">Create token</h2>
141
+ <form onSubmit={createToken} className="mt-4 grid gap-3">
142
+ <label className="space-y-1">
143
+ <span className="text-xs font-semibold uppercase tracking-wide text-[#637083]">Name</span>
144
+ <input
145
+ value={name}
146
+ onChange={(event) => setName(event.target.value)}
147
+ className="w-full rounded-xl border border-[#e4e8f0] bg-[#f6f8fc] px-3 py-2 text-sm"
148
+ placeholder="CI deploy token"
149
+ />
150
+ </label>
151
+ <label className="space-y-1">
152
+ <span className="text-xs font-semibold uppercase tracking-wide text-[#637083]">Scopes (comma separated)</span>
153
+ <input
154
+ value={scopes}
155
+ onChange={(event) => setScopes(event.target.value)}
156
+ className="w-full rounded-xl border border-[#e4e8f0] bg-[#f6f8fc] px-3 py-2 text-sm"
157
+ placeholder="read:all,write:posts"
158
+ />
159
+ </label>
160
+ <button
161
+ type="submit"
162
+ disabled={submitting}
163
+ className="w-fit rounded-xl bg-gradient-to-r from-[#2454ff] to-[#0ea5a4] px-4 py-2 text-sm font-bold text-white disabled:cursor-not-allowed disabled:opacity-65"
164
+ >
165
+ {submitting ? "Creating..." : "Create token"}
166
+ </button>
167
+ </form>
168
+ </section>
169
+
170
+ <section className="rounded-2xl border border-[#e4e8f0] bg-white p-5 shadow-[0_12px_34px_rgba(36,50,75,0.07)]">
171
+ <h2 className="text-lg font-bold text-[#24324b]">Summary</h2>
172
+ <div className="mt-3 space-y-2 text-sm">
173
+ <div className="flex items-center justify-between">
174
+ <span className="text-[#637083]">Total tokens</span>
175
+ <span className="font-semibold text-[#24324b]">{tokens.length}</span>
176
+ </div>
177
+ <div className="flex items-center justify-between">
178
+ <span className="text-[#637083]">Active</span>
179
+ <span className="font-semibold text-[#24324b]">{tokens.filter((token) => !token.revokedAt).length}</span>
180
+ </div>
181
+ <div className="flex items-center justify-between">
182
+ <span className="text-[#637083]">Revoked</span>
183
+ <span className="font-semibold text-[#24324b]">{tokens.filter((token) => token.revokedAt).length}</span>
184
+ </div>
185
+ </div>
186
+ </section>
187
+ </div>
188
+
189
+ <section className="rounded-2xl border border-[#e4e8f0] bg-white p-5 shadow-[0_12px_34px_rgba(36,50,75,0.07)]">
190
+ <h2 className="text-lg font-bold text-[#24324b]">Issued tokens</h2>
191
+ <div className="mt-4 overflow-hidden rounded-xl border border-[#e4e8f0]">
192
+ <table className="w-full text-left text-sm">
193
+ <thead className="bg-[#f6f8fc] text-xs uppercase text-[#637083]">
194
+ <tr>
195
+ <th className="px-3 py-2">Name</th>
196
+ <th className="px-3 py-2">Token ID</th>
197
+ <th className="px-3 py-2">Scopes</th>
198
+ <th className="px-3 py-2">Status</th>
199
+ <th className="px-3 py-2 text-right">Action</th>
200
+ </tr>
201
+ </thead>
202
+ <tbody>
203
+ {tokens.map((token) => (
204
+ <tr key={token.id} className="border-t border-[#eef2fb]">
205
+ <td className="px-3 py-2 font-semibold text-[#24324b]">{token.name}</td>
206
+ <td className="px-3 py-2 text-[#637083]">{maskTokenId(token.id)}</td>
207
+ <td className="px-3 py-2 text-[#637083]">{token.scopes.join(", ") || "*"}</td>
208
+ <td className="px-3 py-2">
209
+ <span className={`rounded-full px-2 py-1 text-xs font-semibold ${token.revokedAt ? "bg-red-100 text-red-700" : "bg-emerald-100 text-emerald-700"}`}>
210
+ {token.revokedAt ? "Revoked" : "Active"}
211
+ </span>
212
+ </td>
213
+ <td className="px-3 py-2 text-right">
214
+ <button
215
+ type="button"
216
+ onClick={() => revokeToken(token.id)}
217
+ disabled={Boolean(token.revokedAt) || busyTokenId === token.id}
218
+ className="rounded-lg border border-[#e4e8f0] bg-white px-3 py-1.5 text-xs font-semibold text-[#24324b] disabled:cursor-not-allowed disabled:opacity-55"
219
+ >
220
+ {busyTokenId === token.id ? "Revoking..." : token.revokedAt ? "Revoked" : "Revoke"}
221
+ </button>
222
+ </td>
223
+ </tr>
224
+ ))}
225
+ {tokens.length === 0 ? (
226
+ <tr>
227
+ <td className="px-3 py-6 text-center text-[#637083]" colSpan={5}>
228
+ No API tokens issued yet.
229
+ </td>
230
+ </tr>
231
+ ) : null}
232
+ </tbody>
233
+ </table>
234
+ </div>
235
+ </section>
236
+
237
+ <section className="rounded-2xl border border-[#e4e8f0] bg-white p-5 shadow-[0_12px_34px_rgba(36,50,75,0.07)]">
238
+ <h2 className="text-lg font-bold text-[#24324b]">Revoke history</h2>
239
+ <div className="mt-4 space-y-2">
240
+ {history.map((entry) => (
241
+ <div key={entry.id} className="flex flex-wrap items-center justify-between gap-2 rounded-xl border border-[#eef2fb] bg-[#f9fbff] px-3 py-2 text-sm">
242
+ <span className="font-semibold text-[#24324b]">{entry.action}</span>
243
+ <span className="text-[#637083]">resourceId: {entry.resourceId ?? "-"}</span>
244
+ <span className="text-[#637083]">{new Date(entry.createdAt).toLocaleString()}</span>
245
+ </div>
246
+ ))}
247
+ {history.length === 0 ? <p className="text-sm text-[#637083]">No token audit events yet.</p> : null}
248
+ </div>
249
+ </section>
250
+ </div>
251
+ </AppShell>
252
+ );
253
+ }