openadminjs 0.1.24 → 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/api/package.json +3 -0
- 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/prisma.service.test.ts +19 -0
- package/template/apps/api/src/common/prisma.service.ts +13 -0
- package/template/apps/api/src/graphql/graphql-apollo-config.test.ts +26 -0
- package/template/apps/api/src/graphql/graphql.module.ts +13 -1
- package/template/package.json +2 -0
- package/template/prisma/migrations/20260713120000_add_user_oidc_key_and_category_order/migration.sql +11 -0
package/package.json
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openadminjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "CLI scaffold generator for OpenAdminJS monorepos (NestJS, Prisma, Next.js). Not a runtime library — use npx openadminjs create.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"openadminjs",
|
|
8
|
+
"admin",
|
|
9
|
+
"nestjs",
|
|
10
|
+
"nextjs",
|
|
11
|
+
"prisma",
|
|
12
|
+
"cli",
|
|
13
|
+
"scaffold",
|
|
14
|
+
"generator",
|
|
15
|
+
"monorepo"
|
|
16
|
+
],
|
|
17
|
+
"homepage": "https://js-senpai.github.io/open-admin-js/",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/js-senpai/open-admin-js/issues"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/js-senpai/open-admin-js.git",
|
|
24
|
+
"directory": "packages/cli"
|
|
25
|
+
},
|
|
4
26
|
"type": "module",
|
|
5
27
|
"bin": {
|
|
6
28
|
"openadminjs": "dist/index.js"
|
|
@@ -20,6 +42,9 @@
|
|
|
20
42
|
"publishConfig": {
|
|
21
43
|
"access": "public"
|
|
22
44
|
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=20"
|
|
47
|
+
},
|
|
23
48
|
"files": [
|
|
24
49
|
"dist",
|
|
25
50
|
"template",
|
package/template/README.md
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
# __APP_NAME__
|
|
2
2
|
|
|
3
|
-
Generated by [OpenAdminJS](https://
|
|
3
|
+
Generated by [OpenAdminJS](https://js-senpai.github.io/open-admin-js/).
|
|
4
4
|
|
|
5
5
|
## Stack
|
|
6
6
|
|
|
7
|
-
- **API** — Nest.js
|
|
7
|
+
- **API** — Nest.js 11 + Prisma 6 (port 4000)
|
|
8
8
|
- **Admin** — Next.js 15 back-office (port 3000)
|
|
9
9
|
- **Web** — Next.js 15 public site (port 3001)
|
|
10
|
+
- **Database** — PostgreSQL, MySQL, or SQLite (chosen during `openadminjs create`)
|
|
10
11
|
|
|
11
12
|
## Getting started
|
|
12
13
|
|
|
13
14
|
```bash
|
|
14
15
|
pnpm install
|
|
16
|
+
pnpm db:migrate # required on first run (especially for MySQL/SQLite)
|
|
17
|
+
pnpm db:seed
|
|
15
18
|
pnpm dev
|
|
16
19
|
```
|
|
17
20
|
|
|
@@ -19,14 +22,30 @@ Admin panel → http://localhost:3000
|
|
|
19
22
|
API + Swagger → http://localhost:4000/api/docs
|
|
20
23
|
Public site → http://localhost:3001
|
|
21
24
|
|
|
25
|
+
Sign in with the superadmin email and password from the scaffold wizard (stored in `apps/api/.env`).
|
|
26
|
+
|
|
27
|
+
## Environment
|
|
28
|
+
|
|
29
|
+
Real secrets live in **`apps/api/.env`** only. A tracked **`.env.example`** at the repo root documents the required keys. Never commit `.env` files.
|
|
30
|
+
|
|
31
|
+
| Provider | Typical `DATABASE_URL` |
|
|
32
|
+
| --- | --- |
|
|
33
|
+
| PostgreSQL | `postgresql://USER:PASSWORD@localhost:5432/db?schema=public` |
|
|
34
|
+
| MySQL | `mysql://USER:PASSWORD@localhost:3306/db` |
|
|
35
|
+
| SQLite | `file:./dev.db` |
|
|
36
|
+
|
|
37
|
+
On **SQLite**, `Json` columns are stored as `String` in the database; the API transparently JSON-encodes/decodes them at runtime.
|
|
38
|
+
|
|
22
39
|
## Useful commands
|
|
23
40
|
|
|
24
41
|
| Command | Description |
|
|
25
42
|
|---|---|
|
|
26
43
|
| `pnpm dev` | Start API + admin in parallel |
|
|
27
|
-
| `pnpm db:migrate` | Run Prisma migrations |
|
|
44
|
+
| `pnpm db:migrate` | Run Prisma migrations (`migrate dev`) |
|
|
28
45
|
| `pnpm db:seed` | Seed database (creates superadmin) |
|
|
29
46
|
| `pnpm db:studio` | Open Prisma Studio |
|
|
30
47
|
| `pnpm build` | Build all workspaces |
|
|
31
48
|
| `pnpm test` | Run all tests |
|
|
32
49
|
| `pnpm lint` | Type-check all workspaces |
|
|
50
|
+
| `openadminjs doctor` | Check project health |
|
|
51
|
+
| `openadminjs security check` | Audit secrets and configuration |
|
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
"pretest": "pnpm run prisma:generate",
|
|
16
16
|
"test": "vitest run",
|
|
17
17
|
"db:migrate": "prisma migrate dev --schema ../../prisma/schema.prisma",
|
|
18
|
+
"db:migrate:deploy": "prisma migrate deploy --schema ../../prisma/schema.prisma",
|
|
19
|
+
"db:studio": "prisma studio --schema ../../prisma/schema.prisma",
|
|
20
|
+
"db:reset": "prisma migrate reset --schema ../../prisma/schema.prisma",
|
|
18
21
|
"db:seed": "tsx ../../prisma/seed.ts"
|
|
19
22
|
},
|
|
20
23
|
"dependencies": {
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
decodeReadResult,
|
|
4
|
+
encodeWriteArgs,
|
|
5
|
+
isSqliteDatabaseUrl,
|
|
6
|
+
SQLITE_JSON_FIELDS
|
|
7
|
+
} from "./json-field-codec";
|
|
8
|
+
|
|
9
|
+
describe("isSqliteDatabaseUrl", () => {
|
|
10
|
+
it("detects file: URLs", () => {
|
|
11
|
+
expect(isSqliteDatabaseUrl("file:./dev.db")).toBe(true);
|
|
12
|
+
expect(isSqliteDatabaseUrl("FILE:./data/app.sqlite")).toBe(true);
|
|
13
|
+
expect(isSqliteDatabaseUrl("postgresql://localhost/db")).toBe(false);
|
|
14
|
+
expect(isSqliteDatabaseUrl("mysql://localhost/db")).toBe(false);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe("encodeWriteArgs / decodeReadResult", () => {
|
|
19
|
+
it("round-trips Json-like fields for AuditLog", () => {
|
|
20
|
+
const payload = { title: "Hello", count: 2 };
|
|
21
|
+
const encoded = encodeWriteArgs("AuditLog", {
|
|
22
|
+
data: { action: "update", before: payload, after: { ...payload, count: 3 } }
|
|
23
|
+
});
|
|
24
|
+
expect(encoded.data).toMatchObject({
|
|
25
|
+
action: "update",
|
|
26
|
+
before: JSON.stringify(payload),
|
|
27
|
+
after: JSON.stringify({ ...payload, count: 3 })
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const decoded = decodeReadResult("AuditLog", {
|
|
31
|
+
id: "1",
|
|
32
|
+
action: "update",
|
|
33
|
+
before: JSON.stringify(payload),
|
|
34
|
+
after: JSON.stringify({ ...payload, count: 3 })
|
|
35
|
+
}) as Record<string, unknown>;
|
|
36
|
+
expect(decoded.before).toEqual(payload);
|
|
37
|
+
expect(decoded.after).toEqual({ ...payload, count: 3 });
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("round-trips scopes array for ApiToken", () => {
|
|
41
|
+
const scopes = ["posts.read", "users.read"];
|
|
42
|
+
const encoded = encodeWriteArgs("ApiToken", { data: { name: "t", scopes } });
|
|
43
|
+
expect((encoded.data as Record<string, unknown>).scopes).toBe(JSON.stringify(scopes));
|
|
44
|
+
|
|
45
|
+
const decoded = decodeReadResult("ApiToken", {
|
|
46
|
+
id: "1",
|
|
47
|
+
name: "t",
|
|
48
|
+
scopes: JSON.stringify(scopes)
|
|
49
|
+
}) as Record<string, unknown>;
|
|
50
|
+
expect(decoded.scopes).toEqual(scopes);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("leaves non-codec models unchanged", () => {
|
|
54
|
+
const data = { email: "a@b.dev", passwordHash: "x" };
|
|
55
|
+
expect(encodeWriteArgs("User", { data }).data).toEqual(data);
|
|
56
|
+
expect(decodeReadResult("User", data)).toEqual(data);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("covers every model listed in SQLITE_JSON_FIELDS", () => {
|
|
60
|
+
expect(Object.keys(SQLITE_JSON_FIELDS).length).toBeGreaterThan(0);
|
|
61
|
+
for (const [model, fields] of Object.entries(SQLITE_JSON_FIELDS)) {
|
|
62
|
+
const sample = Object.fromEntries(fields.map((f) => [f, { k: f }]));
|
|
63
|
+
const encoded = encodeWriteArgs(model, { data: sample });
|
|
64
|
+
for (const field of fields) {
|
|
65
|
+
expect(typeof (encoded.data as Record<string, unknown>)[field]).toBe("string");
|
|
66
|
+
}
|
|
67
|
+
const decoded = decodeReadResult(model, {
|
|
68
|
+
id: "x",
|
|
69
|
+
...Object.fromEntries(fields.map((f) => [f, JSON.stringify({ k: f })]))
|
|
70
|
+
}) as Record<string, unknown>;
|
|
71
|
+
for (const field of fields) {
|
|
72
|
+
expect(decoded[field]).toEqual({ k: field });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQLite has no native Json type. The CLI rewrites Json / scalar-list columns to
|
|
3
|
+
* String when scaffolding for SQLite. This module JSON-encodes those columns on
|
|
4
|
+
* write and JSON-decodes them on read so the rest of the API keeps working with
|
|
5
|
+
* objects/arrays as on PostgreSQL/MySQL.
|
|
6
|
+
*
|
|
7
|
+
* On PostgreSQL and MySQL this module is a no-op (isSqliteDatabaseUrl is false).
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** Prisma model name → fields stored as JSON text on SQLite. */
|
|
11
|
+
export const SQLITE_JSON_FIELDS: Readonly<Record<string, readonly string[]>> = {
|
|
12
|
+
AuditLog: ["before", "after"],
|
|
13
|
+
Setting: ["value"],
|
|
14
|
+
ApiToken: ["scopes"],
|
|
15
|
+
JobLog: ["payload"],
|
|
16
|
+
Product: ["metadata"],
|
|
17
|
+
Order: ["metadata"],
|
|
18
|
+
Transaction: ["metadata"],
|
|
19
|
+
WebhookLog: ["payload"],
|
|
20
|
+
AiMessage: ["meta"],
|
|
21
|
+
AiArtifact: ["meta"]
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export function isSqliteDatabaseUrl(url: string | undefined): boolean {
|
|
25
|
+
return (url ?? "").trim().toLowerCase().startsWith("file:");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function jsonFieldsForModel(model: string): readonly string[] {
|
|
29
|
+
return SQLITE_JSON_FIELDS[model] ?? [];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function encodeValue(value: unknown): unknown {
|
|
33
|
+
if (value === null || value === undefined) return value;
|
|
34
|
+
if (typeof value === "string") return value;
|
|
35
|
+
return JSON.stringify(value);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function decodeValue(value: unknown): unknown {
|
|
39
|
+
if (value === null || value === undefined) return value;
|
|
40
|
+
if (typeof value !== "string") return value;
|
|
41
|
+
try {
|
|
42
|
+
return JSON.parse(value) as unknown;
|
|
43
|
+
} catch {
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function encodeData(model: string, data: unknown): unknown {
|
|
49
|
+
if (!data || typeof data !== "object" || Array.isArray(data)) return data;
|
|
50
|
+
const fields = jsonFieldsForModel(model);
|
|
51
|
+
if (!fields.length) return data;
|
|
52
|
+
const copy = { ...(data as Record<string, unknown>) };
|
|
53
|
+
for (const field of fields) {
|
|
54
|
+
if (field in copy) copy[field] = encodeValue(copy[field]);
|
|
55
|
+
}
|
|
56
|
+
return copy;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function decodeRecord(model: string, record: unknown): unknown {
|
|
60
|
+
if (!record || typeof record !== "object" || Array.isArray(record)) return record;
|
|
61
|
+
const fields = jsonFieldsForModel(model);
|
|
62
|
+
if (!fields.length) return record;
|
|
63
|
+
const copy = { ...(record as Record<string, unknown>) };
|
|
64
|
+
for (const field of fields) {
|
|
65
|
+
if (field in copy) copy[field] = decodeValue(copy[field]);
|
|
66
|
+
}
|
|
67
|
+
return copy;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function decodeMany(model: string, records: unknown): unknown {
|
|
71
|
+
if (!Array.isArray(records)) return records;
|
|
72
|
+
return records.map((r) => decodeRecord(model, r));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
type QueryArgs = { data?: unknown; create?: unknown; update?: unknown };
|
|
76
|
+
|
|
77
|
+
/** Encodes JSON fields inside Prisma write args (`data`, `create`, `update`). */
|
|
78
|
+
export function encodeWriteArgs(model: string, args: QueryArgs): QueryArgs {
|
|
79
|
+
const next = { ...args };
|
|
80
|
+
if (next.data !== undefined) next.data = encodeData(model, next.data);
|
|
81
|
+
if (next.create !== undefined) next.create = encodeData(model, next.create);
|
|
82
|
+
if (next.update !== undefined) next.update = encodeData(model, next.update);
|
|
83
|
+
return next;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function decodeReadResult(model: string, result: unknown): unknown {
|
|
87
|
+
if (Array.isArray(result)) return decodeMany(model, result);
|
|
88
|
+
return decodeRecord(model, result);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
type PrismaQueryHook = {
|
|
92
|
+
args: QueryArgs;
|
|
93
|
+
query: (args: QueryArgs) => Promise<unknown>;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/** Prisma Client extension — only applied when DATABASE_URL is a SQLite file URL. */
|
|
97
|
+
export function sqliteJsonCodecExtension() {
|
|
98
|
+
const queryConfig: Record<string, Record<string, (ctx: PrismaQueryHook) => Promise<unknown>>> = {};
|
|
99
|
+
|
|
100
|
+
for (const model of Object.keys(SQLITE_JSON_FIELDS)) {
|
|
101
|
+
queryConfig[model] = {
|
|
102
|
+
async create({ args, query }) {
|
|
103
|
+
const result = await query(encodeWriteArgs(model, args));
|
|
104
|
+
return decodeRecord(model, result);
|
|
105
|
+
},
|
|
106
|
+
async createMany({ args, query }) {
|
|
107
|
+
if (args.data && Array.isArray(args.data)) {
|
|
108
|
+
return query({ ...args, data: args.data.map((row) => encodeData(model, row)) });
|
|
109
|
+
}
|
|
110
|
+
return query(args);
|
|
111
|
+
},
|
|
112
|
+
async update({ args, query }) {
|
|
113
|
+
const result = await query(encodeWriteArgs(model, args));
|
|
114
|
+
return decodeRecord(model, result);
|
|
115
|
+
},
|
|
116
|
+
async updateMany({ args, query }) {
|
|
117
|
+
return query(encodeWriteArgs(model, args));
|
|
118
|
+
},
|
|
119
|
+
async upsert({ args, query }) {
|
|
120
|
+
const result = await query(encodeWriteArgs(model, args));
|
|
121
|
+
return decodeRecord(model, result);
|
|
122
|
+
},
|
|
123
|
+
async findUnique({ args, query }) {
|
|
124
|
+
const result = await query(args);
|
|
125
|
+
return decodeRecord(model, result);
|
|
126
|
+
},
|
|
127
|
+
async findFirst({ args, query }) {
|
|
128
|
+
const result = await query(args);
|
|
129
|
+
return decodeRecord(model, result);
|
|
130
|
+
},
|
|
131
|
+
async findMany({ args, query }) {
|
|
132
|
+
const result = await query(args);
|
|
133
|
+
return decodeMany(model, result);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return { name: "sqliteJsonCodec", query: queryConfig };
|
|
139
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
2
|
+
import { isSqliteDatabaseUrl } from "./json-field-codec";
|
|
3
|
+
|
|
4
|
+
describe("PrismaService SQLite wiring", () => {
|
|
5
|
+
const original = process.env.DATABASE_URL;
|
|
6
|
+
|
|
7
|
+
afterEach(() => {
|
|
8
|
+
if (original === undefined) delete process.env.DATABASE_URL;
|
|
9
|
+
else process.env.DATABASE_URL = original;
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("detects SQLite from DATABASE_URL (used by PrismaService constructor)", () => {
|
|
13
|
+
process.env.DATABASE_URL = "file:./dev.db";
|
|
14
|
+
expect(isSqliteDatabaseUrl(process.env.DATABASE_URL)).toBe(true);
|
|
15
|
+
|
|
16
|
+
process.env.DATABASE_URL = "postgresql://localhost/db";
|
|
17
|
+
expect(isSqliteDatabaseUrl(process.env.DATABASE_URL)).toBe(false);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
import { Injectable, OnModuleDestroy, OnModuleInit } from "@nestjs/common";
|
|
2
2
|
import { PrismaClient } from "@prisma/client";
|
|
3
|
+
import { isSqliteDatabaseUrl, sqliteJsonCodecExtension } from "./json-field-codec";
|
|
3
4
|
|
|
4
5
|
@Injectable()
|
|
5
6
|
export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
|
|
7
|
+
constructor() {
|
|
8
|
+
const url = process.env.DATABASE_URL;
|
|
9
|
+
if (isSqliteDatabaseUrl(url)) {
|
|
10
|
+
const client = new PrismaClient();
|
|
11
|
+
// Constructor return replaces `this` — extended client keeps full delegate API.
|
|
12
|
+
return client.$extends(
|
|
13
|
+
sqliteJsonCodecExtension() as Parameters<PrismaClient["$extends"]>[0]
|
|
14
|
+
) as unknown as PrismaService;
|
|
15
|
+
}
|
|
16
|
+
super();
|
|
17
|
+
}
|
|
18
|
+
|
|
6
19
|
async onModuleInit() {
|
|
7
20
|
await this.$connect();
|
|
8
21
|
}
|
|
@@ -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
|
+
});
|
|
@@ -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
|
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": {
|
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");
|