openadminjs 0.1.16 → 0.1.18

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 (76) hide show
  1. package/LICENSE +21 -0
  2. package/dist/create-project.js +4 -1
  3. package/dist/index.js +127 -0
  4. package/package.json +10 -11
  5. package/template/apps/admin/.storybook/main.ts +12 -0
  6. package/template/apps/admin/.storybook/preview.ts +10 -0
  7. package/template/apps/admin/app/dashboard/page.tsx +357 -277
  8. package/template/apps/admin/app/layout.tsx +5 -1
  9. package/template/apps/admin/app/login/page.tsx +38 -0
  10. package/template/apps/admin/app/resources/[resource]/page.tsx +15 -1
  11. package/template/apps/admin/app/settings/page.tsx +40 -2
  12. package/template/apps/admin/app/system-logs/page.tsx +212 -0
  13. package/template/apps/admin/components/api-error-banner.tsx +26 -0
  14. package/template/apps/admin/components/app-shell.tsx +92 -18
  15. package/template/apps/admin/components/logo.stories.tsx +24 -0
  16. package/template/apps/admin/components/resource-form.tsx +47 -0
  17. package/template/apps/admin/components/resource-table.tsx +417 -44
  18. package/template/apps/admin/lib/api.ts +44 -1
  19. package/template/apps/admin/lib/resource-table-prefs.ts +57 -0
  20. package/template/apps/admin/package.json +8 -2
  21. package/template/apps/api/package.json +28 -15
  22. package/template/apps/api/plugins.manifest.example.json +12 -0
  23. package/template/apps/api/prisma.config.ts +6 -0
  24. package/template/apps/api/src/admin/admin-ai.controller.ts +3 -2
  25. package/template/apps/api/src/admin/admin-logs.controller.ts +31 -0
  26. package/template/apps/api/src/admin/admin-plugins.controller.ts +5 -0
  27. package/template/apps/api/src/admin/admin-plugins.service.ts +11 -0
  28. package/template/apps/api/src/admin/admin-resource.service.ts +235 -1
  29. package/template/apps/api/src/admin/admin.controller.ts +35 -0
  30. package/template/apps/api/src/admin/admin.module.ts +6 -3
  31. package/template/apps/api/src/admin/dto/resource-bulk.dto.ts +17 -0
  32. package/template/apps/api/src/admin/dto/resource-reorder.dto.ts +17 -0
  33. package/template/apps/api/src/admin/dto/resource-upload.dto.ts +20 -0
  34. package/template/apps/api/src/app.module.ts +45 -5
  35. package/template/apps/api/src/auth/auth.module.ts +4 -2
  36. package/template/apps/api/src/auth/auth.service.test.ts +6 -3
  37. package/template/apps/api/src/auth/auth.service.ts +84 -0
  38. package/template/apps/api/src/auth/sso-oidc.controller.ts +78 -0
  39. package/template/apps/api/src/auth/sso-oidc.service.test.ts +84 -0
  40. package/template/apps/api/src/auth/sso-oidc.service.ts +281 -0
  41. package/template/apps/api/src/common/app-logger.service.ts +138 -0
  42. package/template/apps/api/src/common/auth.guard.test.ts +1 -0
  43. package/template/apps/api/src/common/auth.guard.ts +15 -1
  44. package/template/apps/api/src/common/current-user.decorator.ts +6 -2
  45. package/template/apps/api/src/common/logging.module.ts +10 -0
  46. package/template/apps/api/src/common/request-logging.interceptor.ts +70 -0
  47. package/template/apps/api/src/graphql/admin-resources.resolver.test.ts +44 -0
  48. package/template/apps/api/src/graphql/admin-resources.resolver.ts +65 -0
  49. package/template/apps/api/src/graphql/graphql.module.ts +26 -0
  50. package/template/apps/api/src/main.ts +2 -0
  51. package/template/apps/api/src/plugins/bundled/registry.ts +3 -1
  52. package/template/apps/api/src/plugins/bundled/webhook.plugin.ts +64 -0
  53. package/template/apps/api/src/resources/categories.resource.ts +1 -0
  54. package/template/apps/api/src/resources/system.resource.ts +1 -0
  55. package/template/apps/web/package.json +2 -2
  56. package/template/package.json +1 -1
  57. package/template/packages/auth/package.json +1 -1
  58. package/template/packages/brand/package.json +1 -1
  59. package/template/packages/brand/src/generate-assets.mjs +12 -5
  60. package/template/packages/core/package.json +1 -1
  61. package/template/packages/core/src/index.ts +5 -0
  62. package/template/packages/core/vitest.config.ts +9 -0
  63. package/template/packages/mail/package.json +3 -3
  64. package/template/packages/notifications/package.json +1 -1
  65. package/template/packages/permissions/package.json +1 -1
  66. package/template/packages/plugin-sdk/package.json +1 -1
  67. package/template/packages/queue/package.json +1 -1
  68. package/template/packages/resource/package.json +12 -1
  69. package/template/packages/resource/src/index.test.ts +45 -0
  70. package/template/packages/resource/src/index.ts +63 -0
  71. package/template/packages/storage/package.json +1 -1
  72. package/template/prisma/schema.prisma +5 -0
  73. package/template/packages/core/src/index.js +0 -1
  74. package/template/packages/permissions/src/blueprints.js +0 -57
  75. package/template/packages/permissions/src/index.js +0 -11
  76. package/template/packages/resource/src/index.js +0 -177
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 OpenAdminJS contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -181,8 +181,11 @@ export function createProject(options) {
181
181
  // Write the real .env for apps/api so the app starts and seed runs without
182
182
  // manual intervention. Superadmin credentials are picked up by prisma/seed.ts
183
183
  // via the SUPERADMIN_EMAIL / SUPERADMIN_PASSWORD env vars.
184
+ // Only when the template is a full-stack scaffold (has apps/api); skip for minimal
185
+ // templates (e.g. npx smoke fixtures) that intentionally omit apps/api.
186
+ const templateApiDir = join(options.templateDir, "apps", "api");
184
187
  const apiEnvDir = join(targetDir, "apps", "api");
185
- if (existsSync(apiEnvDir)) {
188
+ if (existsSync(templateApiDir)) {
186
189
  mkdirSync(apiEnvDir, { recursive: true });
187
190
  writeFileSync(join(apiEnvDir, ".env"), [
188
191
  `DATABASE_URL=${options.databaseUrl}`,
package/dist/index.js CHANGED
@@ -101,6 +101,112 @@ function generatePlugin(pluginId, options) {
101
101
  writeFileSync(target, `import type { OpenAdminPlugin } from "@openadminjs/plugin-sdk";\n\nexport const ${slug.replace(/-([a-z])/g, (_, c) => c.toUpperCase())}Plugin: OpenAdminPlugin = {\n id: "${safeId}",\n version: "0.1.0",\n register({ registerSurface }) {\n registerSurface({\n seo: {\n metadata({ resourceName, record }) {\n if (resourceName !== "posts") return {};\n return { title: record.title ?? "Untitled" };\n }\n }\n });\n }\n};\n`);
102
102
  console.log(pc.green(`Created ${target}`));
103
103
  }
104
+ function normalizeFieldType(raw) {
105
+ const t = raw.trim().toLowerCase();
106
+ if (["number", "int", "integer", "float", "decimal"].includes(t))
107
+ return "number";
108
+ if (["boolean", "bool"].includes(t))
109
+ return "boolean";
110
+ if (["datetime", "date", "timestamp"].includes(t))
111
+ return "date";
112
+ if (["json", "object"].includes(t))
113
+ return "json";
114
+ return "text";
115
+ }
116
+ function prismaFieldFragment(fieldName, fieldType, required) {
117
+ switch (fieldType) {
118
+ case "number":
119
+ return `${fieldName} Int${required ? " @default(0)" : "?"}`;
120
+ case "boolean":
121
+ return `${fieldName} Boolean${required ? " @default(false)" : "?"}`;
122
+ case "date":
123
+ return `${fieldName} DateTime${required ? "" : "?"}`;
124
+ case "json":
125
+ return `${fieldName} Json${required ? "" : "?"}`;
126
+ default:
127
+ return `${fieldName} String${required ? "" : "?"}`;
128
+ }
129
+ }
130
+ function resolveResourceFile(raw) {
131
+ const targetDir = join(process.cwd(), "apps/api/src/resources");
132
+ const clean = raw.replace(/\.resource\.ts$/i, "").replace(/^.*\//, "");
133
+ const candidates = [
134
+ clean,
135
+ modelNameToResourceSlug(clean),
136
+ clean.endsWith("s") ? clean.slice(0, -1) : `${clean}s`,
137
+ clean.endsWith("s") ? modelNameToResourceSlug(clean.slice(0, -1)) : modelNameToResourceSlug(`${clean}s`)
138
+ ];
139
+ const seen = new Set();
140
+ for (const c of candidates) {
141
+ if (!c)
142
+ continue;
143
+ const filepath = join(targetDir, `${c}.resource.ts`);
144
+ if (seen.has(filepath))
145
+ continue;
146
+ seen.add(filepath);
147
+ if (existsSync(filepath))
148
+ return filepath;
149
+ }
150
+ return null;
151
+ }
152
+ function startCase(input) {
153
+ const withSpaces = input
154
+ .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
155
+ .replace(/[_-]+/g, " ")
156
+ .trim();
157
+ return withSpaces ? withSpaces[0].toUpperCase() + withSpaces.slice(1) : input;
158
+ }
159
+ function generateResourceField(resourceArg, fieldName, fieldTypeRaw, options) {
160
+ const target = resolveResourceFile(resourceArg);
161
+ if (!target) {
162
+ console.error(pc.red(`Could not find *.resource.ts for "${resourceArg}" under apps/api/src/resources`));
163
+ process.exitCode = 1;
164
+ return;
165
+ }
166
+ if (!/^[a-z][a-zA-Z0-9]*$/.test(fieldName)) {
167
+ console.error(pc.red("fieldName must be camelCase"));
168
+ process.exitCode = 1;
169
+ return;
170
+ }
171
+ const fieldType = normalizeFieldType(fieldTypeRaw);
172
+ const content = readFileSync(target, "utf8");
173
+ if (new RegExp(`^\\s*${fieldName}\\s*:`, "m").test(content) && !options.force) {
174
+ console.error(pc.red(`Field "${fieldName}" already present. Use --force to add anyway.`));
175
+ process.exitCode = 1;
176
+ return;
177
+ }
178
+ const fieldsBlock = content.match(/fields:\s*\{[\s\S]*?\n\s*\},\n\s*(permissions|actions|i18n|seo|listScope|hooks|})/m);
179
+ if (fieldsBlock?.index == null) {
180
+ console.error(pc.red('Could not locate fields block (`fields: { ... }`).'));
181
+ process.exitCode = 1;
182
+ return;
183
+ }
184
+ const fieldsStart = fieldsBlock.index;
185
+ const fieldsEnd = fieldsStart + fieldsBlock[0].length;
186
+ const head = content.slice(0, fieldsEnd - fieldsBlock[1].length - 1);
187
+ const tail = content.slice(fieldsEnd - fieldsBlock[1].length - 1);
188
+ const lb = head.lastIndexOf("},");
189
+ if (lb < 0) {
190
+ console.error(pc.red("Malformed resource file near fields."));
191
+ process.exitCode = 1;
192
+ return;
193
+ }
194
+ const labelJson = JSON.stringify(options.label?.trim() || startCase(fieldName));
195
+ const attributes = [
196
+ `type: '${fieldType}'`,
197
+ `label: ${labelJson}`,
198
+ options.required ? "required: true" : "",
199
+ options.list ? "list: true" : "",
200
+ options.sortable ? "sortable: true" : "",
201
+ options.filterable ? "filterable: true" : "",
202
+ options.searchable ? "searchable: true" : ""
203
+ ].filter(Boolean);
204
+ const snippet = `\n ${fieldName}: { ${attributes.join(", ")} },`;
205
+ writeFileSync(target, `${head.slice(0, lb + 2)}${snippet}${tail}`);
206
+ console.log(pc.green(`Updated ${target}`));
207
+ console.log(pc.dim("// Prisma model fragment — merge into schema.prisma, then pnpm db:migrate"));
208
+ console.log(pc.dim(`// ${prismaFieldFragment(fieldName, fieldType, Boolean(options.required))}`));
209
+ }
104
210
  cli.command("dev", "Start API and admin apps").action(() => runScript("dev"));
105
211
  cli.command("create [projectName]", "Create a new OpenAdminJS project").action(async (projectName) => {
106
212
  try {
@@ -148,6 +254,27 @@ function runGenerateCommand(kind, name, options) {
148
254
  console.error(pc.red(`Unknown generate kind: ${kind}. Use resource or plugin.`));
149
255
  process.exitCode = 1;
150
256
  }
257
+ cli
258
+ .command("generate field <resource> <fieldName>", "Append a field to an existing resource and emit Prisma fragment")
259
+ .option("--type <type>", "Field type (text, number, boolean, date, json)", { default: "text" })
260
+ .option("--label <label>", "Field label override")
261
+ .option("--required", "Mark field as required")
262
+ .option("--list", "Show field in list views")
263
+ .option("--sortable", "Mark field as sortable")
264
+ .option("--filterable", "Mark field as filterable")
265
+ .option("--searchable", "Mark field as searchable")
266
+ .option("--force", "Write even when the field key already exists")
267
+ .action((resource, fieldName, options) => {
268
+ generateResourceField(resource, fieldName, options.type ?? "text", {
269
+ force: options.force,
270
+ required: options.required,
271
+ list: options.list,
272
+ sortable: options.sortable,
273
+ filterable: options.filterable,
274
+ searchable: options.searchable,
275
+ label: options.label
276
+ });
277
+ });
151
278
  cli
152
279
  .command("generate <kind> <name>", "Generate resource or plugin starter")
153
280
  .option("--force", "Overwrite existing file")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openadminjs",
3
- "version": "0.1.16",
3
+ "version": "0.1.18",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "openadminjs": "dist/index.js"
@@ -25,14 +25,6 @@
25
25
  "template",
26
26
  "README.md"
27
27
  ],
28
- "scripts": {
29
- "sync-template": "node ../../scripts/sync-template.mjs",
30
- "prepack": "pnpm run build",
31
- "build": "node ../../scripts/sync-template.mjs && tsc -p tsconfig.json && node ../../scripts/make-executable.mjs dist/index.js",
32
- "lint": "tsc -p tsconfig.json --noEmit",
33
- "typecheck": "tsc -p tsconfig.json --noEmit",
34
- "test": "vitest run"
35
- },
36
28
  "dependencies": {
37
29
  "@clack/prompts": "^0.8.2",
38
30
  "cac": "^6.7.14",
@@ -42,6 +34,13 @@
42
34
  "devDependencies": {
43
35
  "@types/fs-extra": "^11.0.4",
44
36
  "typescript": "^5.7.2",
45
- "vitest": "^2.1.8"
37
+ "vitest": "^3.2.0"
38
+ },
39
+ "scripts": {
40
+ "sync-template": "node ../../scripts/sync-template.mjs",
41
+ "build": "node ../../scripts/sync-template.mjs && tsc -p tsconfig.json && node ../../scripts/make-executable.mjs dist/index.js",
42
+ "lint": "tsc -p tsconfig.json --noEmit",
43
+ "typecheck": "tsc -p tsconfig.json --noEmit",
44
+ "test": "pnpm run sync-template && vitest run"
46
45
  }
47
- }
46
+ }
@@ -0,0 +1,12 @@
1
+ import type { StorybookConfig } from "@storybook/nextjs";
2
+
3
+ const config: StorybookConfig = {
4
+ stories: ["../components/**/*.mdx", "../components/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
5
+ addons: ["@storybook/addon-docs", "@storybook/addon-onboarding"],
6
+ framework: {
7
+ name: "@storybook/nextjs",
8
+ options: {}
9
+ }
10
+ };
11
+
12
+ export default config;
@@ -0,0 +1,10 @@
1
+ import type { Preview } from "@storybook/nextjs";
2
+ import "../app/globals.css";
3
+
4
+ const preview: Preview = {
5
+ parameters: {
6
+ layout: "centered"
7
+ }
8
+ };
9
+
10
+ export default preview;