openadminjs 0.1.11 → 0.1.12
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.
- package/README.md +8 -7
- package/dist/create-project.js +3 -8
- package/dist/create-project.test.js +3 -10
- package/dist/index.js +20 -6
- package/package.json +1 -1
- package/template/apps/api/src/admin/admin-plugins.service.ts +10 -2
- package/template/apps/api/src/admin/dto/plugins.dto.ts +18 -4
- package/template/apps/api/src/auth/auth.module.ts +3 -2
package/README.md
CHANGED
|
@@ -20,25 +20,26 @@ During scaffolding, you can choose the database driver from a list (PostgreSQL,
|
|
|
20
20
|
|
|
21
21
|
### 2. Configure environment
|
|
22
22
|
|
|
23
|
-
The scaffold wizard asks for database access and key env values (`DATABASE_URL`, `REDIS_URL`, JWT secrets) and writes ready-to-use values into `apps/api/.env
|
|
23
|
+
The scaffold wizard asks for database access and key env values (`DATABASE_URL`, `REDIS_URL`, JWT secrets) and writes ready-to-use values into `apps/api/.env` (including `SUPERADMIN_EMAIL` / `SUPERADMIN_PASSWORD` for non-interactive seed).
|
|
24
24
|
`ADMIN_ORIGIN` and `API_PORT` are prefilled with defaults (`http://localhost:3000` and `4000`) and can be changed manually if needed.
|
|
25
|
-
`.env.example`
|
|
25
|
+
New projects do **not** include a root `.env.example` or root `.env`—use `apps/api/.env` as the source of truth (you can add your own `.env.example` for your team if you want).
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
Typical `apps/api/.env` keys (after create, edit as needed):
|
|
28
28
|
|
|
29
29
|
```env
|
|
30
|
-
NODE_ENV=development
|
|
31
30
|
DATABASE_URL=postgresql://USER:PASSWORD@localhost:5432/openadminjs?schema=public
|
|
32
|
-
|
|
31
|
+
REDIS_URL=redis://localhost:6379
|
|
33
32
|
JWT_SECRET=replace-with-a-long-random-string-at-least-32-chars
|
|
34
33
|
JWT_REFRESH_SECRET=another-long-random-string
|
|
35
34
|
ADMIN_ORIGIN=http://localhost:3000
|
|
35
|
+
API_PORT=4000
|
|
36
|
+
SUPERADMIN_EMAIL=admin@localhost.dev
|
|
37
|
+
SUPERADMIN_PASSWORD=your-secure-password
|
|
36
38
|
```
|
|
37
39
|
|
|
38
|
-
Optional:
|
|
40
|
+
Optional (elsewhere / advanced):
|
|
39
41
|
|
|
40
42
|
```env
|
|
41
|
-
REDIS_URL=redis://localhost:6379
|
|
42
43
|
OPENADMIN_PLUGIN_PNPM_INSTALL=0
|
|
43
44
|
```
|
|
44
45
|
|
package/dist/create-project.js
CHANGED
|
@@ -161,7 +161,7 @@ export function createProject(options) {
|
|
|
161
161
|
errorOnExist: true,
|
|
162
162
|
filter: (source) => {
|
|
163
163
|
const segments = relative(options.templateDir, source).split(sep);
|
|
164
|
-
return !segments.some((segment) => segment === "node_modules" || segment === ".next" || segment === "dist");
|
|
164
|
+
return !segments.some((segment) => segment === "node_modules" || segment === ".next" || segment === "dist" || segment === ".env.example");
|
|
165
165
|
}
|
|
166
166
|
});
|
|
167
167
|
if (!existsSync(join(targetDir, "package.json"))) {
|
|
@@ -178,11 +178,6 @@ export function createProject(options) {
|
|
|
178
178
|
__ADMIN_ORIGIN__: options.adminOrigin,
|
|
179
179
|
__API_PORT__: options.apiPort
|
|
180
180
|
});
|
|
181
|
-
const envExamplePath = join(targetDir, ".env.example");
|
|
182
|
-
const envPath = join(targetDir, ".env");
|
|
183
|
-
if (existsSync(envExamplePath) && !existsSync(envPath)) {
|
|
184
|
-
writeFileSync(envPath, readFileSync(envExamplePath, "utf8"));
|
|
185
|
-
}
|
|
186
181
|
// Write the real .env for apps/api so the app starts and seed runs without
|
|
187
182
|
// manual intervention. Superadmin credentials are picked up by prisma/seed.ts
|
|
188
183
|
// via the SUPERADMIN_EMAIL / SUPERADMIN_PASSWORD env vars.
|
|
@@ -336,7 +331,7 @@ export async function createProjectInteractive(options = {}) {
|
|
|
336
331
|
while (!checkedRedisUrl) {
|
|
337
332
|
const entered = options.redisUrl ??
|
|
338
333
|
(await text({
|
|
339
|
-
message: "Redis URL
|
|
334
|
+
message: "Redis URL",
|
|
340
335
|
defaultValue: "redis://localhost:6379",
|
|
341
336
|
validate(value) {
|
|
342
337
|
return value.trim().length > 0 ? undefined : "Redis URL is required.";
|
|
@@ -363,7 +358,7 @@ export async function createProjectInteractive(options = {}) {
|
|
|
363
358
|
if (!retry)
|
|
364
359
|
break;
|
|
365
360
|
const next = await text({
|
|
366
|
-
message: "Redis URL
|
|
361
|
+
message: "Redis URL",
|
|
367
362
|
defaultValue: checkedRedisUrl
|
|
368
363
|
});
|
|
369
364
|
if (isCancel(next)) {
|
|
@@ -24,19 +24,12 @@ describe("create project", () => {
|
|
|
24
24
|
expect(envExample, `missing placeholder ${key}`).toContain(key);
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
|
-
it("
|
|
27
|
+
it("does not scaffold root .env.example or .env files", () => {
|
|
28
28
|
const cwd = mkdtempSync(join(tmpdir(), "openadminjs-cli-test-"));
|
|
29
29
|
try {
|
|
30
30
|
const result = createProject({ ...BASE_OPTIONS, projectName: "my-app", cwd, templateDir: defaultTemplateDir() });
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
expect(envExample).toContain("DATABASE_URL=postgresql://localhost:5432/my-app?schema=public");
|
|
34
|
-
expect(envExample).toContain("REDIS_URL=redis://localhost:6379");
|
|
35
|
-
expect(envExample).toContain("JWT_SECRET=test-jwt-secret");
|
|
36
|
-
expect(envExample).toContain("JWT_REFRESH_SECRET=test-jwt-refresh-secret");
|
|
37
|
-
expect(envExample).toContain("ADMIN_ORIGIN=http://localhost:3000");
|
|
38
|
-
expect(envExample).toContain("API_PORT=4000");
|
|
39
|
-
expect(env).toBe(envExample);
|
|
31
|
+
expect(existsSync(join(result.targetDir, ".env.example"))).toBe(false);
|
|
32
|
+
expect(existsSync(join(result.targetDir, ".env"))).toBe(false);
|
|
40
33
|
expect(existsSync(join(result.targetDir, "tsconfig.base.json"))).toBe(true);
|
|
41
34
|
}
|
|
42
35
|
finally {
|
package/dist/index.js
CHANGED
|
@@ -26,8 +26,13 @@ function runScript(name) {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
function doctor() {
|
|
29
|
-
const
|
|
30
|
-
const
|
|
29
|
+
const cwd = process.cwd();
|
|
30
|
+
const required = ["package.json", "pnpm-workspace.yaml", "prisma/schema.prisma"];
|
|
31
|
+
const missing = required.filter((file) => !existsSync(join(cwd, file)));
|
|
32
|
+
const hasEnvSample = existsSync(join(cwd, ".env.example")) || existsSync(join(cwd, "apps", "api", ".env"));
|
|
33
|
+
if (!hasEnvSample) {
|
|
34
|
+
missing.push("apps/api/.env (or .env.example at repo root)");
|
|
35
|
+
}
|
|
31
36
|
if (missing.length) {
|
|
32
37
|
console.error(pc.red("OpenAdminJS doctor found missing files:"));
|
|
33
38
|
for (const file of missing)
|
|
@@ -38,11 +43,20 @@ function doctor() {
|
|
|
38
43
|
console.log(pc.green("OpenAdminJS doctor passed."));
|
|
39
44
|
}
|
|
40
45
|
function securityCheck() {
|
|
41
|
-
const
|
|
46
|
+
const cwd = process.cwd();
|
|
47
|
+
const envSample = existsSync(join(cwd, ".env.example"))
|
|
48
|
+
? readFileSync(join(cwd, ".env.example"), "utf8")
|
|
49
|
+
: existsSync(join(cwd, "apps", "api", ".env"))
|
|
50
|
+
? readFileSync(join(cwd, "apps", "api", ".env"), "utf8")
|
|
51
|
+
: "";
|
|
42
52
|
const findings = [];
|
|
43
|
-
if (!
|
|
44
|
-
findings.push("
|
|
45
|
-
|
|
53
|
+
if (!envSample) {
|
|
54
|
+
findings.push("No .env.example or apps/api/.env found for security checklist");
|
|
55
|
+
}
|
|
56
|
+
else if (!envSample.includes("JWT_SECRET")) {
|
|
57
|
+
findings.push("JWT_SECRET is missing from env sample (.env.example or apps/api/.env)");
|
|
58
|
+
}
|
|
59
|
+
if (envSample.includes("DATABASE_URL=postgresql://") && !envSample.includes("localhost")) {
|
|
46
60
|
findings.push("DATABASE_URL example should not point to production");
|
|
47
61
|
}
|
|
48
62
|
if (existsSync("apps/admin/app")) {
|
package/package.json
CHANGED
|
@@ -90,7 +90,7 @@ export class AdminPluginsService {
|
|
|
90
90
|
enabled?: boolean;
|
|
91
91
|
config?: Record<string, unknown>;
|
|
92
92
|
trustMode?: "trusted" | "sandboxed";
|
|
93
|
-
capabilities?:
|
|
93
|
+
capabilities?: PluginManifestEntry["capabilities"];
|
|
94
94
|
runPnpmInstall?: boolean;
|
|
95
95
|
}) {
|
|
96
96
|
const hasBundled = Boolean(dto.bundled);
|
|
@@ -156,7 +156,15 @@ export class AdminPluginsService {
|
|
|
156
156
|
};
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
async patch(
|
|
159
|
+
async patch(
|
|
160
|
+
id: string,
|
|
161
|
+
dto: {
|
|
162
|
+
enabled?: boolean;
|
|
163
|
+
config?: Record<string, unknown>;
|
|
164
|
+
trustMode?: "trusted" | "sandboxed";
|
|
165
|
+
capabilities?: PluginManifestEntry["capabilities"];
|
|
166
|
+
}
|
|
167
|
+
) {
|
|
160
168
|
const manifest = this.readManifestOrEmpty();
|
|
161
169
|
const idx = manifest.plugins.findIndex((p) => p.id === id);
|
|
162
170
|
if (idx === -1) {
|
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
import { IsArray, IsBoolean, IsIn, IsObject, IsOptional, IsString } from "class-validator";
|
|
2
2
|
|
|
3
|
+
const PLUGIN_CAPABILITIES = [
|
|
4
|
+
"db.read",
|
|
5
|
+
"db.write",
|
|
6
|
+
"resource.hooks",
|
|
7
|
+
"api.hooks",
|
|
8
|
+
"api.routes",
|
|
9
|
+
"media.pipeline",
|
|
10
|
+
"seo.extend",
|
|
11
|
+
"jobs.run",
|
|
12
|
+
"admin.ui.extend"
|
|
13
|
+
] as const;
|
|
14
|
+
|
|
15
|
+
type PluginCapability = (typeof PLUGIN_CAPABILITIES)[number];
|
|
16
|
+
|
|
3
17
|
export class AddPluginDto {
|
|
4
18
|
@IsString()
|
|
5
19
|
id!: string;
|
|
@@ -26,8 +40,8 @@ export class AddPluginDto {
|
|
|
26
40
|
|
|
27
41
|
@IsOptional()
|
|
28
42
|
@IsArray()
|
|
29
|
-
@
|
|
30
|
-
capabilities?:
|
|
43
|
+
@IsIn(PLUGIN_CAPABILITIES, { each: true })
|
|
44
|
+
capabilities?: PluginCapability[];
|
|
31
45
|
|
|
32
46
|
/** When true and `package` is set, runs `pnpm add <package> --filter @openadminjs/api` (dev / non-production only). */
|
|
33
47
|
@IsOptional()
|
|
@@ -50,6 +64,6 @@ export class PatchPluginDto {
|
|
|
50
64
|
|
|
51
65
|
@IsOptional()
|
|
52
66
|
@IsArray()
|
|
53
|
-
@
|
|
54
|
-
capabilities?:
|
|
67
|
+
@IsIn(PLUGIN_CAPABILITIES, { each: true })
|
|
68
|
+
capabilities?: PluginCapability[];
|
|
55
69
|
}
|
|
@@ -3,12 +3,13 @@ import { ConfigModule, ConfigService } from "@nestjs/config";
|
|
|
3
3
|
import { JwtModule } from "@nestjs/jwt";
|
|
4
4
|
import { AuthGuard } from "../common/auth.guard";
|
|
5
5
|
import { PrismaService } from "../common/prisma.service";
|
|
6
|
-
import {
|
|
6
|
+
import { MailModule } from "../mail/mail.module";
|
|
7
7
|
import { AuthController } from "./auth.controller";
|
|
8
8
|
import { AuthService } from "./auth.service";
|
|
9
9
|
|
|
10
10
|
@Module({
|
|
11
11
|
imports: [
|
|
12
|
+
MailModule,
|
|
12
13
|
JwtModule.registerAsync({
|
|
13
14
|
imports: [ConfigModule],
|
|
14
15
|
inject: [ConfigService],
|
|
@@ -24,7 +25,7 @@ import { AuthService } from "./auth.service";
|
|
|
24
25
|
})
|
|
25
26
|
],
|
|
26
27
|
controllers: [AuthController],
|
|
27
|
-
providers: [AuthService, PrismaService, AuthGuard
|
|
28
|
+
providers: [AuthService, PrismaService, AuthGuard],
|
|
28
29
|
exports: [AuthService, AuthGuard]
|
|
29
30
|
})
|
|
30
31
|
export class AuthModule {}
|