openadminjs 0.1.23 → 0.2.0
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 +97 -16
- package/dist/adapt-package-manager.d.ts +3 -0
- package/dist/adapt-package-manager.js +115 -0
- package/dist/adapt-package-manager.test.d.ts +1 -0
- package/dist/adapt-package-manager.test.js +76 -0
- package/dist/cli.e2e.test.d.ts +1 -0
- package/dist/cli.e2e.test.js +87 -0
- package/dist/create-project.d.ts +31 -2
- package/dist/create-project.js +296 -102
- package/dist/create-project.test.js +180 -4
- package/dist/database-providers.integration.test.d.ts +1 -0
- package/dist/database-providers.integration.test.js +64 -0
- package/dist/db-commands.d.ts +20 -0
- package/dist/db-commands.js +75 -0
- package/dist/db-commands.test.d.ts +1 -0
- package/dist/db-commands.test.js +27 -0
- package/dist/detect-package-manager.d.ts +8 -0
- package/dist/detect-package-manager.js +37 -0
- package/dist/doctor.d.ts +13 -0
- package/dist/doctor.js +203 -0
- package/dist/doctor.test.d.ts +1 -0
- package/dist/doctor.test.js +102 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +233 -141
- package/dist/index.test.js +7 -3
- package/dist/render-schema.d.ts +20 -0
- package/dist/render-schema.js +37 -0
- package/dist/render-schema.test.d.ts +1 -0
- package/dist/render-schema.test.js +57 -0
- package/dist/secrets.d.ts +24 -0
- package/dist/secrets.js +93 -0
- package/dist/secrets.test.d.ts +1 -0
- package/dist/secrets.test.js +36 -0
- package/dist/security.d.ts +13 -0
- package/dist/security.js +168 -0
- package/dist/security.test.d.ts +1 -0
- package/dist/security.test.js +54 -0
- package/dist/validate-name.d.ts +33 -0
- package/dist/validate-name.js +206 -0
- package/dist/validate-name.test.d.ts +1 -0
- package/dist/validate-name.test.js +63 -0
- package/package.json +26 -1
- package/template/README.md +22 -3
- package/template/apps/admin/app/layout.tsx +2 -9
- package/template/apps/api/package.json +22 -20
- package/template/apps/api/src/app.module.test.ts +12 -0
- package/template/apps/api/src/app.module.ts +17 -11
- package/template/apps/api/src/common/json-field-codec.test.ts +76 -0
- package/template/apps/api/src/common/json-field-codec.ts +139 -0
- package/template/apps/api/src/common/openadmin-throttler.guard.ts +39 -0
- package/template/apps/api/src/common/prisma.service.test.ts +19 -0
- package/template/apps/api/src/common/prisma.service.ts +13 -0
- package/template/apps/api/src/common/request-logging.interceptor.test.ts +39 -0
- package/template/apps/api/src/common/request-logging.interceptor.ts +5 -3
- package/template/apps/api/src/graphql/admin-resources.args.ts +15 -0
- package/template/apps/api/src/graphql/ensure-gql-paramtypes.test.ts +20 -1
- package/template/apps/api/src/graphql/ensure-gql-paramtypes.ts +15 -0
- package/template/apps/api/src/graphql/graphql-apollo-config.test.ts +26 -0
- package/template/apps/api/src/graphql/graphql-schema.test.ts +8 -0
- package/template/apps/api/src/graphql/graphql.module.ts +13 -1
- package/template/apps/api/src/queue/queue.module.ts +1 -8
- package/template/apps/api/src/queue/queue.processor.ts +26 -6
- package/template/apps/api/src/queue/queue.service.test.ts +33 -0
- package/template/apps/api/src/queue/queue.service.ts +30 -12
- package/template/package.json +19 -0
- package/template/prisma/migrations/20260713120000_add_user_oidc_key_and_category_order/migration.sql +11 -0
- package/template/prisma/seed.ts +30 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ArgsType, Field, Int } from "@nestjs/graphql";
|
|
2
2
|
import { GraphQLJSON } from "graphql-scalars";
|
|
3
|
+
import { ensureGqlFieldTypes } from "./ensure-gql-paramtypes";
|
|
3
4
|
|
|
4
5
|
@ArgsType()
|
|
5
6
|
export class AdminResourceListArgs {
|
|
@@ -33,3 +34,17 @@ export class AdminResourceRecordArgs {
|
|
|
33
34
|
@Field(() => String)
|
|
34
35
|
id!: string;
|
|
35
36
|
}
|
|
37
|
+
|
|
38
|
+
ensureGqlFieldTypes(AdminResourceListArgs.prototype, {
|
|
39
|
+
name: String,
|
|
40
|
+
page: Number,
|
|
41
|
+
limit: Number,
|
|
42
|
+
search: String,
|
|
43
|
+
sort: String,
|
|
44
|
+
locale: String,
|
|
45
|
+
filter: GraphQLJSON
|
|
46
|
+
});
|
|
47
|
+
ensureGqlFieldTypes(AdminResourceRecordArgs.prototype, {
|
|
48
|
+
name: String,
|
|
49
|
+
id: String
|
|
50
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
2
|
import { describe, expect, it } from "vitest";
|
|
3
|
-
import { ensureGqlParamTypes } from "./ensure-gql-paramtypes";
|
|
3
|
+
import { ensureGqlFieldTypes, ensureGqlParamTypes } from "./ensure-gql-paramtypes";
|
|
4
4
|
|
|
5
5
|
describe("ensureGqlParamTypes", () => {
|
|
6
6
|
it("defines design:paramtypes when missing", () => {
|
|
@@ -22,4 +22,23 @@ describe("ensureGqlParamTypes", () => {
|
|
|
22
22
|
ensureGqlParamTypes(Sample.prototype, "handler", [String]);
|
|
23
23
|
expect(Reflect.getMetadata("design:paramtypes", Sample.prototype, "handler")).toEqual([Date]);
|
|
24
24
|
});
|
|
25
|
+
|
|
26
|
+
it("defines missing design:type metadata for GraphQL fields", () => {
|
|
27
|
+
class Sample {
|
|
28
|
+
name!: string;
|
|
29
|
+
count!: number;
|
|
30
|
+
}
|
|
31
|
+
ensureGqlFieldTypes(Sample.prototype, { name: String, count: Number });
|
|
32
|
+
expect(Reflect.getMetadata("design:type", Sample.prototype, "name")).toBe(String);
|
|
33
|
+
expect(Reflect.getMetadata("design:type", Sample.prototype, "count")).toBe(Number);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("does not overwrite existing field metadata", () => {
|
|
37
|
+
class Sample {
|
|
38
|
+
createdAt!: Date;
|
|
39
|
+
}
|
|
40
|
+
Reflect.defineMetadata("design:type", Date, Sample.prototype, "createdAt");
|
|
41
|
+
ensureGqlFieldTypes(Sample.prototype, { createdAt: String });
|
|
42
|
+
expect(Reflect.getMetadata("design:type", Sample.prototype, "createdAt")).toBe(Date);
|
|
43
|
+
});
|
|
25
44
|
});
|
|
@@ -13,3 +13,18 @@ export function ensureGqlParamTypes(
|
|
|
13
13
|
if (Array.isArray(existing) && existing.length >= paramTypes.length) return;
|
|
14
14
|
Reflect.defineMetadata(key, paramTypes, prototype, methodName);
|
|
15
15
|
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* `@Field(() => Type)` is still resolved through lazy metadata that expects
|
|
19
|
+
* `design:type` to exist. Define the property metadata when `tsx watch` did not emit it.
|
|
20
|
+
*/
|
|
21
|
+
export function ensureGqlFieldTypes(
|
|
22
|
+
prototype: object,
|
|
23
|
+
fieldTypes: Record<string, unknown>
|
|
24
|
+
): void {
|
|
25
|
+
const key = "design:type";
|
|
26
|
+
for (const [fieldName, fieldType] of Object.entries(fieldTypes)) {
|
|
27
|
+
if (Reflect.hasMetadata(key, prototype, fieldName)) continue;
|
|
28
|
+
Reflect.defineMetadata(key, fieldType, prototype, fieldName);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { describe, expect, it } from "vitest";
|
|
5
|
+
|
|
6
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const moduleSource = readFileSync(join(here, "graphql.module.ts"), "utf8");
|
|
8
|
+
|
|
9
|
+
// Strip comments so assertions check actual configuration, not explanatory prose
|
|
10
|
+
// (a comment that names `graphql-playground` must not trip the guard below).
|
|
11
|
+
const moduleCode = moduleSource.replace(/\/\*[\s\S]*?\*\//g, "").replace(/^\s*\/\/.*$/gm, "");
|
|
12
|
+
|
|
13
|
+
describe("Apollo driver config (peer-conflict regression)", () => {
|
|
14
|
+
it("does not enable the deprecated graphql-playground landing page", () => {
|
|
15
|
+
// `playground: true` pulls in @apollo/server-plugin-landing-page-graphql-playground,
|
|
16
|
+
// which has a non-optional @apollo/server@4 peer dependency and breaks a clean install.
|
|
17
|
+
expect(moduleCode).toMatch(/playground:\s*false/);
|
|
18
|
+
expect(moduleCode).not.toMatch(/playground:\s*true/);
|
|
19
|
+
expect(moduleCode).not.toMatch(/graphql-playground/);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("uses the Apollo Server 5 landing page plugin", () => {
|
|
23
|
+
expect(moduleSource).toContain("@apollo/server/plugin/landingPage/default");
|
|
24
|
+
expect(moduleSource).toMatch(/ApolloServerPluginLandingPage(Local|Production)Default/);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -4,6 +4,13 @@ import { AdminResourceListArgs, AdminResourceRecordArgs } from "./admin-resource
|
|
|
4
4
|
import { AdminResourcesResolver } from "./admin-resources.resolver";
|
|
5
5
|
|
|
6
6
|
describe("GraphQL schema (admin resources)", () => {
|
|
7
|
+
it("exposes design:type metadata for args fields when the compiler does not emit it", () => {
|
|
8
|
+
expect(Reflect.getMetadata("design:type", AdminResourceListArgs.prototype, "name")).toBe(String);
|
|
9
|
+
expect(Reflect.getMetadata("design:type", AdminResourceListArgs.prototype, "page")).toBe(Number);
|
|
10
|
+
expect(Reflect.getMetadata("design:type", AdminResourceListArgs.prototype, "filter")).toBeTruthy();
|
|
11
|
+
expect(Reflect.getMetadata("design:type", AdminResourceRecordArgs.prototype, "id")).toBe(String);
|
|
12
|
+
});
|
|
13
|
+
|
|
7
14
|
it("exposes design:paramtypes for Nest GraphQL when the compiler does not emit it", () => {
|
|
8
15
|
expect(
|
|
9
16
|
Reflect.getMetadata("design:paramtypes", AdminResourcesResolver.prototype, "adminResourceList")
|
|
@@ -15,4 +22,5 @@ describe("GraphQL schema (admin resources)", () => {
|
|
|
15
22
|
Reflect.getMetadata("design:paramtypes", AdminResourcesResolver.prototype, "adminRegisteredResourceNames")
|
|
16
23
|
).toEqual([Object]);
|
|
17
24
|
});
|
|
25
|
+
|
|
18
26
|
});
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Module } from "@nestjs/common";
|
|
2
2
|
import { GraphQLModule } from "@nestjs/graphql";
|
|
3
3
|
import { ApolloDriver, ApolloDriverConfig } from "@nestjs/apollo";
|
|
4
|
+
import {
|
|
5
|
+
ApolloServerPluginLandingPageLocalDefault,
|
|
6
|
+
ApolloServerPluginLandingPageProductionDefault
|
|
7
|
+
} from "@apollo/server/plugin/landingPage/default";
|
|
4
8
|
import { GraphQLJSON } from "graphql-scalars";
|
|
5
9
|
import { AdminModule } from "../admin/admin.module";
|
|
6
10
|
import { AuthModule } from "../auth/auth.module";
|
|
@@ -16,7 +20,15 @@ import { AdminResourcesResolver } from "./admin-resources.resolver";
|
|
|
16
20
|
path: "/graphql",
|
|
17
21
|
context: ({ req, res }: { req: unknown; res: unknown }) => ({ req, res }),
|
|
18
22
|
resolvers: { JSON: GraphQLJSON },
|
|
19
|
-
|
|
23
|
+
// Apollo Server 5 landing page. Avoids the deprecated graphql-playground
|
|
24
|
+
// plugin, which carries a non-optional @apollo/server@4 peer dependency
|
|
25
|
+
// and causes peer conflicts on a clean install.
|
|
26
|
+
playground: false,
|
|
27
|
+
plugins: [
|
|
28
|
+
process.env.NODE_ENV === "production"
|
|
29
|
+
? ApolloServerPluginLandingPageProductionDefault()
|
|
30
|
+
: ApolloServerPluginLandingPageLocalDefault({ embed: true })
|
|
31
|
+
]
|
|
20
32
|
}),
|
|
21
33
|
AdminModule,
|
|
22
34
|
AuthModule
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Module } from "@nestjs/common";
|
|
2
2
|
import { JwtModule } from "@nestjs/jwt";
|
|
3
|
-
import { BullModule } from "@nestjs/bullmq";
|
|
4
3
|
import { PrismaService } from "../common/prisma.service";
|
|
5
4
|
import { AuthGuard } from "../common/auth.guard";
|
|
6
5
|
import { PermissionsGuard } from "../common/permissions.guard";
|
|
@@ -10,13 +9,7 @@ import { QueueService } from "./queue.service";
|
|
|
10
9
|
import { QueueProcessor } from "./queue.processor";
|
|
11
10
|
|
|
12
11
|
@Module({
|
|
13
|
-
imports: [
|
|
14
|
-
JwtModule.register({}),
|
|
15
|
-
BullModule.forRoot({
|
|
16
|
-
connection: { url: process.env.REDIS_URL ?? "redis://127.0.0.1:6379" }
|
|
17
|
-
}),
|
|
18
|
-
BullModule.registerQueue({ name: "default" })
|
|
19
|
-
],
|
|
12
|
+
imports: [JwtModule.register({})],
|
|
20
13
|
controllers: [QueueController],
|
|
21
14
|
providers: [QueueService, QueueProcessor, PrismaService, AuthGuard, PermissionsGuard, CaslAbilityFactory]
|
|
22
15
|
})
|
|
@@ -1,14 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import type { Job } from "bullmq";
|
|
1
|
+
import { Inject, Injectable, Logger, OnModuleDestroy, OnModuleInit } from "@nestjs/common";
|
|
2
|
+
import { Worker } from "bullmq";
|
|
3
|
+
import type { ConnectionOptions, Job } from "bullmq";
|
|
4
4
|
import { PrismaService } from "../common/prisma.service";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const QUEUE_NAME = "default";
|
|
7
|
+
|
|
8
|
+
function redisConnection(): ConnectionOptions | undefined {
|
|
9
|
+
const url = process.env.REDIS_URL?.trim();
|
|
10
|
+
return url ? { url } : undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@Injectable()
|
|
14
|
+
export class QueueProcessor implements OnModuleInit, OnModuleDestroy {
|
|
8
15
|
private readonly logger = new Logger(QueueProcessor.name);
|
|
16
|
+
private worker?: Worker<{ initiatedBy?: string; at?: string }, { ok: boolean }>;
|
|
9
17
|
|
|
10
18
|
constructor(@Inject(PrismaService) private readonly prisma: PrismaService) {
|
|
11
|
-
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
onModuleInit() {
|
|
22
|
+
const connection = redisConnection();
|
|
23
|
+
if (!connection) {
|
|
24
|
+
this.logger.log("Redis is not configured; queue worker is disabled.");
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
this.worker = new Worker(QUEUE_NAME, (job) => this.process(job), { connection });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async onModuleDestroy() {
|
|
31
|
+
await this.worker?.close();
|
|
12
32
|
}
|
|
13
33
|
|
|
14
34
|
async process(job: Job<{ initiatedBy?: string; at?: string }>) {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ServiceUnavailableException } from "@nestjs/common";
|
|
2
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
3
|
+
import { QueueService } from "./queue.service";
|
|
4
|
+
|
|
5
|
+
const originalRedisUrl = process.env.REDIS_URL;
|
|
6
|
+
|
|
7
|
+
describe("QueueService", () => {
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
process.env.REDIS_URL = originalRedisUrl;
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("degrades gracefully when Redis is not configured", async () => {
|
|
13
|
+
delete process.env.REDIS_URL;
|
|
14
|
+
const recent = [{ id: "job_1", name: "maintenance.sync", status: "completed" }];
|
|
15
|
+
const service = new QueueService({
|
|
16
|
+
jobLog: {
|
|
17
|
+
findMany: async () => recent
|
|
18
|
+
}
|
|
19
|
+
} as never);
|
|
20
|
+
|
|
21
|
+
await expect(service.getStats()).resolves.toEqual({
|
|
22
|
+
counts: {
|
|
23
|
+
active: 0,
|
|
24
|
+
waiting: 0,
|
|
25
|
+
completed: 0,
|
|
26
|
+
failed: 0,
|
|
27
|
+
delayed: 0
|
|
28
|
+
},
|
|
29
|
+
recent
|
|
30
|
+
});
|
|
31
|
+
await expect(service.dispatch("user_1")).rejects.toBeInstanceOf(ServiceUnavailableException);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -1,18 +1,35 @@
|
|
|
1
|
-
import { Inject, Injectable, ServiceUnavailableException } from "@nestjs/common";
|
|
2
|
-
import { InjectQueue } from "@nestjs/bullmq";
|
|
1
|
+
import { Inject, Injectable, OnModuleDestroy, ServiceUnavailableException } from "@nestjs/common";
|
|
3
2
|
import { Queue } from "bullmq";
|
|
3
|
+
import type { ConnectionOptions } from "bullmq";
|
|
4
4
|
import { PrismaService } from "../common/prisma.service";
|
|
5
5
|
|
|
6
|
+
const QUEUE_NAME = "default";
|
|
7
|
+
|
|
8
|
+
function redisConnection(): ConnectionOptions | undefined {
|
|
9
|
+
const url = process.env.REDIS_URL?.trim();
|
|
10
|
+
return url ? { url } : undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
6
13
|
@Injectable()
|
|
7
|
-
export class QueueService {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
) {}
|
|
14
|
+
export class QueueService implements OnModuleDestroy {
|
|
15
|
+
private readonly connection = redisConnection();
|
|
16
|
+
private readonly queue = this.connection ? new Queue(QUEUE_NAME, { connection: this.connection }) : undefined;
|
|
17
|
+
|
|
18
|
+
constructor(@Inject(PrismaService) private readonly prisma: PrismaService) {}
|
|
19
|
+
|
|
20
|
+
async onModuleDestroy() {
|
|
21
|
+
await this.queue?.close();
|
|
22
|
+
}
|
|
12
23
|
|
|
13
24
|
async getStats() {
|
|
14
25
|
const [counts, recent] = await Promise.all([
|
|
15
|
-
this.queue
|
|
26
|
+
this.queue?.getJobCounts("active", "waiting", "completed", "failed", "delayed") ?? {
|
|
27
|
+
active: 0,
|
|
28
|
+
waiting: 0,
|
|
29
|
+
completed: 0,
|
|
30
|
+
failed: 0,
|
|
31
|
+
delayed: 0
|
|
32
|
+
},
|
|
16
33
|
this.prisma.jobLog.findMany({ orderBy: { createdAt: "desc" }, take: 10 })
|
|
17
34
|
]);
|
|
18
35
|
|
|
@@ -20,9 +37,9 @@ export class QueueService {
|
|
|
20
37
|
}
|
|
21
38
|
|
|
22
39
|
async dispatch(userId: string) {
|
|
23
|
-
this.ensureRedisConfigured();
|
|
40
|
+
const queue = this.ensureRedisConfigured();
|
|
24
41
|
const payload = { initiatedBy: userId, at: new Date().toISOString() };
|
|
25
|
-
const job = await
|
|
42
|
+
const job = await queue.add("maintenance.sync", payload, {
|
|
26
43
|
removeOnComplete: 100,
|
|
27
44
|
attempts: 3,
|
|
28
45
|
backoff: { type: "exponential", delay: 1000 }
|
|
@@ -39,12 +56,13 @@ export class QueueService {
|
|
|
39
56
|
return { id: job.id, name: job.name };
|
|
40
57
|
}
|
|
41
58
|
|
|
42
|
-
private ensureRedisConfigured() {
|
|
43
|
-
if (!
|
|
59
|
+
private ensureRedisConfigured(): Queue {
|
|
60
|
+
if (!this.queue) {
|
|
44
61
|
throw new ServiceUnavailableException({
|
|
45
62
|
message: "Redis is not configured. Set REDIS_URL to enable queues.",
|
|
46
63
|
code: "REDIS_NOT_CONFIGURED"
|
|
47
64
|
});
|
|
48
65
|
}
|
|
66
|
+
return this.queue;
|
|
49
67
|
}
|
|
50
68
|
}
|
package/template/package.json
CHANGED
|
@@ -11,8 +11,10 @@
|
|
|
11
11
|
"typecheck": "pnpm -r typecheck",
|
|
12
12
|
"test": "pnpm -r test",
|
|
13
13
|
"db:migrate": "pnpm --filter @openadminjs/api db:migrate",
|
|
14
|
+
"db:migrate:deploy": "pnpm --filter @openadminjs/api db:migrate:deploy",
|
|
14
15
|
"db:seed": "pnpm --filter @openadminjs/api db:seed",
|
|
15
16
|
"db:studio": "pnpm --filter @openadminjs/api db:studio",
|
|
17
|
+
"db:reset": "pnpm --filter @openadminjs/api db:reset",
|
|
16
18
|
"generate": "pnpm --filter @openadminjs/api generate"
|
|
17
19
|
},
|
|
18
20
|
"devDependencies": {
|
|
@@ -22,5 +24,22 @@
|
|
|
22
24
|
"tsx": "^4.19.2",
|
|
23
25
|
"typescript": "^5.7.2",
|
|
24
26
|
"vitest": "^3.2.0"
|
|
27
|
+
},
|
|
28
|
+
"pnpm": {
|
|
29
|
+
"overrides": {
|
|
30
|
+
"@nestjs/apollo": "13.4.0",
|
|
31
|
+
"@nestjs/common": "11.1.21",
|
|
32
|
+
"@nestjs/config": "4.0.4",
|
|
33
|
+
"@nestjs/core": "11.1.21",
|
|
34
|
+
"@nestjs/graphql": "13.4.0",
|
|
35
|
+
"@nestjs/jwt": "11.0.2",
|
|
36
|
+
"@nestjs/platform-express": "11.1.21",
|
|
37
|
+
"@nestjs/swagger": "11.4.3",
|
|
38
|
+
"@nestjs/throttler": "6.5.0",
|
|
39
|
+
"class-transformer": "0.5.1",
|
|
40
|
+
"class-validator": "0.14.4",
|
|
41
|
+
"reflect-metadata": "0.2.2",
|
|
42
|
+
"rxjs": "7.8.2"
|
|
43
|
+
}
|
|
25
44
|
}
|
|
26
45
|
}
|
package/template/prisma/migrations/20260713120000_add_user_oidc_key_and_category_order/migration.sql
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
-- AlterTable
|
|
2
|
+
ALTER TABLE "User" ADD COLUMN "oidcKey" TEXT;
|
|
3
|
+
|
|
4
|
+
-- AlterTable
|
|
5
|
+
ALTER TABLE "Category" ADD COLUMN "order" INTEGER NOT NULL DEFAULT 0;
|
|
6
|
+
|
|
7
|
+
-- CreateIndex
|
|
8
|
+
CREATE UNIQUE INDEX "User_oidcKey_key" ON "User"("oidcKey");
|
|
9
|
+
|
|
10
|
+
-- CreateIndex
|
|
11
|
+
CREATE INDEX "Category_order_idx" ON "Category"("order");
|
package/template/prisma/seed.ts
CHANGED
|
@@ -1,11 +1,37 @@
|
|
|
1
1
|
import { PrismaClient } from "@prisma/client";
|
|
2
2
|
import bcrypt from "bcryptjs";
|
|
3
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
3
5
|
import { createInterface } from "node:readline/promises";
|
|
4
6
|
import { stdin as input, stdout as output } from "node:process";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
5
8
|
import { materializeAllRoles, roleMatrixKey } from "@openadminjs/permissions";
|
|
6
9
|
import { catalogSlugList, permissionCatalog, roleBlueprints } from "../apps/api/src/access/catalog";
|
|
7
10
|
import { publicPermissionCatalog, publicRoleBlueprints } from "../apps/api/src/access/public-catalog";
|
|
8
11
|
|
|
12
|
+
function loadApiEnv(): void {
|
|
13
|
+
const rootDir = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
14
|
+
const candidates = [
|
|
15
|
+
join(process.cwd(), ".env"),
|
|
16
|
+
join(process.cwd(), "apps", "api", ".env"),
|
|
17
|
+
join(rootDir, "apps", "api", ".env")
|
|
18
|
+
];
|
|
19
|
+
const envFile = candidates.find((path) => existsSync(path));
|
|
20
|
+
if (!envFile) return;
|
|
21
|
+
|
|
22
|
+
for (const line of readFileSync(envFile, "utf8").split(/\r?\n/)) {
|
|
23
|
+
if (!line || line.trimStart().startsWith("#")) continue;
|
|
24
|
+
const separator = line.indexOf("=");
|
|
25
|
+
if (separator <= 0) continue;
|
|
26
|
+
const key = line.slice(0, separator).trim();
|
|
27
|
+
if (process.env[key] !== undefined) continue;
|
|
28
|
+
const value = line.slice(separator + 1).trim().replace(/^(['"])(.*)\1$/, "$2");
|
|
29
|
+
process.env[key] = value;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
loadApiEnv();
|
|
34
|
+
|
|
9
35
|
const prisma = new PrismaClient();
|
|
10
36
|
|
|
11
37
|
type SeedCredentials = {
|
|
@@ -118,7 +144,10 @@ async function main() {
|
|
|
118
144
|
|
|
119
145
|
const user = await prisma.user.upsert({
|
|
120
146
|
where: { email: superadmin.email },
|
|
121
|
-
update: {
|
|
147
|
+
update: {
|
|
148
|
+
name: "Admin",
|
|
149
|
+
passwordHash: await bcrypt.hash(superadmin.password, 12)
|
|
150
|
+
},
|
|
122
151
|
create: {
|
|
123
152
|
email: superadmin.email,
|
|
124
153
|
name: "Admin",
|