openadminjs 0.1.7 → 0.1.8
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/dist/create-project.js +27 -4
- package/dist/create-project.test.js +57 -41
- package/dist/index.js +16 -5
- package/package.json +4 -2
- package/template/.env.example +2 -2
- package/template/README.md +24 -3
- package/template/apps/admin/app/api/auth/login/route.ts +51 -0
- package/template/apps/admin/app/api/auth/logout/route.ts +11 -0
- package/template/apps/admin/app/api/auth/refresh/route.ts +46 -0
- package/template/apps/admin/app/api-tokens/page.tsx +253 -0
- package/template/apps/admin/app/audit-logs/page.tsx +5 -0
- package/template/apps/admin/app/dashboard/page.tsx +392 -0
- package/template/apps/admin/app/files/page.tsx +5 -0
- package/template/apps/admin/app/globals.css +206 -0
- package/template/apps/admin/app/jobs/page.tsx +19 -0
- package/template/apps/admin/app/layout.tsx +57 -0
- package/template/apps/admin/app/login/page.test.tsx +18 -0
- package/template/apps/admin/app/login/page.tsx +161 -0
- package/template/apps/admin/app/login/safe-next-param.ts +4 -0
- package/template/apps/admin/app/notifications/page.tsx +146 -0
- package/template/apps/admin/app/page.tsx +5 -0
- package/template/apps/admin/app/plugins/page.tsx +407 -0
- package/template/apps/admin/app/profile/page.tsx +116 -0
- package/template/apps/admin/app/resources/[resource]/[id]/edit/page.tsx +45 -0
- package/template/apps/admin/app/resources/[resource]/[id]/page.tsx +449 -0
- package/template/apps/admin/app/resources/[resource]/create/page.tsx +34 -0
- package/template/apps/admin/app/resources/[resource]/page.tsx +100 -0
- package/template/apps/admin/app/settings/page.tsx +233 -0
- package/template/apps/admin/components/ai-assistant-widget.tsx +684 -0
- package/template/apps/admin/components/app-shell.tsx +305 -0
- package/template/apps/admin/components/auth-guard.test.tsx +55 -0
- package/template/apps/admin/components/auth-guard.tsx +39 -0
- package/template/apps/admin/components/jobs-panel.tsx +103 -0
- package/template/apps/admin/components/logo.tsx +30 -0
- package/template/apps/admin/components/resource-form.tsx +349 -0
- package/template/apps/admin/components/resource-table.tsx +277 -0
- package/template/apps/admin/lib/ai-events.ts +23 -0
- package/template/apps/admin/lib/api.test.ts +118 -0
- package/template/apps/admin/lib/api.ts +135 -0
- package/template/apps/admin/lib/auth-flow.e2e.test.ts +79 -0
- package/template/apps/admin/lib/brand.ts +14 -0
- package/template/apps/admin/lib/locale.ts +49 -0
- package/template/apps/admin/lib/tokens.ts +93 -0
- package/template/apps/admin/middleware.ts +58 -0
- package/template/apps/admin/next-env.d.ts +6 -0
- package/template/apps/admin/next.config.mjs +7 -0
- package/template/apps/admin/package.json +44 -0
- package/template/apps/admin/postcss.config.mjs +6 -0
- package/template/apps/admin/public/brand/apple-touch-icon.png +0 -0
- package/template/apps/admin/public/brand/favicon.svg +1 -0
- package/template/apps/admin/public/brand/og-image.png +0 -0
- package/template/apps/admin/public/brand/openadminjs-icon-new.png +0 -0
- package/template/apps/admin/public/brand/openadminjs-logo-monochrome.png +0 -0
- package/template/apps/admin/public/brand/openadminjs-logo-new.png +0 -0
- package/template/apps/admin/tailwind.config.ts +37 -0
- package/template/apps/admin/tsconfig.json +23 -0
- package/template/apps/admin/vitest.config.ts +7 -0
- package/template/apps/api/package.json +56 -0
- package/template/apps/api/plugins.manifest.example.json +34 -0
- package/template/apps/api/plugins.manifest.json +4 -0
- package/template/apps/api/src/access/catalog.ts +112 -0
- package/template/apps/api/src/access/derive-permissions.test.ts +26 -0
- package/template/apps/api/src/access/derive-permissions.ts +36 -0
- package/template/apps/api/src/access/public-catalog.ts +28 -0
- package/template/apps/api/src/admin/admin-ai.controller.ts +125 -0
- package/template/apps/api/src/admin/admin-ai.events.ts +23 -0
- package/template/apps/api/src/admin/admin-ai.service.ts +1271 -0
- package/template/apps/api/src/admin/admin-analytics.service.ts +164 -0
- package/template/apps/api/src/admin/admin-plugins.controller.ts +32 -0
- package/template/apps/api/src/admin/admin-plugins.service.ts +267 -0
- package/template/apps/api/src/admin/admin-resource.service.test.ts +118 -0
- package/template/apps/api/src/admin/admin-resource.service.ts +375 -0
- package/template/apps/api/src/admin/admin.controller.ts +72 -0
- package/template/apps/api/src/admin/admin.module.ts +30 -0
- package/template/apps/api/src/admin/dto/plugins.dto.ts +55 -0
- package/template/apps/api/src/admin/validate-resource-payload.test.ts +44 -0
- package/template/apps/api/src/admin/validate-resource-payload.ts +103 -0
- package/template/apps/api/src/app.module.ts +45 -0
- package/template/apps/api/src/auth/auth.controller.ts +70 -0
- package/template/apps/api/src/auth/auth.dto.ts +49 -0
- package/template/apps/api/src/auth/auth.module.ts +30 -0
- package/template/apps/api/src/auth/auth.service.test.ts +75 -0
- package/template/apps/api/src/auth/auth.service.ts +231 -0
- package/template/apps/api/src/common/auth-realm.decorator.ts +6 -0
- package/template/apps/api/src/common/auth.guard.test.ts +61 -0
- package/template/apps/api/src/common/auth.guard.ts +78 -0
- package/template/apps/api/src/common/casl-ability.factory.test.ts +33 -0
- package/template/apps/api/src/common/casl-ability.factory.ts +41 -0
- package/template/apps/api/src/common/current-user.decorator.ts +6 -0
- package/template/apps/api/src/common/permission.decorator.ts +7 -0
- package/template/apps/api/src/common/permissions.guard.ts +31 -0
- package/template/apps/api/src/common/prisma.service.ts +13 -0
- package/template/apps/api/src/health/health.controller.ts +25 -0
- package/template/apps/api/src/mail/mail.module.ts +9 -0
- package/template/apps/api/src/mail/mail.service.ts +115 -0
- package/template/apps/api/src/main.ts +37 -0
- package/template/apps/api/src/plugins/bootstrap.ts +4 -0
- package/template/apps/api/src/plugins/bundled/admin-widget.plugin.ts +25 -0
- package/template/apps/api/src/plugins/bundled/hello.plugin.ts +19 -0
- package/template/apps/api/src/plugins/bundled/image-optimizer.plugin.ts +22 -0
- package/template/apps/api/src/plugins/bundled/registry.ts +13 -0
- package/template/apps/api/src/plugins/bundled/seo.plugin.ts +25 -0
- package/template/apps/api/src/plugins/manifest-path.ts +35 -0
- package/template/apps/api/src/plugins/manifest.schema.test.ts +36 -0
- package/template/apps/api/src/plugins/manifest.schema.ts +58 -0
- package/template/apps/api/src/plugins/plugin-api.interceptor.ts +47 -0
- package/template/apps/api/src/plugins/plugin-loader.ts +134 -0
- package/template/apps/api/src/plugins/plugin-runtime.test.ts +24 -0
- package/template/apps/api/src/plugins/plugin-runtime.ts +85 -0
- package/template/apps/api/src/queue/queue.controller.ts +28 -0
- package/template/apps/api/src/queue/queue.module.ts +23 -0
- package/template/apps/api/src/queue/queue.processor.ts +47 -0
- package/template/apps/api/src/queue/queue.service.ts +50 -0
- package/template/apps/api/src/resources/categories.resource.ts +21 -0
- package/template/apps/api/src/resources/commerce.resource.ts +157 -0
- package/template/apps/api/src/resources/operations.resource.ts +111 -0
- package/template/apps/api/src/resources/posts.resource.ts +88 -0
- package/template/apps/api/src/resources/registry.ts +27 -0
- package/template/apps/api/src/resources/resource-hooks.install.ts +18 -0
- package/template/apps/api/src/resources/resource-hooks.registry.test.ts +72 -0
- package/template/apps/api/src/resources/resource-hooks.registry.ts +66 -0
- package/template/apps/api/src/resources/resource-hooks.runner.ts +93 -0
- package/template/apps/api/src/resources/system.resource.ts +51 -0
- package/template/apps/api/src/resources/users.resource.ts +19 -0
- package/template/apps/api/src/store/payment/payment.controller.ts +98 -0
- package/template/apps/api/src/store/payment/payment.module.ts +14 -0
- package/template/apps/api/src/store/payment/payment.provider.ts +38 -0
- package/template/apps/api/src/store/payment/payment.service.ts +235 -0
- package/template/apps/api/src/store/store.controller.ts +26 -0
- package/template/apps/api/src/store/store.module.ts +12 -0
- package/template/apps/api/src/test-setup.ts +1 -0
- package/template/apps/api/tsconfig.json +11 -0
- package/template/apps/api/vitest.config.ts +21 -0
- package/template/apps/web/lib/openadmin-client.ts +11 -0
- package/template/apps/web/lib/seo.test.ts +41 -0
- package/template/apps/web/lib/seo.ts +24 -13
- package/template/apps/web/next-env.d.ts +4 -0
- package/template/apps/web/package.json +2 -1
- package/template/apps/web/test/next-stub.ts +7 -0
- package/template/apps/web/vitest.config.ts +19 -0
- package/template/package.json +18 -11
- package/template/packages/auth/package.json +17 -0
- package/template/packages/auth/src/index.test.ts +10 -0
- package/template/packages/auth/src/index.ts +17 -0
- package/template/packages/auth/tsconfig.json +8 -0
- package/template/packages/brand/apps/admin/public/brand/apple-touch-icon.png +0 -0
- package/template/packages/brand/apps/admin/public/brand/favicon.svg +1 -0
- package/template/packages/brand/apps/admin/public/brand/og-image.png +0 -0
- package/template/packages/brand/apps/admin/public/brand/openadminjs-icon-new.png +0 -0
- package/template/packages/brand/apps/admin/public/brand/openadminjs-logo-monochrome.png +0 -0
- package/template/packages/brand/apps/admin/public/brand/openadminjs-logo-new.png +0 -0
- package/template/packages/brand/apps/web/public/brand/apple-touch-icon.png +0 -0
- package/template/packages/brand/apps/web/public/brand/favicon.svg +1 -0
- package/template/packages/brand/apps/web/public/brand/og-image.png +0 -0
- package/template/packages/brand/apps/web/public/brand/openadminjs-icon-new.png +0 -0
- package/template/packages/brand/apps/web/public/brand/openadminjs-logo-monochrome.png +0 -0
- package/template/packages/brand/apps/web/public/brand/openadminjs-logo-new.png +0 -0
- package/template/packages/brand/package.json +19 -0
- package/template/packages/brand/site/assets/brand/favicon.svg +1 -0
- package/template/packages/brand/site/assets/brand/og-image.svg +1 -0
- package/template/packages/brand/site/assets/brand/openadminjs-icon.svg +1 -0
- package/template/packages/brand/site/assets/brand/openadminjs-logo-dark.svg +1 -0
- package/template/packages/brand/site/assets/brand/openadminjs-logo-horizontal.svg +1 -0
- package/template/packages/brand/site/assets/brand/openadminjs-logo-monochrome.svg +1 -0
- package/template/packages/brand/site/assets/brand/openadminjs-logo.svg +1 -0
- package/template/packages/brand/src/generate-assets.mjs +182 -0
- package/template/packages/brand/src/index.test.ts +9 -0
- package/template/packages/brand/src/index.ts +7 -0
- package/template/packages/brand/tsconfig.json +7 -0
- package/template/packages/core/package.json +20 -0
- package/template/packages/core/src/index.js +1 -0
- package/template/packages/core/src/index.test.ts +27 -0
- package/template/packages/core/src/index.ts +61 -0
- package/template/packages/core/tsconfig.json +8 -0
- package/template/packages/mail/package.json +18 -0
- package/template/packages/mail/src/index.test.ts +23 -0
- package/template/packages/mail/src/index.ts +246 -0
- package/template/packages/mail/tsconfig.json +5 -0
- package/template/packages/notifications/package.json +16 -0
- package/template/packages/notifications/src/index.test.ts +9 -0
- package/template/packages/notifications/src/index.ts +5 -0
- package/template/packages/notifications/tsconfig.json +5 -0
- package/template/packages/payments/package.json +15 -0
- package/template/packages/payments/src/index.ts +256 -0
- package/template/packages/payments/tsconfig.json +9 -0
- package/template/packages/permissions/package.json +17 -0
- package/template/packages/permissions/src/blueprints.js +57 -0
- package/template/packages/permissions/src/blueprints.test.ts +62 -0
- package/template/packages/permissions/src/blueprints.ts +89 -0
- package/template/packages/permissions/src/index.js +11 -0
- package/template/packages/permissions/src/index.test.ts +34 -0
- package/template/packages/permissions/src/index.ts +22 -0
- package/template/packages/permissions/tsconfig.json +8 -0
- package/template/packages/plugin-sdk/package.json +26 -0
- package/template/packages/plugin-sdk/src/hooks.ts +135 -0
- package/template/packages/plugin-sdk/src/index.ts +42 -0
- package/template/packages/plugin-sdk/src/sdk.test.ts +13 -0
- package/template/packages/plugin-sdk/tsconfig.json +8 -0
- package/template/packages/plugin-sdk/vitest.config.ts +5 -0
- package/template/packages/queue/package.json +16 -0
- package/template/packages/queue/src/index.test.ts +12 -0
- package/template/packages/queue/src/index.ts +6 -0
- package/template/packages/queue/tsconfig.json +5 -0
- package/template/packages/resource/package.json +17 -0
- package/template/packages/resource/src/index.js +177 -0
- package/template/packages/resource/src/index.test.ts +151 -0
- package/template/packages/resource/src/index.ts +344 -0
- package/template/packages/resource/tsconfig.json +8 -0
- package/template/packages/storage/package.json +16 -0
- package/template/packages/storage/src/index.test.ts +10 -0
- package/template/packages/storage/src/index.ts +23 -0
- package/template/packages/storage/tsconfig.json +5 -0
- package/template/prisma/migrations/20260505151751_baseline_init_all_tables/migration.sql +371 -0
- package/template/prisma/migrations/migration_lock.toml +3 -0
- package/template/prisma/schema.prisma +291 -0
- package/template/prisma/seed.ts +217 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"jsx": "preserve",
|
|
5
|
+
"noEmit": true,
|
|
6
|
+
"plugins": [
|
|
7
|
+
{
|
|
8
|
+
"name": "next"
|
|
9
|
+
}
|
|
10
|
+
],
|
|
11
|
+
"allowJs": true,
|
|
12
|
+
"incremental": true
|
|
13
|
+
},
|
|
14
|
+
"include": [
|
|
15
|
+
"next-env.d.ts",
|
|
16
|
+
"**/*.ts",
|
|
17
|
+
"**/*.tsx",
|
|
18
|
+
".next/types/**/*.ts"
|
|
19
|
+
],
|
|
20
|
+
"exclude": [
|
|
21
|
+
"node_modules"
|
|
22
|
+
]
|
|
23
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openadminjs/api",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "tsx watch src/main.ts",
|
|
8
|
+
"build": "nest build",
|
|
9
|
+
"start": "node dist/apps/api/src/main.js",
|
|
10
|
+
"lint": "tsc -p tsconfig.json --noEmit",
|
|
11
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
12
|
+
"test": "vitest run",
|
|
13
|
+
"db:migrate": "prisma migrate dev --schema ../../prisma/schema.prisma",
|
|
14
|
+
"db:seed": "prisma db seed --schema ../../prisma/schema.prisma"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@casl/ability": "^6.8.1",
|
|
18
|
+
"@nestjs/bullmq": "^11.0.4",
|
|
19
|
+
"@nestjs/common": "^10.4.15",
|
|
20
|
+
"@nestjs/config": "^3.3.0",
|
|
21
|
+
"@nestjs/core": "^10.4.15",
|
|
22
|
+
"@nestjs/jwt": "^10.2.0",
|
|
23
|
+
"@nestjs/platform-express": "^10.4.15",
|
|
24
|
+
"@nestjs/swagger": "^8.1.0",
|
|
25
|
+
"@nestjs/throttler": "^6.3.0",
|
|
26
|
+
"@openadminjs/core": "workspace:*",
|
|
27
|
+
"@openadminjs/mail": "workspace:*",
|
|
28
|
+
"@openadminjs/payments": "workspace:*",
|
|
29
|
+
"@openadminjs/permissions": "workspace:*",
|
|
30
|
+
"@openadminjs/plugin-sdk": "workspace:*",
|
|
31
|
+
"nodemailer": "^6.9.16",
|
|
32
|
+
"stripe": "^17.7.0",
|
|
33
|
+
"@prisma/client": "^6.1.0",
|
|
34
|
+
"bcryptjs": "^2.4.3",
|
|
35
|
+
"bullmq": "^5.76.4",
|
|
36
|
+
"class-transformer": "^0.5.1",
|
|
37
|
+
"class-validator": "^0.14.1",
|
|
38
|
+
"helmet": "^8.0.0",
|
|
39
|
+
"ioredis": "^5.10.1",
|
|
40
|
+
"reflect-metadata": "^0.2.2",
|
|
41
|
+
"rxjs": "^7.8.1",
|
|
42
|
+
"zod": "^3.24.1"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@nestjs/cli": "^10.4.8",
|
|
46
|
+
"@types/bcryptjs": "^2.4.6",
|
|
47
|
+
"@types/nodemailer": "^6.4.17",
|
|
48
|
+
"prisma": "^6.1.0",
|
|
49
|
+
"tsx": "4.19.2",
|
|
50
|
+
"typescript": "^5.7.2",
|
|
51
|
+
"vitest": "^2.1.8"
|
|
52
|
+
},
|
|
53
|
+
"prisma": {
|
|
54
|
+
"seed": "tsx ../../prisma/seed.ts"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"plugins": [
|
|
4
|
+
{
|
|
5
|
+
"id": "io.openadminjs.hello",
|
|
6
|
+
"enabled": true,
|
|
7
|
+
"trustMode": "trusted",
|
|
8
|
+
"capabilities": ["resource.hooks"],
|
|
9
|
+
"bundled": "hello",
|
|
10
|
+
"config": { "tag": "optional-config-passed-to-plugin" }
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"id": "io.openadminjs.seo",
|
|
14
|
+
"enabled": false,
|
|
15
|
+
"trustMode": "sandboxed",
|
|
16
|
+
"capabilities": ["seo.extend"],
|
|
17
|
+
"bundled": "seo",
|
|
18
|
+
"config": {}
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"id": "com.vendor.billing",
|
|
22
|
+
"enabled": false,
|
|
23
|
+
"trustMode": "sandboxed",
|
|
24
|
+
"capabilities": ["resource.hooks", "api.routes", "jobs.run", "admin.ui.extend"],
|
|
25
|
+
"package": "@vendor/openadmin-billing",
|
|
26
|
+
"marketplace": {
|
|
27
|
+
"listingUrl": "https://example.com/plugins/billing",
|
|
28
|
+
"productId": "sku-123",
|
|
29
|
+
"licenseKey": "signing-key-or-token-for-future-use"
|
|
30
|
+
},
|
|
31
|
+
"config": { "currency": "EUR" }
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { ResourceConfig } from "@openadminjs/core";
|
|
2
|
+
import type { RoleBlueprint } from "@openadminjs/permissions";
|
|
3
|
+
import { resources } from "../resources/registry";
|
|
4
|
+
import { collectPermissionSlugsFromResources, slugToDefaultLabels } from "./derive-permissions";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Human labels for slugs that never appear on `defineResource.permissions`
|
|
8
|
+
* (wildcard, cross-cutting keys, list-scope bypass, etc.).
|
|
9
|
+
*/
|
|
10
|
+
const PERMISSION_LABEL_OVERRIDES: Record<string, { en: string; ru: string }> = {
|
|
11
|
+
"*": { en: "All permissions", ru: "Все разрешения" },
|
|
12
|
+
"roles.read": { en: "View roles", ru: "Просмотр ролей" },
|
|
13
|
+
"notifications.read.all": { en: "View all users' notifications", ru: "Все уведомления" },
|
|
14
|
+
"users.read": { en: "View users", ru: "Просмотр пользователей" },
|
|
15
|
+
"posts.read": { en: "View posts", ru: "Просмотр записей" },
|
|
16
|
+
"posts.create": { en: "Create posts", ru: "Создание записей" },
|
|
17
|
+
"posts.update": { en: "Update posts", ru: "Изменение записей" },
|
|
18
|
+
"posts.delete": { en: "Delete posts", ru: "Удаление записей" },
|
|
19
|
+
"posts.publish": { en: "Publish posts", ru: "Публикация записей" },
|
|
20
|
+
"categories.read": { en: "View categories", ru: "Просмотр категорий" },
|
|
21
|
+
"categories.create": { en: "Create categories", ru: "Создание категорий" },
|
|
22
|
+
"categories.update": { en: "Update categories", ru: "Изменение категорий" },
|
|
23
|
+
"categories.delete": { en: "Delete categories", ru: "Удаление категорий" },
|
|
24
|
+
"files.read": { en: "View files", ru: "Просмотр файлов" },
|
|
25
|
+
"files.create": { en: "Upload files", ru: "Загрузка файлов" },
|
|
26
|
+
"files.delete": { en: "Delete files", ru: "Удаление файлов" },
|
|
27
|
+
"audit-logs.read": { en: "View audit logs", ru: "Аудит" },
|
|
28
|
+
"settings.read": { en: "View settings", ru: "Настройки (чтение)" },
|
|
29
|
+
"settings.update": { en: "Update settings", ru: "Настройки (запись)" },
|
|
30
|
+
"api-tokens.read": { en: "View API tokens", ru: "Токены API" },
|
|
31
|
+
"api-tokens.create": { en: "Create API tokens", ru: "Создание токенов" },
|
|
32
|
+
"api-tokens.delete": { en: "Delete API tokens", ru: "Удаление токенов" },
|
|
33
|
+
"api-tokens.revoke": { en: "Revoke API tokens", ru: "Отзыв токенов" },
|
|
34
|
+
"notifications.read": { en: "View notifications", ru: "Уведомления" },
|
|
35
|
+
"notifications.create": { en: "Create notifications", ru: "Создание уведомлений" },
|
|
36
|
+
"notifications.update": { en: "Update notifications", ru: "Изменение уведомлений" },
|
|
37
|
+
"notifications.delete": { en: "Delete notifications", ru: "Удаление уведомлений" },
|
|
38
|
+
"jobs.read": { en: "View jobs", ru: "Задачи" },
|
|
39
|
+
"jobs.dispatch": { en: "Dispatch jobs", ru: "Запуск задач" },
|
|
40
|
+
"ai.chat": { en: "Use AI consultant", ru: "AI-консультант" }
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export function buildPermissionCatalog(
|
|
44
|
+
allResources: readonly ResourceConfig[],
|
|
45
|
+
labelOverrides: Record<string, { en: string; ru: string }>
|
|
46
|
+
): { name: string; label: { en: string; ru: string } }[] {
|
|
47
|
+
const slugs = collectPermissionSlugsFromResources(allResources);
|
|
48
|
+
for (const key of Object.keys(labelOverrides)) {
|
|
49
|
+
slugs.add(key);
|
|
50
|
+
}
|
|
51
|
+
return [...slugs]
|
|
52
|
+
.sort((a, b) => a.localeCompare(b))
|
|
53
|
+
.map((name) => ({
|
|
54
|
+
name,
|
|
55
|
+
label: labelOverrides[name] ?? slugToDefaultLabels(name)
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Merged from `resources[]` introspection + manual overrides (wildcard, bypass slugs, i18n copy). */
|
|
60
|
+
export const permissionCatalog = buildPermissionCatalog(resources, PERMISSION_LABEL_OVERRIDES);
|
|
61
|
+
|
|
62
|
+
/** Slugs passed to blueprint expansion (omit "*" — wildcard adds the rest at seed time). */
|
|
63
|
+
export const catalogSlugList = permissionCatalog.map((p) => p.name).filter((n) => n !== "*");
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Declarative roles: edit this file to reshape RBAC without touching seed logic.
|
|
67
|
+
* - `inherits` pulls in another blueprint's permissions (DAG).
|
|
68
|
+
* - `"*"` grants every slug in `catalogSlugList` plus the literal "*" (superuser).
|
|
69
|
+
*/
|
|
70
|
+
export const roleBlueprints = [
|
|
71
|
+
{
|
|
72
|
+
name: "viewer",
|
|
73
|
+
label: { en: "Viewer", ru: "Наблюдатель" },
|
|
74
|
+
permissions: ["posts.read", "categories.read", "notifications.read", "jobs.read"]
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: "editor",
|
|
78
|
+
label: { en: "Editor", ru: "Редактор" },
|
|
79
|
+
inherits: ["viewer"],
|
|
80
|
+
permissions: [
|
|
81
|
+
"posts.create",
|
|
82
|
+
"posts.update",
|
|
83
|
+
"posts.delete",
|
|
84
|
+
"posts.publish",
|
|
85
|
+
"categories.create",
|
|
86
|
+
"categories.update",
|
|
87
|
+
"categories.delete",
|
|
88
|
+
"files.read",
|
|
89
|
+
"files.create",
|
|
90
|
+
"files.delete",
|
|
91
|
+
"users.read",
|
|
92
|
+
"settings.read",
|
|
93
|
+
"settings.update",
|
|
94
|
+
"api-tokens.read",
|
|
95
|
+
"api-tokens.create",
|
|
96
|
+
"api-tokens.delete",
|
|
97
|
+
"api-tokens.revoke",
|
|
98
|
+
"notifications.create",
|
|
99
|
+
"notifications.update",
|
|
100
|
+
"notifications.delete",
|
|
101
|
+
"audit-logs.read",
|
|
102
|
+
"jobs.dispatch",
|
|
103
|
+
"ai.chat"
|
|
104
|
+
]
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: "admin",
|
|
108
|
+
label: { en: "Administrator", ru: "Администратор" },
|
|
109
|
+
inherits: ["editor"],
|
|
110
|
+
permissions: ["*", "notifications.read.all", "roles.read"]
|
|
111
|
+
}
|
|
112
|
+
] as const satisfies readonly RoleBlueprint[];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { defineResource } from "@openadminjs/core";
|
|
3
|
+
import { collectPermissionSlugsFromResources } from "./derive-permissions";
|
|
4
|
+
|
|
5
|
+
describe("collectPermissionSlugsFromResources", () => {
|
|
6
|
+
it("collects resource, field, action and listScope bypass slugs", () => {
|
|
7
|
+
const r = defineResource({
|
|
8
|
+
name: "widgets",
|
|
9
|
+
label: "Widgets",
|
|
10
|
+
model: "Widget",
|
|
11
|
+
permissions: { read: "widgets.read", custom: "widgets.custom" },
|
|
12
|
+
listScope: { type: "userOwns", field: "ownerId", bypassPermissions: ["widgets.read.all"] },
|
|
13
|
+
fields: {
|
|
14
|
+
id: { type: "id", list: true },
|
|
15
|
+
secret: { type: "text", list: false, permissions: { read: "widgets.secret.read" } }
|
|
16
|
+
},
|
|
17
|
+
actions: {
|
|
18
|
+
ping: { label: "Ping", permission: "widgets.ping" }
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
const set = collectPermissionSlugsFromResources([r]);
|
|
22
|
+
expect([...set].sort()).toEqual(
|
|
23
|
+
["widgets.custom", "widgets.ping", "widgets.read", "widgets.read.all", "widgets.secret.read"].sort()
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ResourceConfig } from "@openadminjs/core";
|
|
2
|
+
|
|
3
|
+
/** Collects every permission slug referenced by resource metadata (for seeds & audits). */
|
|
4
|
+
export function collectPermissionSlugsFromResources(resources: readonly ResourceConfig[]): Set<string> {
|
|
5
|
+
const out = new Set<string>();
|
|
6
|
+
for (const r of resources) {
|
|
7
|
+
for (const v of Object.values(r.permissions)) {
|
|
8
|
+
if (typeof v === "string" && v.trim()) out.add(v);
|
|
9
|
+
}
|
|
10
|
+
for (const f of Object.values(r.fields)) {
|
|
11
|
+
if (!f.permissions) continue;
|
|
12
|
+
for (const v of Object.values(f.permissions)) {
|
|
13
|
+
if (typeof v === "string" && v.trim()) out.add(v);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (r.actions) {
|
|
17
|
+
for (const a of Object.values(r.actions)) {
|
|
18
|
+
if (a.permission?.trim()) out.add(a.permission);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const ls = r.listScope;
|
|
22
|
+
if (ls && "bypassPermissions" in ls && ls.bypassPermissions) {
|
|
23
|
+
for (const p of ls.bypassPermissions) {
|
|
24
|
+
if (typeof p === "string" && p.trim()) out.add(p);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Fallback labels when no override exists (seed stores EN string; RU kept for parity). */
|
|
32
|
+
export function slugToDefaultLabels(slug: string): { en: string; ru: string } {
|
|
33
|
+
const readable = slug.replace(/\./g, " · ").replace(/-/g, " ");
|
|
34
|
+
const title = readable.replace(/\b\w/g, (c) => c.toUpperCase());
|
|
35
|
+
return { en: title, ru: title };
|
|
36
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { RoleBlueprint } from "@openadminjs/permissions";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Storefront / public API permission slugs (separate namespace from admin resource introspection).
|
|
5
|
+
* Extend this list freely; seed syncs rows into `Permission` and assigns them to `public` realm roles.
|
|
6
|
+
*/
|
|
7
|
+
export const publicPermissionCatalog = [
|
|
8
|
+
{ name: "public.session.read", label: { en: "Read own session", ru: "Сессия (чтение)" } },
|
|
9
|
+
{ name: "public.account.read", label: { en: "Read own profile", ru: "Профиль (чтение)" } },
|
|
10
|
+
{ name: "public.account.update", label: { en: "Update own profile", ru: "Профиль (изменение)" } },
|
|
11
|
+
{ name: "public.orders.read_own", label: { en: "Read own orders", ru: "Свои заказы" } },
|
|
12
|
+
{ name: "public.orders.create", label: { en: "Place orders", ru: "Оформление заказов" } }
|
|
13
|
+
] as const;
|
|
14
|
+
|
|
15
|
+
/** Blueprints for `Role.realm === "public"` (inherits only within this realm). */
|
|
16
|
+
export const publicRoleBlueprints = [
|
|
17
|
+
{
|
|
18
|
+
name: "guest",
|
|
19
|
+
realm: "public",
|
|
20
|
+
label: { en: "Guest", ru: "Гость" }
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: "member",
|
|
24
|
+
realm: "public",
|
|
25
|
+
label: { en: "Member", ru: "Участник" },
|
|
26
|
+
permissions: ["public.session.read", "public.account.read", "public.account.update", "public.orders.read_own", "public.orders.create"]
|
|
27
|
+
}
|
|
28
|
+
] as const satisfies readonly RoleBlueprint[];
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { Body, Controller, Delete, Get, Param, Patch, Post, Put, Query, Res, UseGuards } from "@nestjs/common";
|
|
2
|
+
import { AuthGuard } from "../common/auth.guard";
|
|
3
|
+
import { RequireAuthRealm } from "../common/auth-realm.decorator";
|
|
4
|
+
import { CurrentUser } from "../common/current-user.decorator";
|
|
5
|
+
import { AdminAiService } from "./admin-ai.service";
|
|
6
|
+
import type { AiStreamErrorEvent } from "./admin-ai.events";
|
|
7
|
+
|
|
8
|
+
type UserContext = { id: string; email?: string; permissions: string[] };
|
|
9
|
+
|
|
10
|
+
@UseGuards(AuthGuard)
|
|
11
|
+
@RequireAuthRealm("admin")
|
|
12
|
+
@Controller("admin/ai")
|
|
13
|
+
export class AdminAiController {
|
|
14
|
+
constructor(private readonly ai: AdminAiService) {}
|
|
15
|
+
|
|
16
|
+
@Get("config")
|
|
17
|
+
config() {
|
|
18
|
+
return this.ai.getConfig();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@Put("config")
|
|
22
|
+
updateConfig(
|
|
23
|
+
@Body()
|
|
24
|
+
body: {
|
|
25
|
+
providers?: Array<{ id: string; label: string; kind: "openai" | "anthropic" | "gemini"; baseUrl?: string; model: string }>;
|
|
26
|
+
activeProvider?: string;
|
|
27
|
+
tokenProviderId?: string;
|
|
28
|
+
token?: string;
|
|
29
|
+
systemPrompt?: string;
|
|
30
|
+
}
|
|
31
|
+
) {
|
|
32
|
+
return this.ai.updateConfig(body);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@Post("chat")
|
|
36
|
+
chat(
|
|
37
|
+
@CurrentUser() user: UserContext,
|
|
38
|
+
@Body()
|
|
39
|
+
body: {
|
|
40
|
+
message: string;
|
|
41
|
+
pagePath?: string;
|
|
42
|
+
attachments?: Array<{ name: string; mimeType: string; contentBase64: string }>;
|
|
43
|
+
}
|
|
44
|
+
) {
|
|
45
|
+
return this.ai.chat(user, body);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@Post("chat/stream")
|
|
49
|
+
async chatStream(
|
|
50
|
+
@CurrentUser() user: UserContext,
|
|
51
|
+
@Body()
|
|
52
|
+
body: {
|
|
53
|
+
message: string;
|
|
54
|
+
pagePath?: string;
|
|
55
|
+
conversationId?: string;
|
|
56
|
+
pendingAction?: Record<string, unknown>;
|
|
57
|
+
confirmAction?: boolean;
|
|
58
|
+
attachments?: Array<{ name: string; mimeType: string; contentBase64: string }>;
|
|
59
|
+
},
|
|
60
|
+
@Res() res: { setHeader: (name: string, value: string) => void; write: (chunk: string) => void; end: () => void }
|
|
61
|
+
) {
|
|
62
|
+
res.setHeader("content-type", "text/event-stream");
|
|
63
|
+
res.setHeader("cache-control", "no-cache");
|
|
64
|
+
res.setHeader("connection", "keep-alive");
|
|
65
|
+
try {
|
|
66
|
+
for await (const event of this.ai.chatStream(user, body)) {
|
|
67
|
+
res.write(`data: ${JSON.stringify(event)}\n\n`);
|
|
68
|
+
}
|
|
69
|
+
} catch (error) {
|
|
70
|
+
const err = error as { response?: { message?: string; code?: string; details?: unknown } };
|
|
71
|
+
const payload: AiStreamErrorEvent = {
|
|
72
|
+
type: "error",
|
|
73
|
+
message: err.response?.message ?? (error instanceof Error ? error.message : "Chat stream failed"),
|
|
74
|
+
code: err.response?.code ?? "AI_STREAM_FAILED",
|
|
75
|
+
details: err.response?.details ?? null
|
|
76
|
+
};
|
|
77
|
+
res.write(`data: ${JSON.stringify(payload)}\n\n`);
|
|
78
|
+
}
|
|
79
|
+
res.end();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@Get("conversations")
|
|
83
|
+
conversations(
|
|
84
|
+
@CurrentUser() user: UserContext,
|
|
85
|
+
@Query("q") q?: string,
|
|
86
|
+
@Query("page") page?: string,
|
|
87
|
+
@Query("limit") limit?: string
|
|
88
|
+
) {
|
|
89
|
+
return this.ai.listConversations(user, q, Number(page ?? 1), Number(limit ?? 20));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
@Get("conversations/:id")
|
|
93
|
+
conversation(@CurrentUser() user: UserContext, @Param("id") id: string) {
|
|
94
|
+
return this.ai.getConversation(user, id);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@Patch("conversations/:id")
|
|
98
|
+
renameConversation(
|
|
99
|
+
@CurrentUser() user: UserContext,
|
|
100
|
+
@Param("id") id: string,
|
|
101
|
+
@Body() body: { title: string }
|
|
102
|
+
) {
|
|
103
|
+
return this.ai.renameConversation(user, id, body.title);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@Delete("conversations/:id")
|
|
107
|
+
deleteConversation(@CurrentUser() user: UserContext, @Param("id") id: string) {
|
|
108
|
+
return this.ai.deleteConversation(user, id);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
@Get("artifacts/:id/download")
|
|
112
|
+
async downloadArtifact(
|
|
113
|
+
@CurrentUser() user: UserContext,
|
|
114
|
+
@Param("id") id: string,
|
|
115
|
+
@Res() res: {
|
|
116
|
+
setHeader: (name: string, value: string) => void;
|
|
117
|
+
send: (body: Buffer) => void;
|
|
118
|
+
}
|
|
119
|
+
) {
|
|
120
|
+
const artifact = await this.ai.getArtifact(user, id);
|
|
121
|
+
res.setHeader("content-type", artifact.mimeType);
|
|
122
|
+
res.setHeader("content-disposition", `attachment; filename="${artifact.filename.replace(/"/g, "")}"`);
|
|
123
|
+
res.send(Buffer.from(artifact.contentBase64, "base64"));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type AiStreamDeltaEvent = {
|
|
2
|
+
type: "delta";
|
|
3
|
+
delta: string;
|
|
4
|
+
conversationId?: string;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type AiStreamDoneEvent = {
|
|
8
|
+
type: "done";
|
|
9
|
+
conversationId?: string;
|
|
10
|
+
reply?: string;
|
|
11
|
+
actionResult?: Record<string, unknown> | null;
|
|
12
|
+
pendingAction?: Record<string, unknown> | null;
|
|
13
|
+
requiresConfirmation?: boolean;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type AiStreamErrorEvent = {
|
|
17
|
+
type: "error";
|
|
18
|
+
message: string;
|
|
19
|
+
code?: string;
|
|
20
|
+
details?: unknown;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type AiStreamEvent = AiStreamDeltaEvent | AiStreamDoneEvent | AiStreamErrorEvent;
|