openadminjs 0.1.15 → 0.1.17

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 (92) hide show
  1. package/dist/create-project.js +4 -1
  2. package/dist/index.js +127 -0
  3. package/package.json +2 -2
  4. package/template/apps/admin/.storybook/main.ts +12 -0
  5. package/template/apps/admin/.storybook/preview.ts +10 -0
  6. package/template/apps/admin/app/dashboard/page.tsx +357 -277
  7. package/template/apps/admin/app/layout.tsx +5 -1
  8. package/template/apps/admin/app/login/page.tsx +38 -0
  9. package/template/apps/admin/app/resources/[resource]/page.tsx +15 -1
  10. package/template/apps/admin/app/settings/page.tsx +40 -2
  11. package/template/apps/admin/app/system-logs/page.tsx +212 -0
  12. package/template/apps/admin/components/api-error-banner.tsx +26 -0
  13. package/template/apps/admin/components/app-shell.tsx +92 -18
  14. package/template/apps/admin/components/logo.stories.tsx +24 -0
  15. package/template/apps/admin/components/resource-form.tsx +47 -0
  16. package/template/apps/admin/components/resource-table.tsx +417 -44
  17. package/template/apps/admin/lib/api.ts +44 -1
  18. package/template/apps/admin/lib/resource-table-prefs.ts +57 -0
  19. package/template/apps/admin/package.json +6 -0
  20. package/template/apps/admin/storybook-static/370.e922f076.iframe.bundle.js +9 -0
  21. package/template/apps/admin/storybook-static/389.c0dd6bde.iframe.bundle.js +818 -0
  22. package/template/apps/admin/storybook-static/990.36428b6c.iframe.bundle.js +25 -0
  23. package/template/apps/admin/storybook-static/favicon-wrapper.svg +46 -0
  24. package/template/apps/admin/storybook-static/favicon.svg +1 -0
  25. package/template/apps/admin/storybook-static/iframe.html +560 -0
  26. package/template/apps/admin/storybook-static/index.html +139 -0
  27. package/template/apps/admin/storybook-static/index.json +1 -0
  28. package/template/apps/admin/storybook-static/logo-stories.c470fc8c.iframe.bundle.js +1 -0
  29. package/template/apps/admin/storybook-static/main.743ea6f2.iframe.bundle.js +2550 -0
  30. package/template/apps/admin/storybook-static/mocker-runtime-injected.js +2 -0
  31. package/template/apps/admin/storybook-static/nunito-sans-bold-italic.woff2 +0 -0
  32. package/template/apps/admin/storybook-static/nunito-sans-bold.woff2 +0 -0
  33. package/template/apps/admin/storybook-static/nunito-sans-italic.woff2 +0 -0
  34. package/template/apps/admin/storybook-static/nunito-sans-regular.woff2 +0 -0
  35. package/template/apps/admin/storybook-static/project.json +1 -0
  36. package/template/apps/admin/storybook-static/runtime~main.6f822e3b.iframe.bundle.js +2 -0
  37. package/template/apps/admin/storybook-static/sb-addons/onboarding-1/manager-bundle.js +97 -0
  38. package/template/apps/admin/storybook-static/sb-addons/storybook-core-server-presets-0/common-manager-bundle.js +630 -0
  39. package/template/apps/admin/storybook-static/sb-common-assets/favicon-wrapper.svg +46 -0
  40. package/template/apps/admin/storybook-static/sb-common-assets/favicon.svg +1 -0
  41. package/template/apps/admin/storybook-static/sb-common-assets/nunito-sans-bold-italic.woff2 +0 -0
  42. package/template/apps/admin/storybook-static/sb-common-assets/nunito-sans-bold.woff2 +0 -0
  43. package/template/apps/admin/storybook-static/sb-common-assets/nunito-sans-italic.woff2 +0 -0
  44. package/template/apps/admin/storybook-static/sb-common-assets/nunito-sans-regular.woff2 +0 -0
  45. package/template/apps/admin/storybook-static/sb-manager/globals-runtime.js +76309 -0
  46. package/template/apps/admin/storybook-static/sb-manager/globals.js +24 -0
  47. package/template/apps/admin/storybook-static/sb-manager/manager-stores.js +23 -0
  48. package/template/apps/admin/storybook-static/sb-manager/runtime.js +26078 -0
  49. package/template/apps/admin/storybook-static/sb-preview/globals.js +20 -0
  50. package/template/apps/admin/storybook-static/sb-preview/runtime.js +35472 -0
  51. package/template/apps/api/package.json +13 -2
  52. package/template/apps/api/plugins.manifest.example.json +12 -0
  53. package/template/apps/api/src/admin/admin-logs.controller.ts +31 -0
  54. package/template/apps/api/src/admin/admin-plugins.controller.ts +5 -0
  55. package/template/apps/api/src/admin/admin-plugins.service.ts +11 -0
  56. package/template/apps/api/src/admin/admin-resource.service.ts +235 -1
  57. package/template/apps/api/src/admin/admin.controller.ts +35 -0
  58. package/template/apps/api/src/admin/admin.module.ts +6 -3
  59. package/template/apps/api/src/admin/dto/resource-bulk.dto.ts +17 -0
  60. package/template/apps/api/src/admin/dto/resource-reorder.dto.ts +17 -0
  61. package/template/apps/api/src/admin/dto/resource-upload.dto.ts +20 -0
  62. package/template/apps/api/src/app.module.ts +45 -5
  63. package/template/apps/api/src/auth/auth.module.ts +5 -3
  64. package/template/apps/api/src/auth/auth.service.test.ts +6 -3
  65. package/template/apps/api/src/auth/auth.service.ts +84 -0
  66. package/template/apps/api/src/auth/sso-oidc.controller.ts +78 -0
  67. package/template/apps/api/src/auth/sso-oidc.service.test.ts +84 -0
  68. package/template/apps/api/src/auth/sso-oidc.service.ts +281 -0
  69. package/template/apps/api/src/common/app-logger.service.ts +138 -0
  70. package/template/apps/api/src/common/auth.guard.test.ts +1 -0
  71. package/template/apps/api/src/common/auth.guard.ts +15 -1
  72. package/template/apps/api/src/common/current-user.decorator.ts +6 -2
  73. package/template/apps/api/src/common/logging.module.ts +10 -0
  74. package/template/apps/api/src/common/request-logging.interceptor.ts +70 -0
  75. package/template/apps/api/src/graphql/admin-resources.resolver.test.ts +44 -0
  76. package/template/apps/api/src/graphql/admin-resources.resolver.ts +65 -0
  77. package/template/apps/api/src/graphql/graphql.module.ts +26 -0
  78. package/template/apps/api/src/main.ts +2 -0
  79. package/template/apps/api/src/plugins/bundled/registry.ts +3 -1
  80. package/template/apps/api/src/plugins/bundled/webhook.plugin.ts +64 -0
  81. package/template/apps/api/src/resources/categories.resource.ts +1 -0
  82. package/template/apps/api/src/resources/system.resource.ts +1 -0
  83. package/template/packages/core/src/index.ts +5 -0
  84. package/template/packages/core/vitest.config.ts +9 -0
  85. package/template/packages/resource/package.json +11 -0
  86. package/template/packages/resource/src/index.test.ts +45 -0
  87. package/template/packages/resource/src/index.ts +63 -0
  88. package/template/prisma/schema.prisma +5 -0
  89. package/template/packages/core/src/index.js +0 -1
  90. package/template/packages/permissions/src/blueprints.js +0 -57
  91. package/template/packages/permissions/src/index.js +0 -11
  92. package/template/packages/resource/src/index.js +0 -177
@@ -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.15",
3
+ "version": "0.1.17",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "openadminjs": "dist/index.js"
@@ -31,7 +31,7 @@
31
31
  "build": "node ../../scripts/sync-template.mjs && tsc -p tsconfig.json && node ../../scripts/make-executable.mjs dist/index.js",
32
32
  "lint": "tsc -p tsconfig.json --noEmit",
33
33
  "typecheck": "tsc -p tsconfig.json --noEmit",
34
- "test": "vitest run"
34
+ "test": "pnpm run sync-template && vitest run"
35
35
  },
36
36
  "dependencies": {
37
37
  "@clack/prompts": "^0.8.2",
@@ -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;