openadminjs 0.1.1
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/.env.example +9 -0
- package/.github/FUNDING.yml +3 -0
- package/.github/ISSUE_TEMPLATE/bug_report.yml +10 -0
- package/.github/ISSUE_TEMPLATE/feature_request.yml +10 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +9 -0
- package/.github/dependabot.yml +10 -0
- package/.github/workflows/ci.yml +26 -0
- package/CHANGELOG.md +5 -0
- package/CODE_OF_CONDUCT.md +3 -0
- package/CONTRIBUTING.md +11 -0
- package/LICENSE +21 -0
- package/README.md +175 -0
- package/ROADMAP.md +7 -0
- package/SECURITY.md +11 -0
- package/apps/admin/app/api/auth/login/route.ts +51 -0
- package/apps/admin/app/api/auth/logout/route.ts +11 -0
- package/apps/admin/app/api/auth/refresh/route.ts +46 -0
- package/apps/admin/app/api-tokens/page.tsx +253 -0
- package/apps/admin/app/audit-logs/page.tsx +5 -0
- package/apps/admin/app/dashboard/page.tsx +392 -0
- package/apps/admin/app/files/page.tsx +5 -0
- package/apps/admin/app/globals.css +206 -0
- package/apps/admin/app/jobs/page.tsx +19 -0
- package/apps/admin/app/layout.tsx +57 -0
- package/apps/admin/app/login/page.test.tsx +18 -0
- package/apps/admin/app/login/page.tsx +161 -0
- package/apps/admin/app/login/safe-next-param.ts +4 -0
- package/apps/admin/app/notifications/page.tsx +146 -0
- package/apps/admin/app/page.tsx +5 -0
- package/apps/admin/app/plugins/page.tsx +348 -0
- package/apps/admin/app/profile/page.tsx +116 -0
- package/apps/admin/app/resources/[resource]/[id]/edit/page.tsx +45 -0
- package/apps/admin/app/resources/[resource]/[id]/page.tsx +449 -0
- package/apps/admin/app/resources/[resource]/create/page.tsx +34 -0
- package/apps/admin/app/resources/[resource]/page.tsx +100 -0
- package/apps/admin/app/settings/page.tsx +233 -0
- package/apps/admin/components/ai-assistant-widget.tsx +684 -0
- package/apps/admin/components/app-shell.tsx +305 -0
- package/apps/admin/components/auth-guard.test.tsx +55 -0
- package/apps/admin/components/auth-guard.tsx +39 -0
- package/apps/admin/components/jobs-panel.tsx +103 -0
- package/apps/admin/components/logo.tsx +30 -0
- package/apps/admin/components/resource-form.tsx +349 -0
- package/apps/admin/components/resource-table.tsx +277 -0
- package/apps/admin/lib/ai-events.ts +23 -0
- package/apps/admin/lib/api.test.ts +118 -0
- package/apps/admin/lib/api.ts +135 -0
- package/apps/admin/lib/auth-flow.e2e.test.ts +79 -0
- package/apps/admin/lib/brand.ts +14 -0
- package/apps/admin/lib/locale.ts +49 -0
- package/apps/admin/lib/tokens.ts +93 -0
- package/apps/admin/middleware.ts +58 -0
- package/apps/admin/next-env.d.ts +6 -0
- package/apps/admin/next.config.mjs +7 -0
- package/apps/admin/package.json +44 -0
- package/apps/admin/postcss.config.mjs +6 -0
- package/apps/admin/public/brand/apple-touch-icon.png +0 -0
- package/apps/admin/public/brand/favicon.svg +1 -0
- package/apps/admin/public/brand/og-image.png +0 -0
- package/apps/admin/public/brand/openadminjs-icon-new.png +0 -0
- package/apps/admin/public/brand/openadminjs-logo-monochrome.png +0 -0
- package/apps/admin/public/brand/openadminjs-logo-new.png +0 -0
- package/apps/admin/tailwind.config.ts +37 -0
- package/apps/admin/tsconfig.json +23 -0
- package/apps/admin/vitest.config.ts +7 -0
- package/apps/api/package.json +56 -0
- package/apps/api/plugins.manifest.example.json +22 -0
- package/apps/api/plugins.manifest.json +4 -0
- package/apps/api/src/access/catalog.ts +112 -0
- package/apps/api/src/access/derive-permissions.test.ts +26 -0
- package/apps/api/src/access/derive-permissions.ts +36 -0
- package/apps/api/src/access/public-catalog.ts +28 -0
- package/apps/api/src/admin/admin-ai.controller.ts +125 -0
- package/apps/api/src/admin/admin-ai.events.ts +23 -0
- package/apps/api/src/admin/admin-ai.service.ts +1238 -0
- package/apps/api/src/admin/admin-analytics.service.ts +164 -0
- package/apps/api/src/admin/admin-plugins.controller.ts +32 -0
- package/apps/api/src/admin/admin-plugins.service.ts +253 -0
- package/apps/api/src/admin/admin-resource.service.test.ts +118 -0
- package/apps/api/src/admin/admin-resource.service.ts +375 -0
- package/apps/api/src/admin/admin.controller.ts +72 -0
- package/apps/api/src/admin/admin.module.ts +30 -0
- package/apps/api/src/admin/dto/plugins.dto.ts +37 -0
- package/apps/api/src/admin/validate-resource-payload.test.ts +44 -0
- package/apps/api/src/admin/validate-resource-payload.ts +103 -0
- package/apps/api/src/app.module.ts +37 -0
- package/apps/api/src/auth/auth.controller.ts +70 -0
- package/apps/api/src/auth/auth.dto.ts +49 -0
- package/apps/api/src/auth/auth.module.ts +30 -0
- package/apps/api/src/auth/auth.service.test.ts +75 -0
- package/apps/api/src/auth/auth.service.ts +231 -0
- package/apps/api/src/common/auth-realm.decorator.ts +6 -0
- package/apps/api/src/common/auth.guard.test.ts +61 -0
- package/apps/api/src/common/auth.guard.ts +78 -0
- package/apps/api/src/common/casl-ability.factory.test.ts +33 -0
- package/apps/api/src/common/casl-ability.factory.ts +41 -0
- package/apps/api/src/common/current-user.decorator.ts +6 -0
- package/apps/api/src/common/permission.decorator.ts +7 -0
- package/apps/api/src/common/permissions.guard.ts +31 -0
- package/apps/api/src/common/prisma.service.ts +13 -0
- package/apps/api/src/health/health.controller.ts +25 -0
- package/apps/api/src/mail/mail.module.ts +9 -0
- package/apps/api/src/mail/mail.service.ts +115 -0
- package/apps/api/src/main.ts +37 -0
- package/apps/api/src/plugins/bootstrap.ts +4 -0
- package/apps/api/src/plugins/bundled/hello.plugin.ts +19 -0
- package/apps/api/src/plugins/bundled/registry.ts +7 -0
- package/apps/api/src/plugins/manifest-path.ts +35 -0
- package/apps/api/src/plugins/manifest.schema.test.ts +28 -0
- package/apps/api/src/plugins/manifest.schema.ts +38 -0
- package/apps/api/src/plugins/plugin-loader.ts +109 -0
- package/apps/api/src/queue/queue.controller.ts +28 -0
- package/apps/api/src/queue/queue.module.ts +23 -0
- package/apps/api/src/queue/queue.processor.ts +47 -0
- package/apps/api/src/queue/queue.service.ts +50 -0
- package/apps/api/src/resources/categories.resource.ts +21 -0
- package/apps/api/src/resources/commerce.resource.ts +157 -0
- package/apps/api/src/resources/operations.resource.ts +111 -0
- package/apps/api/src/resources/posts.resource.ts +88 -0
- package/apps/api/src/resources/registry.ts +27 -0
- package/apps/api/src/resources/resource-hooks.install.ts +18 -0
- package/apps/api/src/resources/resource-hooks.registry.test.ts +72 -0
- package/apps/api/src/resources/resource-hooks.registry.ts +66 -0
- package/apps/api/src/resources/resource-hooks.runner.ts +86 -0
- package/apps/api/src/resources/system.resource.ts +51 -0
- package/apps/api/src/resources/users.resource.ts +19 -0
- package/apps/api/src/store/payment/payment.controller.ts +98 -0
- package/apps/api/src/store/payment/payment.module.ts +14 -0
- package/apps/api/src/store/payment/payment.provider.ts +38 -0
- package/apps/api/src/store/payment/payment.service.ts +235 -0
- package/apps/api/src/store/store.controller.ts +26 -0
- package/apps/api/src/store/store.module.ts +12 -0
- package/apps/api/src/test-setup.ts +1 -0
- package/apps/api/tsconfig.json +11 -0
- package/apps/api/vitest.config.ts +21 -0
- package/apps/web/README.md +12 -0
- package/apps/web/app/globals.css +12 -0
- package/apps/web/app/layout.tsx +18 -0
- package/apps/web/app/page.tsx +27 -0
- package/apps/web/app/posts/[slug]/page.tsx +38 -0
- package/apps/web/app/posts/page.tsx +20 -0
- package/apps/web/app/robots.txt/route.ts +9 -0
- package/apps/web/app/sitemap.xml/route.ts +20 -0
- package/apps/web/components/public-fields.tsx +22 -0
- package/apps/web/lib/openadmin-client.ts +82 -0
- package/apps/web/lib/seo.test.ts +41 -0
- package/apps/web/lib/seo.ts +53 -0
- package/apps/web/next-env.d.ts +6 -0
- package/apps/web/next.config.mjs +5 -0
- package/apps/web/package.json +30 -0
- package/apps/web/postcss.config.mjs +6 -0
- package/apps/web/public/brand/apple-touch-icon.png +0 -0
- package/apps/web/public/brand/favicon.svg +1 -0
- package/apps/web/public/brand/og-image.png +0 -0
- package/apps/web/public/brand/openadminjs-icon-new.png +0 -0
- package/apps/web/public/brand/openadminjs-logo-monochrome.png +0 -0
- package/apps/web/public/brand/openadminjs-logo-new.png +0 -0
- package/apps/web/tailwind.config.ts +21 -0
- package/apps/web/test/next-stub.ts +7 -0
- package/apps/web/tsconfig.json +23 -0
- package/apps/web/vitest.config.ts +19 -0
- package/docs/content/security.md +7 -0
- package/eslint.config.mjs +11 -0
- package/examples/README.md +80 -0
- package/examples/basic-admin/README.md +24 -0
- package/examples/basic-admin/package.json +17 -0
- package/examples/basic-admin/prisma/models.fragment.prisma +12 -0
- package/examples/basic-admin/src/index.test.ts +8 -0
- package/examples/basic-admin/src/index.ts +5 -0
- package/examples/basic-admin/src/resources/lead.resource.ts +30 -0
- package/examples/basic-admin/tsconfig.json +7 -0
- package/examples/basic-admin/vitest.config.ts +16 -0
- package/examples/blog-admin/README.md +18 -0
- package/examples/blog-admin/package.json +17 -0
- package/examples/blog-admin/prisma/models.fragment.prisma +30 -0
- package/examples/blog-admin/src/index.test.ts +8 -0
- package/examples/blog-admin/src/index.ts +5 -0
- package/examples/blog-admin/src/resources/authors.resource.ts +21 -0
- package/examples/blog-admin/src/resources/tags.resource.ts +20 -0
- package/examples/blog-admin/tsconfig.json +7 -0
- package/examples/blog-admin/vitest.config.ts +16 -0
- package/examples/crm-admin/README.md +17 -0
- package/examples/crm-admin/package.json +17 -0
- package/examples/crm-admin/prisma/models.fragment.prisma +50 -0
- package/examples/crm-admin/src/index.test.ts +9 -0
- package/examples/crm-admin/src/index.ts +7 -0
- package/examples/crm-admin/src/resources/activities.resource.ts +29 -0
- package/examples/crm-admin/src/resources/companies.resource.ts +21 -0
- package/examples/crm-admin/src/resources/contacts.resource.ts +24 -0
- package/examples/crm-admin/src/resources/deals.resource.ts +30 -0
- package/examples/crm-admin/tsconfig.json +7 -0
- package/examples/crm-admin/vitest.config.ts +16 -0
- package/examples/ecommerce-admin/README.md +17 -0
- package/examples/ecommerce-admin/package.json +17 -0
- package/examples/ecommerce-admin/prisma/models.fragment.prisma +43 -0
- package/examples/ecommerce-admin/src/index.test.ts +8 -0
- package/examples/ecommerce-admin/src/index.ts +7 -0
- package/examples/ecommerce-admin/src/resources/customers.resource.ts +21 -0
- package/examples/ecommerce-admin/src/resources/order-items.resource.ts +22 -0
- package/examples/ecommerce-admin/src/resources/orders.resource.ts +27 -0
- package/examples/ecommerce-admin/src/resources/products.resource.ts +23 -0
- package/examples/ecommerce-admin/tsconfig.json +7 -0
- package/examples/ecommerce-admin/vitest.config.ts +16 -0
- package/examples/marketplace-admin/README.md +17 -0
- package/examples/marketplace-admin/package.json +17 -0
- package/examples/marketplace-admin/prisma/models.fragment.prisma +32 -0
- package/examples/marketplace-admin/src/index.test.ts +8 -0
- package/examples/marketplace-admin/src/index.ts +6 -0
- package/examples/marketplace-admin/src/resources/listings.resource.ts +29 -0
- package/examples/marketplace-admin/src/resources/payouts.resource.ts +28 -0
- package/examples/marketplace-admin/src/resources/sellers.resource.ts +28 -0
- package/examples/marketplace-admin/tsconfig.json +7 -0
- package/examples/marketplace-admin/vitest.config.ts +16 -0
- package/examples/support-admin/README.md +18 -0
- package/examples/support-admin/package.json +17 -0
- package/examples/support-admin/prisma/models.fragment.prisma +20 -0
- package/examples/support-admin/src/index.test.ts +8 -0
- package/examples/support-admin/src/index.ts +5 -0
- package/examples/support-admin/src/resources/ticket-messages.resource.ts +22 -0
- package/examples/support-admin/src/resources/tickets.resource.ts +35 -0
- package/examples/support-admin/tsconfig.json +7 -0
- package/examples/support-admin/vitest.config.ts +16 -0
- package/package.json +33 -0
- package/packages/auth/package.json +17 -0
- package/packages/auth/src/index.test.ts +10 -0
- package/packages/auth/src/index.ts +17 -0
- package/packages/auth/tsconfig.json +8 -0
- package/packages/brand/apps/admin/public/brand/apple-touch-icon.png +0 -0
- package/packages/brand/apps/admin/public/brand/favicon.svg +1 -0
- package/packages/brand/apps/admin/public/brand/og-image.png +0 -0
- package/packages/brand/apps/admin/public/brand/openadminjs-icon-new.png +0 -0
- package/packages/brand/apps/admin/public/brand/openadminjs-logo-monochrome.png +0 -0
- package/packages/brand/apps/admin/public/brand/openadminjs-logo-new.png +0 -0
- package/packages/brand/apps/web/public/brand/apple-touch-icon.png +0 -0
- package/packages/brand/apps/web/public/brand/favicon.svg +1 -0
- package/packages/brand/apps/web/public/brand/og-image.png +0 -0
- package/packages/brand/apps/web/public/brand/openadminjs-icon-new.png +0 -0
- package/packages/brand/apps/web/public/brand/openadminjs-logo-monochrome.png +0 -0
- package/packages/brand/apps/web/public/brand/openadminjs-logo-new.png +0 -0
- package/packages/brand/package.json +19 -0
- package/packages/brand/site/assets/brand/favicon.svg +1 -0
- package/packages/brand/site/assets/brand/og-image.svg +1 -0
- package/packages/brand/site/assets/brand/openadminjs-icon.svg +1 -0
- package/packages/brand/site/assets/brand/openadminjs-logo-dark.svg +1 -0
- package/packages/brand/site/assets/brand/openadminjs-logo-horizontal.svg +1 -0
- package/packages/brand/site/assets/brand/openadminjs-logo-monochrome.svg +1 -0
- package/packages/brand/site/assets/brand/openadminjs-logo.svg +1 -0
- package/packages/brand/src/generate-assets.mjs +182 -0
- package/packages/brand/src/index.test.ts +9 -0
- package/packages/brand/src/index.ts +7 -0
- package/packages/brand/tsconfig.json +7 -0
- package/packages/cli/package.json +44 -0
- package/packages/cli/src/create-project.ts +227 -0
- package/packages/cli/src/index.test.ts +8 -0
- package/packages/cli/src/index.ts +90 -0
- package/packages/cli/src/resource-slug.test.ts +10 -0
- package/packages/cli/src/resource-slug.ts +4 -0
- package/packages/cli/template/.env.example +4 -0
- package/packages/cli/template/README.md +13 -0
- package/packages/cli/template/apps/web/README.md +12 -0
- package/packages/cli/template/apps/web/app/globals.css +12 -0
- package/packages/cli/template/apps/web/app/layout.tsx +18 -0
- package/packages/cli/template/apps/web/app/page.tsx +27 -0
- package/packages/cli/template/apps/web/app/posts/[slug]/page.tsx +38 -0
- package/packages/cli/template/apps/web/app/posts/page.tsx +20 -0
- package/packages/cli/template/apps/web/app/robots.txt/route.ts +9 -0
- package/packages/cli/template/apps/web/app/sitemap.xml/route.ts +20 -0
- package/packages/cli/template/apps/web/components/public-fields.tsx +22 -0
- package/packages/cli/template/apps/web/lib/openadmin-client.ts +71 -0
- package/packages/cli/template/apps/web/lib/seo.ts +42 -0
- package/packages/cli/template/apps/web/next-env.d.ts +2 -0
- package/packages/cli/template/apps/web/next.config.mjs +5 -0
- package/packages/cli/template/apps/web/package.json +29 -0
- package/packages/cli/template/apps/web/postcss.config.mjs +6 -0
- package/packages/cli/template/apps/web/public/brand/apple-touch-icon.png +0 -0
- package/packages/cli/template/apps/web/public/brand/favicon.svg +1 -0
- package/packages/cli/template/apps/web/public/brand/og-image.png +0 -0
- package/packages/cli/template/apps/web/public/brand/openadminjs-icon-new.png +0 -0
- package/packages/cli/template/apps/web/public/brand/openadminjs-logo-monochrome.png +0 -0
- package/packages/cli/template/apps/web/public/brand/openadminjs-logo-new.png +0 -0
- package/packages/cli/template/apps/web/tailwind.config.ts +21 -0
- package/packages/cli/template/apps/web/tsconfig.json +23 -0
- package/packages/cli/template/package.json +19 -0
- package/packages/cli/template/pnpm-workspace.yaml +3 -0
- package/packages/cli/tsconfig.json +10 -0
- package/packages/core/package.json +20 -0
- package/packages/core/src/index.js +1 -0
- package/packages/core/src/index.test.ts +27 -0
- package/packages/core/src/index.ts +61 -0
- package/packages/core/tsconfig.json +8 -0
- package/packages/create-openadminjs/package.json +25 -0
- package/packages/create-openadminjs/src/index.ts +70 -0
- package/packages/create-openadminjs/src/package-name.test.ts +13 -0
- package/packages/create-openadminjs/src/package-name.ts +8 -0
- package/packages/create-openadminjs/src/render-files.test.ts +26 -0
- package/packages/create-openadminjs/src/render-files.ts +21 -0
- package/packages/create-openadminjs/template/.env.example +4 -0
- package/packages/create-openadminjs/template/README.md +13 -0
- package/packages/create-openadminjs/template/apps/web/README.md +12 -0
- package/packages/create-openadminjs/template/apps/web/app/globals.css +12 -0
- package/packages/create-openadminjs/template/apps/web/app/layout.tsx +18 -0
- package/packages/create-openadminjs/template/apps/web/app/page.tsx +27 -0
- package/packages/create-openadminjs/template/apps/web/app/posts/[slug]/page.tsx +38 -0
- package/packages/create-openadminjs/template/apps/web/app/posts/page.tsx +20 -0
- package/packages/create-openadminjs/template/apps/web/app/robots.txt/route.ts +9 -0
- package/packages/create-openadminjs/template/apps/web/app/sitemap.xml/route.ts +20 -0
- package/packages/create-openadminjs/template/apps/web/components/public-fields.tsx +22 -0
- package/packages/create-openadminjs/template/apps/web/lib/openadmin-client.ts +71 -0
- package/packages/create-openadminjs/template/apps/web/lib/seo.ts +42 -0
- package/packages/create-openadminjs/template/apps/web/next-env.d.ts +2 -0
- package/packages/create-openadminjs/template/apps/web/next.config.mjs +5 -0
- package/packages/create-openadminjs/template/apps/web/package.json +29 -0
- package/packages/create-openadminjs/template/apps/web/postcss.config.mjs +6 -0
- package/packages/create-openadminjs/template/apps/web/public/brand/apple-touch-icon.png +0 -0
- package/packages/create-openadminjs/template/apps/web/public/brand/favicon.svg +1 -0
- package/packages/create-openadminjs/template/apps/web/public/brand/og-image.png +0 -0
- package/packages/create-openadminjs/template/apps/web/public/brand/openadminjs-icon-new.png +0 -0
- package/packages/create-openadminjs/template/apps/web/public/brand/openadminjs-logo-monochrome.png +0 -0
- package/packages/create-openadminjs/template/apps/web/public/brand/openadminjs-logo-new.png +0 -0
- package/packages/create-openadminjs/template/apps/web/tailwind.config.ts +21 -0
- package/packages/create-openadminjs/template/apps/web/tsconfig.json +23 -0
- package/packages/create-openadminjs/template/package.json +19 -0
- package/packages/create-openadminjs/template/pnpm-workspace.yaml +3 -0
- package/packages/create-openadminjs/tsconfig.json +10 -0
- package/packages/mail/package.json +18 -0
- package/packages/mail/src/index.test.ts +23 -0
- package/packages/mail/src/index.ts +246 -0
- package/packages/mail/tsconfig.json +5 -0
- package/packages/notifications/package.json +16 -0
- package/packages/notifications/src/index.test.ts +9 -0
- package/packages/notifications/src/index.ts +5 -0
- package/packages/notifications/tsconfig.json +5 -0
- package/packages/payments/package.json +15 -0
- package/packages/payments/src/index.ts +256 -0
- package/packages/payments/tsconfig.json +9 -0
- package/packages/permissions/package.json +17 -0
- package/packages/permissions/src/blueprints.js +57 -0
- package/packages/permissions/src/blueprints.test.ts +62 -0
- package/packages/permissions/src/blueprints.ts +89 -0
- package/packages/permissions/src/index.js +11 -0
- package/packages/permissions/src/index.test.ts +34 -0
- package/packages/permissions/src/index.ts +22 -0
- package/packages/permissions/tsconfig.json +8 -0
- package/packages/plugin-sdk/package.json +26 -0
- package/packages/plugin-sdk/src/hooks.ts +44 -0
- package/packages/plugin-sdk/src/index.ts +37 -0
- package/packages/plugin-sdk/src/sdk.test.ts +13 -0
- package/packages/plugin-sdk/tsconfig.json +8 -0
- package/packages/plugin-sdk/vitest.config.ts +5 -0
- package/packages/queue/package.json +16 -0
- package/packages/queue/src/index.test.ts +12 -0
- package/packages/queue/src/index.ts +6 -0
- package/packages/queue/tsconfig.json +5 -0
- package/packages/resource/package.json +17 -0
- package/packages/resource/src/index.js +177 -0
- package/packages/resource/src/index.test.ts +151 -0
- package/packages/resource/src/index.ts +344 -0
- package/packages/resource/tsconfig.json +8 -0
- package/packages/storage/package.json +16 -0
- package/packages/storage/src/index.test.ts +10 -0
- package/packages/storage/src/index.ts +23 -0
- package/packages/storage/tsconfig.json +5 -0
- package/pnpm-workspace.yaml +4 -0
- package/prisma/migrations/20260505151751_baseline_init_all_tables/migration.sql +371 -0
- package/prisma/migrations/migration_lock.toml +3 -0
- package/prisma/schema.prisma +291 -0
- package/prisma/seed.ts +210 -0
- package/scripts/check-static-site.mjs +17 -0
- package/scripts/e2e-smoke.mjs +17 -0
- package/scripts/make-executable.mjs +4 -0
- package/site/.nojekyll +0 -0
- package/site/assets/brand/apple-touch-icon.png +0 -0
- package/site/assets/brand/favicon.svg +1 -0
- package/site/assets/brand/og-image.png +0 -0
- package/site/assets/brand/openadminjs-icon-new.png +0 -0
- package/site/assets/brand/openadminjs-logo-monochrome.png +0 -0
- package/site/assets/brand/openadminjs-logo-new.png +0 -0
- package/site/assets/css/styles.css +1521 -0
- package/site/assets/js/main.js +193 -0
- package/site/assets/partners/arcbyte.svg +11 -0
- package/site/assets/partners/gridstack.svg +8 -0
- package/site/assets/partners/nebula.svg +12 -0
- package/site/assets/partners/orbitlab.svg +7 -0
- package/site/assets/partners/pulseforge.svg +11 -0
- package/site/assets/partners/vertex.svg +6 -0
- package/site/docs.html +1452 -0
- package/site/index.html +357 -0
- package/tsconfig.base.json +23 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { AbilityBuilder, createMongoAbility, type MongoAbility } from "@casl/ability";
|
|
2
|
+
import { Injectable } from "@nestjs/common";
|
|
3
|
+
|
|
4
|
+
type AppAction = "manage" | "create" | "read" | "update" | "delete" | "dispatch";
|
|
5
|
+
type AppAbility = MongoAbility<[AppAction, string]>;
|
|
6
|
+
|
|
7
|
+
type RequestUser = {
|
|
8
|
+
permissions?: string[];
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
@Injectable()
|
|
12
|
+
export class CaslAbilityFactory {
|
|
13
|
+
createForUser(user: RequestUser): AppAbility {
|
|
14
|
+
const { can, build } = new AbilityBuilder<AppAbility>(createMongoAbility);
|
|
15
|
+
|
|
16
|
+
for (const permission of user.permissions ?? []) {
|
|
17
|
+
if (permission === "*") {
|
|
18
|
+
can("manage", "all");
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const dot = permission.lastIndexOf(".");
|
|
23
|
+
if (dot <= 0) continue;
|
|
24
|
+
const subject = permission.slice(0, dot);
|
|
25
|
+
const action = permission.slice(dot + 1);
|
|
26
|
+
if (!subject || !action) continue;
|
|
27
|
+
|
|
28
|
+
can(this.toAction(action), subject);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return build();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private toAction(action: string): AppAction {
|
|
35
|
+
if (action === "create" || action === "read" || action === "update" || action === "delete") {
|
|
36
|
+
return action;
|
|
37
|
+
}
|
|
38
|
+
if (action === "dispatch") return "dispatch";
|
|
39
|
+
return "manage";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SetMetadata } from "@nestjs/common";
|
|
2
|
+
|
|
3
|
+
export const REQUIRE_PERMISSION = "requirePermission";
|
|
4
|
+
export const REQUIRE_ROLE = "requireRole";
|
|
5
|
+
|
|
6
|
+
export const RequirePermission = (permission: string) => SetMetadata(REQUIRE_PERMISSION, permission);
|
|
7
|
+
export const RequireRole = (role: string) => SetMetadata(REQUIRE_ROLE, role);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { CanActivate, ExecutionContext, ForbiddenException, Injectable } from "@nestjs/common";
|
|
2
|
+
import { Reflector } from "@nestjs/core";
|
|
3
|
+
import { REQUIRE_PERMISSION, REQUIRE_ROLE } from "./permission.decorator";
|
|
4
|
+
import { CaslAbilityFactory } from "./casl-ability.factory";
|
|
5
|
+
|
|
6
|
+
@Injectable()
|
|
7
|
+
export class PermissionsGuard implements CanActivate {
|
|
8
|
+
constructor(
|
|
9
|
+
private readonly reflector: Reflector,
|
|
10
|
+
private readonly abilityFactory: CaslAbilityFactory
|
|
11
|
+
) {}
|
|
12
|
+
|
|
13
|
+
canActivate(context: ExecutionContext): boolean {
|
|
14
|
+
const permission = this.reflector.getAllAndOverride<string>(REQUIRE_PERMISSION, [context.getHandler(), context.getClass()]);
|
|
15
|
+
const role = this.reflector.getAllAndOverride<string>(REQUIRE_ROLE, [context.getHandler(), context.getClass()]);
|
|
16
|
+
const request = context.switchToHttp().getRequest();
|
|
17
|
+
const user = request.user;
|
|
18
|
+
|
|
19
|
+
if (role && !user?.roles?.includes(role)) throw new ForbiddenException({ message: "Missing role", code: "ROLE_DENIED" });
|
|
20
|
+
if (permission) {
|
|
21
|
+
const [subject, action] = permission.split(".");
|
|
22
|
+
const ability = this.abilityFactory.createForUser(user ?? {});
|
|
23
|
+
const hasRawPermission = user?.permissions?.includes(permission) || user?.permissions?.includes("*");
|
|
24
|
+
const hasCaslPermission = subject && action ? ability.can(action as never, subject) : false;
|
|
25
|
+
if (!hasRawPermission && !hasCaslPermission) {
|
|
26
|
+
throw new ForbiddenException({ message: "Missing permission", code: "PERMISSION_DENIED", details: { permission } });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Injectable, OnModuleDestroy, OnModuleInit } from "@nestjs/common";
|
|
2
|
+
import { PrismaClient } from "@prisma/client";
|
|
3
|
+
|
|
4
|
+
@Injectable()
|
|
5
|
+
export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
|
|
6
|
+
async onModuleInit() {
|
|
7
|
+
await this.$connect();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async onModuleDestroy() {
|
|
11
|
+
await this.$disconnect();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Controller, Get, Inject } from "@nestjs/common";
|
|
2
|
+
import Redis from "ioredis";
|
|
3
|
+
import { PrismaService } from "../common/prisma.service";
|
|
4
|
+
|
|
5
|
+
@Controller("health")
|
|
6
|
+
export class HealthController {
|
|
7
|
+
constructor(@Inject(PrismaService) private readonly prisma: PrismaService) {}
|
|
8
|
+
|
|
9
|
+
@Get()
|
|
10
|
+
async health() {
|
|
11
|
+
await this.prisma.$queryRaw`SELECT 1`;
|
|
12
|
+
if (!process.env.REDIS_URL) return { api: "ok", db: "ok", redis: "unavailable", reason: "REDIS_URL is not set" };
|
|
13
|
+
|
|
14
|
+
const redis = new Redis(process.env.REDIS_URL, { lazyConnect: true, maxRetriesPerRequest: 1 });
|
|
15
|
+
try {
|
|
16
|
+
await redis.connect();
|
|
17
|
+
const pong = await redis.ping();
|
|
18
|
+
return { api: "ok", db: "ok", redis: pong === "PONG" ? "ok" : "degraded" };
|
|
19
|
+
} catch {
|
|
20
|
+
return { api: "ok", db: "ok", redis: "error" };
|
|
21
|
+
} finally {
|
|
22
|
+
await redis.quit().catch(() => undefined);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { Injectable, Logger } from "@nestjs/common";
|
|
2
|
+
import { ConfigService } from "@nestjs/config";
|
|
3
|
+
import {
|
|
4
|
+
createMailDriver,
|
|
5
|
+
type MailDriver,
|
|
6
|
+
type MailMessage,
|
|
7
|
+
type SentInfo
|
|
8
|
+
} from "@openadminjs/mail";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* NestJS wrapper around @openadminjs/mail.
|
|
12
|
+
*
|
|
13
|
+
* Configure via env:
|
|
14
|
+
* SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASS, SMTP_FROM, APP_NAME
|
|
15
|
+
* If SMTP_HOST is not set → uses MockMailDriver (logs to console in dev).
|
|
16
|
+
*/
|
|
17
|
+
@Injectable()
|
|
18
|
+
export class MailService {
|
|
19
|
+
private readonly driver: MailDriver;
|
|
20
|
+
private readonly logger = new Logger(MailService.name);
|
|
21
|
+
private readonly appName: string;
|
|
22
|
+
private readonly appUrl: string;
|
|
23
|
+
|
|
24
|
+
constructor(private readonly config: ConfigService) {
|
|
25
|
+
const host = this.config.get<string>("SMTP_HOST");
|
|
26
|
+
this.appName = this.config.get<string>("APP_NAME") ?? "OpenAdminJS";
|
|
27
|
+
this.appUrl = this.config.get<string>("APP_URL") ?? "http://localhost:3000";
|
|
28
|
+
|
|
29
|
+
this.driver = createMailDriver(
|
|
30
|
+
host
|
|
31
|
+
? {
|
|
32
|
+
host,
|
|
33
|
+
port: Number(this.config.get<string>("SMTP_PORT") ?? "587"),
|
|
34
|
+
secure: this.config.get<string>("SMTP_SECURE") === "true",
|
|
35
|
+
auth:
|
|
36
|
+
this.config.get<string>("SMTP_USER")
|
|
37
|
+
? {
|
|
38
|
+
user: this.config.get<string>("SMTP_USER")!,
|
|
39
|
+
pass: this.config.get<string>("SMTP_PASS") ?? ""
|
|
40
|
+
}
|
|
41
|
+
: undefined,
|
|
42
|
+
from: this.config.get<string>("SMTP_FROM"),
|
|
43
|
+
appName: this.appName
|
|
44
|
+
}
|
|
45
|
+
: undefined
|
|
46
|
+
);
|
|
47
|
+
this.logger.log(`Mail driver: ${host ? `smtp(${host})` : "mock"}`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async send(message: MailMessage): Promise<SentInfo> {
|
|
51
|
+
return this.driver.send({
|
|
52
|
+
...message,
|
|
53
|
+
data: { appName: this.appName, appUrl: this.appUrl, ...(message.data ?? {}) }
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async sendWelcome(to: string, name: string) {
|
|
58
|
+
return this.send({
|
|
59
|
+
to,
|
|
60
|
+
subject: `Welcome to ${this.appName}!`,
|
|
61
|
+
template: "welcome",
|
|
62
|
+
data: { name, loginUrl: `${this.appUrl}/login` }
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async sendPasswordReset(to: string, name: string, token: string) {
|
|
67
|
+
return this.send({
|
|
68
|
+
to,
|
|
69
|
+
subject: `Reset your ${this.appName} password`,
|
|
70
|
+
template: "password-reset",
|
|
71
|
+
data: {
|
|
72
|
+
name,
|
|
73
|
+
resetUrl: `${this.appUrl}/reset-password?token=${encodeURIComponent(token)}`,
|
|
74
|
+
expiresIn: "1 hour"
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async sendEmailVerification(to: string, name: string, token: string) {
|
|
80
|
+
return this.send({
|
|
81
|
+
to,
|
|
82
|
+
subject: `Verify your email address`,
|
|
83
|
+
template: "email-verification",
|
|
84
|
+
data: {
|
|
85
|
+
name,
|
|
86
|
+
verifyUrl: `${this.appUrl}/verify-email?token=${encodeURIComponent(token)}`,
|
|
87
|
+
expiresIn: "24 hours"
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async sendOrderConfirmation(to: string, customerName: string, orderId: string, total: number, currency: string) {
|
|
93
|
+
return this.send({
|
|
94
|
+
to,
|
|
95
|
+
subject: `Order confirmation #${orderId}`,
|
|
96
|
+
template: "order-confirmation",
|
|
97
|
+
data: {
|
|
98
|
+
customerName,
|
|
99
|
+
orderId,
|
|
100
|
+
currency,
|
|
101
|
+
totalDisplay: (total / 100).toFixed(2),
|
|
102
|
+
orderUrl: `${this.appUrl}/orders/${orderId}`
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async sendRefundNotification(to: string, customerName: string, orderId: string, total: number, currency: string) {
|
|
108
|
+
return this.send({
|
|
109
|
+
to,
|
|
110
|
+
subject: `Refund processed for order #${orderId}`,
|
|
111
|
+
template: "order-refunded",
|
|
112
|
+
data: { customerName, orderId, currency, totalDisplay: (total / 100).toFixed(2) }
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import helmet from "helmet";
|
|
3
|
+
import { NestFactory } from "@nestjs/core";
|
|
4
|
+
import { ValidationPipe } from "@nestjs/common";
|
|
5
|
+
import { SwaggerModule, DocumentBuilder } from "@nestjs/swagger";
|
|
6
|
+
import { AppModule } from "./app.module";
|
|
7
|
+
|
|
8
|
+
async function bootstrap() {
|
|
9
|
+
const app = await NestFactory.create(AppModule);
|
|
10
|
+
app.use(helmet());
|
|
11
|
+
const prodOrigins = (process.env.ADMIN_ORIGIN ?? "")
|
|
12
|
+
.split(",")
|
|
13
|
+
.map((s) => s.trim())
|
|
14
|
+
.filter(Boolean);
|
|
15
|
+
app.enableCors({
|
|
16
|
+
origin:
|
|
17
|
+
process.env.NODE_ENV === "production"
|
|
18
|
+
? prodOrigins.length
|
|
19
|
+
? prodOrigins
|
|
20
|
+
: false
|
|
21
|
+
: true,
|
|
22
|
+
credentials: true
|
|
23
|
+
});
|
|
24
|
+
app.useGlobalPipes(new ValidationPipe({ whitelist: true, forbidNonWhitelisted: true, transform: true }));
|
|
25
|
+
|
|
26
|
+
const config = new DocumentBuilder()
|
|
27
|
+
.setTitle("OpenAdminJS API")
|
|
28
|
+
.setDescription("Generic admin API")
|
|
29
|
+
.setVersion("0.1.0")
|
|
30
|
+
.addBearerAuth()
|
|
31
|
+
.build();
|
|
32
|
+
SwaggerModule.setup("api/docs", app, SwaggerModule.createDocument(app, config));
|
|
33
|
+
|
|
34
|
+
await app.listen(Number(process.env.API_PORT ?? 4000));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
bootstrap();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { OpenAdminPlugin } from "@openadminjs/plugin-sdk";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Demo bundled plugin: stacks `afterCreate` on `posts` after core hooks.
|
|
5
|
+
* Enable in `plugins.manifest.json` with `{ "id": "io.openadminjs.hello", "bundled": "hello", "enabled": true }`.
|
|
6
|
+
*/
|
|
7
|
+
export const helloBundledPlugin: OpenAdminPlugin = {
|
|
8
|
+
id: "io.openadminjs.hello",
|
|
9
|
+
version: "0.1.0",
|
|
10
|
+
displayName: "Hello (bundled demo)",
|
|
11
|
+
register({ registerResourceHooks, config }) {
|
|
12
|
+
const tag = typeof config.tag === "string" ? config.tag : "hello-plugin";
|
|
13
|
+
registerResourceHooks("posts", {
|
|
14
|
+
afterCreate() {
|
|
15
|
+
void tag;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { OpenAdminPlugin } from "@openadminjs/plugin-sdk";
|
|
2
|
+
import { helloBundledPlugin } from "./hello.plugin";
|
|
3
|
+
|
|
4
|
+
/** First-party plugins shipped inside the API package (no separate npm install). */
|
|
5
|
+
export const bundledOpenAdminPlugins: Record<string, OpenAdminPlugin> = {
|
|
6
|
+
hello: helloBundledPlugin
|
|
7
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
/** Same resolution order as plugin-loader (env → cwd → beside apps/api). */
|
|
6
|
+
export function getManifestCandidateStrings(): string[] {
|
|
7
|
+
const fromEnv = process.env.OPENADMIN_PLUGINS_MANIFEST;
|
|
8
|
+
const fromCwd = join(process.cwd(), "plugins.manifest.json");
|
|
9
|
+
const apiPkgDir = fileURLToPath(new URL("../..", import.meta.url));
|
|
10
|
+
const besideApi = join(apiPkgDir, "plugins.manifest.json");
|
|
11
|
+
return [...new Set([fromEnv, fromCwd, besideApi].filter(Boolean) as string[])];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function toAbsoluteManifestPath(candidate: string): string {
|
|
15
|
+
return isAbsolute(candidate) ? candidate : resolve(process.cwd(), candidate);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** First existing manifest file, if any. */
|
|
19
|
+
export function resolveExistingManifestPath(): string | undefined {
|
|
20
|
+
for (const candidate of getManifestCandidateStrings()) {
|
|
21
|
+
const abs = toAbsoluteManifestPath(candidate);
|
|
22
|
+
if (existsSync(abs)) return abs;
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Path to write when no file exists yet (beside apps/api). */
|
|
28
|
+
export function defaultWritableManifestPath(): string {
|
|
29
|
+
const apiPkgDir = fileURLToPath(new URL("../..", import.meta.url));
|
|
30
|
+
return join(apiPkgDir, "plugins.manifest.json");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function resolveWritableManifestPath(): string {
|
|
34
|
+
return resolveExistingManifestPath() ?? defaultWritableManifestPath();
|
|
35
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { pluginManifestSchema } from "./manifest.schema";
|
|
3
|
+
|
|
4
|
+
describe("pluginManifestSchema", () => {
|
|
5
|
+
it("accepts bundled-only entry", () => {
|
|
6
|
+
const r = pluginManifestSchema.safeParse({
|
|
7
|
+
version: 1,
|
|
8
|
+
plugins: [{ id: "a.b", bundled: "hello", enabled: true, config: { x: 1 } }]
|
|
9
|
+
});
|
|
10
|
+
expect(r.success).toBe(true);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("rejects both bundled and package", () => {
|
|
14
|
+
const r = pluginManifestSchema.safeParse({
|
|
15
|
+
version: 1,
|
|
16
|
+
plugins: [{ id: "x", bundled: "hello", package: "@x/y" }]
|
|
17
|
+
});
|
|
18
|
+
expect(r.success).toBe(false);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("rejects neither bundled nor package", () => {
|
|
22
|
+
const r = pluginManifestSchema.safeParse({
|
|
23
|
+
version: 1,
|
|
24
|
+
plugins: [{ id: "x" }]
|
|
25
|
+
});
|
|
26
|
+
expect(r.success).toBe(false);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
export const pluginManifestEntrySchema = z
|
|
4
|
+
.object({
|
|
5
|
+
id: z.string().min(1),
|
|
6
|
+
enabled: z.boolean().optional().default(true),
|
|
7
|
+
bundled: z
|
|
8
|
+
.string()
|
|
9
|
+
.regex(/^[a-z0-9-]+$/, "bundled id must be lowercase slug")
|
|
10
|
+
.optional(),
|
|
11
|
+
package: z
|
|
12
|
+
.string()
|
|
13
|
+
.min(1)
|
|
14
|
+
.regex(/^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/i, "invalid npm package name")
|
|
15
|
+
.optional(),
|
|
16
|
+
config: z.record(z.string(), z.unknown()).optional().default({}),
|
|
17
|
+
marketplace: z
|
|
18
|
+
.object({
|
|
19
|
+
listingUrl: z.string().optional(),
|
|
20
|
+
productId: z.string().optional(),
|
|
21
|
+
licenseKey: z.string().optional()
|
|
22
|
+
})
|
|
23
|
+
.optional()
|
|
24
|
+
})
|
|
25
|
+
.strict()
|
|
26
|
+
.refine((e) => Number(Boolean(e.bundled)) + Number(Boolean(e.package)) === 1, {
|
|
27
|
+
message: "Each plugin must set exactly one of: bundled, package"
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export const pluginManifestSchema = z
|
|
31
|
+
.object({
|
|
32
|
+
version: z.literal(1),
|
|
33
|
+
plugins: z.array(pluginManifestEntrySchema)
|
|
34
|
+
})
|
|
35
|
+
.strict();
|
|
36
|
+
|
|
37
|
+
export type PluginManifest = z.infer<typeof pluginManifestSchema>;
|
|
38
|
+
export type PluginManifestEntry = z.infer<typeof pluginManifestEntrySchema>;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import type { OpenAdminPlugin, OpenAdminPluginModule, PluginRegistrationContext } from "@openadminjs/plugin-sdk";
|
|
4
|
+
import { Logger } from "@nestjs/common";
|
|
5
|
+
import { registerResourceHooks, unregisterResourceHooksBySource } from "../resources/resource-hooks.registry";
|
|
6
|
+
import { bundledOpenAdminPlugins } from "./bundled/registry";
|
|
7
|
+
import { getManifestCandidateStrings, toAbsoluteManifestPath } from "./manifest-path";
|
|
8
|
+
import { pluginManifestSchema, type PluginManifestEntry } from "./manifest.schema";
|
|
9
|
+
|
|
10
|
+
const log = new Logger("OpenAdminPlugins");
|
|
11
|
+
|
|
12
|
+
const require = createRequire(import.meta.url);
|
|
13
|
+
|
|
14
|
+
function readManifest(): unknown | undefined {
|
|
15
|
+
for (const candidate of getManifestCandidateStrings()) {
|
|
16
|
+
const path = toAbsoluteManifestPath(candidate);
|
|
17
|
+
if (existsSync(path)) {
|
|
18
|
+
log.log(`Loading plugin manifest: ${path}`);
|
|
19
|
+
return JSON.parse(readFileSync(path, "utf8")) as unknown;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Clears the main module entry so the next `require` re-reads from disk (e.g. after `pnpm add`). */
|
|
26
|
+
export function invalidateNpmPluginMainModule(packageSpec: string): void {
|
|
27
|
+
try {
|
|
28
|
+
const resolved = require.resolve(packageSpec);
|
|
29
|
+
delete require.cache[resolved];
|
|
30
|
+
} catch {
|
|
31
|
+
/* not resolved yet — fine */
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function resolveNpmPlugin(entry: PluginManifestEntry): OpenAdminPlugin {
|
|
36
|
+
const spec = entry.package!;
|
|
37
|
+
if (process.env.NODE_ENV === "production" && (spec.includes("..") || spec.startsWith(".") || spec.startsWith("/"))) {
|
|
38
|
+
throw new Error(`Refusing to load plugin package path in production: ${entry.id}`);
|
|
39
|
+
}
|
|
40
|
+
const mod = require(spec) as OpenAdminPluginModule;
|
|
41
|
+
const plugin = mod.openAdminPlugin ?? mod.default;
|
|
42
|
+
if (!plugin) {
|
|
43
|
+
throw new Error(`Package "${spec}" has no openAdminPlugin or default export (${entry.id})`);
|
|
44
|
+
}
|
|
45
|
+
if (plugin.id !== entry.id) {
|
|
46
|
+
log.warn(`Plugin manifest id "${entry.id}" differs from plugin.id "${plugin.id}" — manifest id is used as source label`);
|
|
47
|
+
}
|
|
48
|
+
return plugin;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function resolveBundledPlugin(entry: PluginManifestEntry): OpenAdminPlugin {
|
|
52
|
+
const key = entry.bundled!;
|
|
53
|
+
const plugin = bundledOpenAdminPlugins[key];
|
|
54
|
+
if (!plugin) {
|
|
55
|
+
throw new Error(`Unknown bundled plugin "${key}" for ${entry.id}. Known: ${Object.keys(bundledOpenAdminPlugins).join(", ")}`);
|
|
56
|
+
}
|
|
57
|
+
return plugin;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function createContext(entry: PluginManifestEntry): PluginRegistrationContext {
|
|
61
|
+
const config = (entry.config ?? {}) as Record<string, unknown>;
|
|
62
|
+
return {
|
|
63
|
+
pluginId: entry.id,
|
|
64
|
+
config,
|
|
65
|
+
registerResourceHooks: (resourceName, hooks, options) =>
|
|
66
|
+
registerResourceHooks(resourceName, hooks, { ...options, source: entry.id })
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Register hooks for one manifest entry (same as bootstrap). Throws on failure. */
|
|
71
|
+
export function applyManifestPluginEntry(entry: PluginManifestEntry): void {
|
|
72
|
+
if (entry.enabled === false) return;
|
|
73
|
+
const plugin: OpenAdminPlugin = entry.bundled ? resolveBundledPlugin(entry) : resolveNpmPlugin(entry);
|
|
74
|
+
const ctx = createContext(entry);
|
|
75
|
+
const result = plugin.register(ctx as PluginRegistrationContext);
|
|
76
|
+
if (result && typeof (result as Promise<void>).then === "function") {
|
|
77
|
+
throw new Error(`Plugin ${entry.id} must use synchronous register() at bootstrap`);
|
|
78
|
+
}
|
|
79
|
+
log.log(`Loaded plugin ${entry.id} (${entry.bundled ? `bundled:${entry.bundled}` : `package:${entry.package}`})`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Drop all hook registrations attributed to this plugin id (before re-apply or disable). */
|
|
83
|
+
export function removeManifestPluginHooks(pluginId: string): void {
|
|
84
|
+
unregisterResourceHooksBySource(pluginId);
|
|
85
|
+
log.log(`Removed runtime hooks for plugin ${pluginId}`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function loadPluginsFromManifestSync(): void {
|
|
89
|
+
const raw = readManifest();
|
|
90
|
+
if (!raw) {
|
|
91
|
+
log.log("No plugins.manifest.json found — skipping plugins");
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const parsed = pluginManifestSchema.safeParse(raw);
|
|
95
|
+
if (!parsed.success) {
|
|
96
|
+
log.error(`Invalid plugins.manifest.json: ${parsed.error.message}`);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const manifest = parsed.data;
|
|
100
|
+
for (const entry of manifest.plugins) {
|
|
101
|
+
if (entry.enabled === false) continue;
|
|
102
|
+
try {
|
|
103
|
+
applyManifestPluginEntry(entry);
|
|
104
|
+
} catch (e) {
|
|
105
|
+
log.error(`Failed to load plugin ${entry.id}: ${(e as Error).message}`);
|
|
106
|
+
if (process.env.NODE_ENV === "production") throw e;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Controller, Get, Post, UseGuards } from "@nestjs/common";
|
|
2
|
+
import { AuthGuard } from "../common/auth.guard";
|
|
3
|
+
import { RequireAuthRealm } from "../common/auth-realm.decorator";
|
|
4
|
+
import { PermissionsGuard } from "../common/permissions.guard";
|
|
5
|
+
import { RequirePermission } from "../common/permission.decorator";
|
|
6
|
+
import { CurrentUser } from "../common/current-user.decorator";
|
|
7
|
+
import { QueueService } from "./queue.service";
|
|
8
|
+
|
|
9
|
+
type UserContext = { id: string };
|
|
10
|
+
|
|
11
|
+
@Controller("jobs")
|
|
12
|
+
@UseGuards(AuthGuard, PermissionsGuard)
|
|
13
|
+
@RequireAuthRealm("admin")
|
|
14
|
+
export class QueueController {
|
|
15
|
+
constructor(private readonly queue: QueueService) {}
|
|
16
|
+
|
|
17
|
+
@Get("stats")
|
|
18
|
+
@RequirePermission("jobs.read")
|
|
19
|
+
stats() {
|
|
20
|
+
return this.queue.getStats();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@Post("dispatch")
|
|
24
|
+
@RequirePermission("jobs.dispatch")
|
|
25
|
+
dispatch(@CurrentUser() user: UserContext) {
|
|
26
|
+
return this.queue.dispatch(user.id);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Module } from "@nestjs/common";
|
|
2
|
+
import { JwtModule } from "@nestjs/jwt";
|
|
3
|
+
import { BullModule } from "@nestjs/bullmq";
|
|
4
|
+
import { PrismaService } from "../common/prisma.service";
|
|
5
|
+
import { AuthGuard } from "../common/auth.guard";
|
|
6
|
+
import { PermissionsGuard } from "../common/permissions.guard";
|
|
7
|
+
import { CaslAbilityFactory } from "../common/casl-ability.factory";
|
|
8
|
+
import { QueueController } from "./queue.controller";
|
|
9
|
+
import { QueueService } from "./queue.service";
|
|
10
|
+
import { QueueProcessor } from "./queue.processor";
|
|
11
|
+
|
|
12
|
+
@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
|
+
],
|
|
20
|
+
controllers: [QueueController],
|
|
21
|
+
providers: [QueueService, QueueProcessor, PrismaService, AuthGuard, PermissionsGuard, CaslAbilityFactory]
|
|
22
|
+
})
|
|
23
|
+
export class QueueModule {}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Processor, WorkerHost } from "@nestjs/bullmq";
|
|
2
|
+
import { Logger } from "@nestjs/common";
|
|
3
|
+
import type { Job } from "bullmq";
|
|
4
|
+
import { PrismaService } from "../common/prisma.service";
|
|
5
|
+
|
|
6
|
+
@Processor("default")
|
|
7
|
+
export class QueueProcessor extends WorkerHost {
|
|
8
|
+
private readonly logger = new Logger(QueueProcessor.name);
|
|
9
|
+
|
|
10
|
+
constructor(private readonly prisma: PrismaService) {
|
|
11
|
+
super();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async process(job: Job<{ initiatedBy?: string; at?: string }>) {
|
|
15
|
+
await this.prisma.jobLog.create({
|
|
16
|
+
data: {
|
|
17
|
+
name: job.name,
|
|
18
|
+
status: "processing",
|
|
19
|
+
payload: { queueJobId: job.id, ...job.data }
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
25
|
+
await this.prisma.jobLog.create({
|
|
26
|
+
data: {
|
|
27
|
+
name: job.name,
|
|
28
|
+
status: "completed",
|
|
29
|
+
payload: { queueJobId: job.id, ...job.data }
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return { ok: true };
|
|
33
|
+
} catch (error) {
|
|
34
|
+
const message = error instanceof Error ? error.message : "Unknown queue error";
|
|
35
|
+
await this.prisma.jobLog.create({
|
|
36
|
+
data: {
|
|
37
|
+
name: job.name,
|
|
38
|
+
status: "failed",
|
|
39
|
+
error: message,
|
|
40
|
+
payload: { queueJobId: job.id, ...job.data }
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
this.logger.error(`Job ${job.id} failed`, error instanceof Error ? error.stack : undefined);
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|