openadminjs 0.1.18 → 0.1.20

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.
@@ -36,6 +36,18 @@ describe("create project", () => {
36
36
  rmSync(cwd, { recursive: true, force: true });
37
37
  }
38
38
  });
39
+ it("scaffolds prisma.config.ts that loads apps/api/.env for Prisma CLI", () => {
40
+ const cwd = mkdtempSync(join(tmpdir(), "openadminjs-cli-test-"));
41
+ try {
42
+ const result = createProject({ ...BASE_OPTIONS, projectName: "my-app", cwd, templateDir: defaultTemplateDir() });
43
+ const prismaConfig = readFileSync(join(result.targetDir, "apps", "api", "prisma.config.ts"), "utf8");
44
+ expect(prismaConfig).toContain("dotenv");
45
+ expect(prismaConfig).toContain('.env")');
46
+ }
47
+ finally {
48
+ rmSync(cwd, { recursive: true, force: true });
49
+ }
50
+ });
39
51
  it("writes apps/api/.env with real secrets and superadmin credentials", () => {
40
52
  const cwd = mkdtempSync(join(tmpdir(), "openadminjs-cli-test-"));
41
53
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openadminjs",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "openadminjs": "dist/index.js"
@@ -57,6 +57,7 @@
57
57
  "zod": "^3.24.1"
58
58
  },
59
59
  "devDependencies": {
60
+ "dotenv": "^16.4.7",
60
61
  "@nestjs/cli": "^11.0.21",
61
62
  "@types/bcryptjs": "^2.4.6",
62
63
  "@types/cookie-parser": "^1.4.10",
@@ -1,5 +1,11 @@
1
+ import { config } from "dotenv";
2
+ import { dirname, join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
1
4
  import { defineConfig } from "prisma/config";
2
5
 
6
+ // Prisma skips default .env discovery when prisma.config.ts is present; load apps/api/.env explicitly.
7
+ config({ path: join(dirname(fileURLToPath(import.meta.url)), ".env") });
8
+
3
9
  export default defineConfig({
4
10
  schema: "../../prisma/schema.prisma",
5
11
  seed: "tsx ../../prisma/seed.ts",
@@ -28,6 +28,6 @@ import { SsoOidcService } from "./sso-oidc.service";
28
28
  ],
29
29
  controllers: [AuthController, SsoOidcController],
30
30
  providers: [AuthService, SsoOidcService, PrismaService, AuthGuard],
31
- exports: [AuthService, AuthGuard, JwtModule]
31
+ exports: [AuthService, AuthGuard, JwtModule, PrismaService]
32
32
  })
33
33
  export class AuthModule {}
@@ -11,7 +11,6 @@ describe("AdminResourcesResolver", () => {
11
11
 
12
12
  await resolver.adminResourceList(
13
13
  "posts",
14
- user as never,
15
14
  2,
16
15
  15,
17
16
  "hello",
@@ -21,7 +20,8 @@ describe("AdminResourcesResolver", () => {
21
20
  status: { eq: "published" },
22
21
  views: { gte: 10, lte: 100 },
23
22
  authorId: "u1"
24
- }
23
+ },
24
+ { req: { user } } as never
25
25
  );
26
26
 
27
27
  expect(adminResources.list).toHaveBeenCalledWith(
@@ -1,13 +1,14 @@
1
1
  import { UseGuards } from "@nestjs/common";
2
- import { Args, Int, Query, Resolver } from "@nestjs/graphql";
2
+ import { Args, Context, Int, Query, Resolver } from "@nestjs/graphql";
3
3
  import { GraphQLJSON } from "graphql-scalars";
4
4
  import { AdminResourceService } from "../admin/admin-resource.service";
5
5
  import { AuthGuard } from "../common/auth.guard";
6
6
  import type { RequestUser } from "../common/auth.guard";
7
7
  import { RequireAuthRealm } from "../common/auth-realm.decorator";
8
- import { CurrentUser } from "../common/current-user.decorator";
9
8
  import { resources } from "../resources/registry";
10
9
 
10
+ type GqlAuthContext = { req: { user: RequestUser } };
11
+
11
12
  @Resolver()
12
13
  @UseGuards(AuthGuard)
13
14
  @RequireAuthRealm("admin")
@@ -30,7 +31,8 @@ export class AdminResourcesResolver {
30
31
  }
31
32
 
32
33
  @Query(() => [String], { name: "adminRegisteredResourceNames" })
33
- adminRegisteredResourceNames(@CurrentUser() user: RequestUser): string[] {
34
+ adminRegisteredResourceNames(@Context() ctx: GqlAuthContext): string[] {
35
+ const user = ctx.req.user;
34
36
  return resources
35
37
  .filter(
36
38
  (r) =>
@@ -43,23 +45,23 @@ export class AdminResourcesResolver {
43
45
  @Query(() => GraphQLJSON, { name: "adminResourceList", description: "Paginated list (same rules as REST /admin/resources/:name)" })
44
46
  adminResourceList(
45
47
  @Args("name") name: string,
46
- @CurrentUser() user: RequestUser,
47
48
  @Args("page", { type: () => Int, nullable: true, defaultValue: 1 }) page: number,
48
49
  @Args("limit", { type: () => Int, nullable: true, defaultValue: 20 }) limit: number,
49
- @Args("search", { nullable: true }) search?: string,
50
- @Args("sort", { nullable: true }) sort?: string,
51
- @Args("locale", { nullable: true }) locale?: string,
52
- @Args("filter", { type: () => GraphQLJSON, nullable: true }) filter?: Record<string, unknown>
50
+ @Args("search", { type: () => String, nullable: true }) search: string | undefined,
51
+ @Args("sort", { type: () => String, nullable: true }) sort: string | undefined,
52
+ @Args("locale", { type: () => String, nullable: true }) locale: string | undefined,
53
+ @Args("filter", { type: () => GraphQLJSON, nullable: true }) filter: unknown | undefined,
54
+ @Context() ctx: GqlAuthContext
53
55
  ) {
54
56
  const query: Record<string, unknown> = { page, limit, ...this.flattenFilters(filter) };
55
57
  if (search) query.search = search;
56
58
  if (sort) query.sort = sort;
57
59
  if (locale) query.locale = locale;
58
- return this.adminResources.list(name, query, user);
60
+ return this.adminResources.list(name, query, ctx.req.user);
59
61
  }
60
62
 
61
63
  @Query(() => GraphQLJSON, { name: "adminResourceRecord" })
62
- adminResourceRecord(@Args("name") name: string, @Args("id") id: string, @CurrentUser() user: RequestUser) {
63
- return this.adminResources.get(name, id, user);
64
+ adminResourceRecord(@Args("name") name: string, @Args("id") id: string, @Context() ctx: GqlAuthContext) {
65
+ return this.adminResources.get(name, id, ctx.req.user);
64
66
  }
65
67
  }
@@ -4,7 +4,6 @@ import { ApolloDriver, ApolloDriverConfig } from "@nestjs/apollo";
4
4
  import { GraphQLJSON } from "graphql-scalars";
5
5
  import { AdminModule } from "../admin/admin.module";
6
6
  import { AuthModule } from "../auth/auth.module";
7
- import { AuthGuard } from "../common/auth.guard";
8
7
  import { AdminResourcesResolver } from "./admin-resources.resolver";
9
8
 
10
9
  @Module({
@@ -21,6 +20,6 @@ import { AdminResourcesResolver } from "./admin-resources.resolver";
21
20
  AdminModule,
22
21
  AuthModule
23
22
  ],
24
- providers: [AdminResourcesResolver, AuthGuard]
23
+ providers: [AdminResourcesResolver]
25
24
  })
26
25
  export class GraphqlApiModule {}