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,50 @@
|
|
|
1
|
+
import { Injectable, ServiceUnavailableException } from "@nestjs/common";
|
|
2
|
+
import { InjectQueue } from "@nestjs/bullmq";
|
|
3
|
+
import { Queue } from "bullmq";
|
|
4
|
+
import { PrismaService } from "../common/prisma.service";
|
|
5
|
+
|
|
6
|
+
@Injectable()
|
|
7
|
+
export class QueueService {
|
|
8
|
+
constructor(
|
|
9
|
+
@InjectQueue("default") private readonly queue: Queue,
|
|
10
|
+
private readonly prisma: PrismaService
|
|
11
|
+
) {}
|
|
12
|
+
|
|
13
|
+
async getStats() {
|
|
14
|
+
const [counts, recent] = await Promise.all([
|
|
15
|
+
this.queue.getJobCounts("active", "waiting", "completed", "failed", "delayed"),
|
|
16
|
+
this.prisma.jobLog.findMany({ orderBy: { createdAt: "desc" }, take: 10 })
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
return { counts, recent };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async dispatch(userId: string) {
|
|
23
|
+
this.ensureRedisConfigured();
|
|
24
|
+
const payload = { initiatedBy: userId, at: new Date().toISOString() };
|
|
25
|
+
const job = await this.queue.add("maintenance.sync", payload, {
|
|
26
|
+
removeOnComplete: 100,
|
|
27
|
+
attempts: 3,
|
|
28
|
+
backoff: { type: "exponential", delay: 1000 }
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
await this.prisma.jobLog.create({
|
|
32
|
+
data: {
|
|
33
|
+
name: "maintenance.sync",
|
|
34
|
+
status: "queued",
|
|
35
|
+
payload: { ...payload, queueJobId: job.id }
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return { id: job.id, name: job.name };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private ensureRedisConfigured() {
|
|
43
|
+
if (!process.env.REDIS_URL) {
|
|
44
|
+
throw new ServiceUnavailableException({
|
|
45
|
+
message: "Redis is not configured. Set REDIS_URL to enable queues.",
|
|
46
|
+
code: "REDIS_NOT_CONFIGURED"
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineResource } from "@openadminjs/core";
|
|
2
|
+
|
|
3
|
+
export default defineResource({
|
|
4
|
+
name: "categories",
|
|
5
|
+
label: "Categories",
|
|
6
|
+
model: "category",
|
|
7
|
+
titleField: "name",
|
|
8
|
+
icon: "Folder",
|
|
9
|
+
permissions: {
|
|
10
|
+
read: "categories.read",
|
|
11
|
+
create: "categories.create",
|
|
12
|
+
update: "categories.update",
|
|
13
|
+
delete: "categories.delete"
|
|
14
|
+
},
|
|
15
|
+
fields: {
|
|
16
|
+
id: { type: "id", label: "ID", create: false, edit: false, list: false },
|
|
17
|
+
name: { type: "text", label: "Name", required: true, searchable: true, sortable: true },
|
|
18
|
+
slug: { type: "slug", label: "Slug", from: "name", searchable: true },
|
|
19
|
+
createdAt: { type: "datetime", label: "Created at", create: false, edit: false, sortable: true }
|
|
20
|
+
}
|
|
21
|
+
});
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import type { PrismaClient } from "@prisma/client";
|
|
2
|
+
import { defineResource } from "@openadminjs/core";
|
|
3
|
+
|
|
4
|
+
export const productsResource = defineResource({
|
|
5
|
+
name: "products",
|
|
6
|
+
label: { en: "Products", ru: "Товары" },
|
|
7
|
+
model: "product",
|
|
8
|
+
titleField: "name",
|
|
9
|
+
icon: "ShoppingBag",
|
|
10
|
+
i18n: { defaultLocale: "en", locales: ["en", "ru"] },
|
|
11
|
+
permissions: {
|
|
12
|
+
read: "products.read",
|
|
13
|
+
create: "products.create",
|
|
14
|
+
update: "products.update",
|
|
15
|
+
delete: "products.delete"
|
|
16
|
+
},
|
|
17
|
+
fields: {
|
|
18
|
+
id: { type: "id", label: "ID", create: false, edit: false, list: false },
|
|
19
|
+
name: { type: "text", label: { en: "Name", ru: "Название" }, required: true, searchable: true, maxLength: 200 },
|
|
20
|
+
slug: { type: "slug", label: "Slug", required: true, maxLength: 200 },
|
|
21
|
+
description: { type: "textarea", label: { en: "Description", ru: "Описание" }, list: false },
|
|
22
|
+
price: {
|
|
23
|
+
type: "number",
|
|
24
|
+
label: { en: "Price (cents)", ru: "Цена (копейки)" },
|
|
25
|
+
required: true,
|
|
26
|
+
min: 0,
|
|
27
|
+
filterable: true,
|
|
28
|
+
sortable: true
|
|
29
|
+
},
|
|
30
|
+
currency: {
|
|
31
|
+
type: "select",
|
|
32
|
+
label: "Currency",
|
|
33
|
+
options: ["USD", "EUR", "GBP", "RUB", "UAH"],
|
|
34
|
+
required: true
|
|
35
|
+
},
|
|
36
|
+
active: { type: "boolean", label: { en: "Active", ru: "Активен" }, filterable: true, sortable: true },
|
|
37
|
+
imageUrl: { type: "url", label: { en: "Image URL", ru: "URL изображения" }, list: false },
|
|
38
|
+
metadata: { type: "json", label: "Metadata", list: false },
|
|
39
|
+
createdAt: { type: "datetime", label: { en: "Created", ru: "Создан" }, create: false, edit: false, sortable: true }
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export const ordersResource = defineResource({
|
|
44
|
+
name: "orders",
|
|
45
|
+
label: { en: "Orders", ru: "Заказы" },
|
|
46
|
+
model: "order",
|
|
47
|
+
titleField: "id",
|
|
48
|
+
icon: "Receipt",
|
|
49
|
+
i18n: { defaultLocale: "en", locales: ["en", "ru"] },
|
|
50
|
+
permissions: {
|
|
51
|
+
read: "orders.read",
|
|
52
|
+
update: "orders.update",
|
|
53
|
+
refund: "orders.refund"
|
|
54
|
+
},
|
|
55
|
+
fields: {
|
|
56
|
+
id: { type: "id", label: "ID", create: false, edit: false },
|
|
57
|
+
email: { type: "email", label: { en: "Email", ru: "Email" }, searchable: true, edit: false },
|
|
58
|
+
status: {
|
|
59
|
+
type: "badge",
|
|
60
|
+
label: { en: "Status", ru: "Статус" },
|
|
61
|
+
options: ["pending", "paid", "failed", "refunded", "cancelled"],
|
|
62
|
+
filterable: true,
|
|
63
|
+
sortable: true
|
|
64
|
+
},
|
|
65
|
+
total: { type: "number", label: { en: "Total (cents)", ru: "Итог (копейки)" }, edit: false, sortable: true, filterable: true },
|
|
66
|
+
currency: { type: "text", label: "Currency", edit: false },
|
|
67
|
+
notes: { type: "textarea", label: { en: "Notes", ru: "Заметки" }, list: false },
|
|
68
|
+
createdAt: { type: "datetime", label: { en: "Created", ru: "Создан" }, create: false, edit: false, sortable: true }
|
|
69
|
+
},
|
|
70
|
+
actions: {
|
|
71
|
+
refund: {
|
|
72
|
+
label: { en: "Refund", ru: "Возврат" },
|
|
73
|
+
variant: "destructive",
|
|
74
|
+
confirm: true,
|
|
75
|
+
permission: "orders.refund",
|
|
76
|
+
async handler(ctx) {
|
|
77
|
+
const db = ctx.prisma as PrismaClient;
|
|
78
|
+
const order = await db.order.findUnique({
|
|
79
|
+
where: { id: ctx.id },
|
|
80
|
+
include: { transactions: true }
|
|
81
|
+
});
|
|
82
|
+
if (!order || order.status !== "paid") {
|
|
83
|
+
throw new Error("Order is not paid or not found");
|
|
84
|
+
}
|
|
85
|
+
return db.order.update({ where: { id: ctx.id }, data: { status: "refunded" } });
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
cancel: {
|
|
89
|
+
label: { en: "Cancel", ru: "Отменить" },
|
|
90
|
+
variant: "destructive",
|
|
91
|
+
confirm: true,
|
|
92
|
+
permission: "orders.update",
|
|
93
|
+
async handler(ctx) {
|
|
94
|
+
const db = ctx.prisma as PrismaClient;
|
|
95
|
+
return db.order.update({
|
|
96
|
+
where: { id: ctx.id },
|
|
97
|
+
data: { status: "cancelled" }
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
export const transactionsResource = defineResource({
|
|
105
|
+
name: "transactions",
|
|
106
|
+
label: { en: "Transactions", ru: "Транзакции" },
|
|
107
|
+
model: "transaction",
|
|
108
|
+
titleField: "id",
|
|
109
|
+
icon: "CreditCard",
|
|
110
|
+
i18n: { defaultLocale: "en", locales: ["en", "ru"] },
|
|
111
|
+
permissions: {
|
|
112
|
+
read: "transactions.read"
|
|
113
|
+
},
|
|
114
|
+
fields: {
|
|
115
|
+
id: { type: "id", label: "ID", create: false, edit: false },
|
|
116
|
+
provider: { type: "badge", label: { en: "Provider", ru: "Провайдер" }, create: false, edit: false, filterable: true },
|
|
117
|
+
providerTxId: { type: "text", label: { en: "Provider TX ID", ru: "ID транзакции" }, create: false, edit: false },
|
|
118
|
+
status: {
|
|
119
|
+
type: "badge",
|
|
120
|
+
label: { en: "Status", ru: "Статус" },
|
|
121
|
+
options: ["pending", "succeeded", "failed", "refunded"],
|
|
122
|
+
create: false,
|
|
123
|
+
edit: false,
|
|
124
|
+
filterable: true,
|
|
125
|
+
sortable: true
|
|
126
|
+
},
|
|
127
|
+
amount: { type: "number", label: { en: "Amount (cents)", ru: "Сумма (копейки)" }, create: false, edit: false, sortable: true },
|
|
128
|
+
currency: { type: "text", label: "Currency", create: false, edit: false },
|
|
129
|
+
createdAt: { type: "datetime", label: { en: "Created", ru: "Создан" }, create: false, edit: false, sortable: true }
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
export const webhookLogsResource = defineResource({
|
|
134
|
+
name: "webhook-logs",
|
|
135
|
+
label: { en: "Webhook Logs", ru: "Вебхук Логи" },
|
|
136
|
+
model: "webhookLog",
|
|
137
|
+
titleField: "eventType",
|
|
138
|
+
icon: "Webhook",
|
|
139
|
+
permissions: {
|
|
140
|
+
read: "webhook-logs.read"
|
|
141
|
+
},
|
|
142
|
+
fields: {
|
|
143
|
+
id: { type: "id", label: "ID", create: false, edit: false, list: false },
|
|
144
|
+
provider: { type: "badge", label: "Provider", create: false, edit: false, filterable: true },
|
|
145
|
+
eventType: { type: "text", label: { en: "Event Type", ru: "Тип события" }, create: false, edit: false, searchable: true },
|
|
146
|
+
status: {
|
|
147
|
+
type: "badge",
|
|
148
|
+
label: "Status",
|
|
149
|
+
options: ["pending", "processed", "failed"],
|
|
150
|
+
create: false,
|
|
151
|
+
edit: false,
|
|
152
|
+
filterable: true
|
|
153
|
+
},
|
|
154
|
+
error: { type: "textarea", label: "Error", create: false, edit: false, list: false },
|
|
155
|
+
createdAt: { type: "datetime", label: { en: "Received", ru: "Получен" }, create: false, edit: false, sortable: true }
|
|
156
|
+
}
|
|
157
|
+
});
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { PrismaClient } from "@prisma/client";
|
|
2
|
+
import { defineResource } from "@openadminjs/core";
|
|
3
|
+
|
|
4
|
+
export const apiTokensResource = defineResource({
|
|
5
|
+
name: "api-tokens",
|
|
6
|
+
label: { en: "API tokens", ru: "API-токены" },
|
|
7
|
+
model: "apiToken",
|
|
8
|
+
titleField: "name",
|
|
9
|
+
icon: "KeyRound",
|
|
10
|
+
i18n: { defaultLocale: "en", locales: ["en", "ru"] },
|
|
11
|
+
permissions: {
|
|
12
|
+
read: "api-tokens.read",
|
|
13
|
+
create: "api-tokens.create",
|
|
14
|
+
delete: "api-tokens.delete",
|
|
15
|
+
revoke: "api-tokens.revoke"
|
|
16
|
+
},
|
|
17
|
+
fields: {
|
|
18
|
+
id: { type: "id", label: "ID", create: false, edit: false, list: false },
|
|
19
|
+
name: { type: "text", label: { en: "Name", ru: "Имя" }, searchable: true },
|
|
20
|
+
scopes: { type: "json", label: "Scopes", create: true, edit: false },
|
|
21
|
+
tokenHash: { type: "hidden", label: "Token hash" },
|
|
22
|
+
revokedAt: { type: "datetime", label: { en: "Revoked at", ru: "Отозван" }, create: false, edit: false },
|
|
23
|
+
createdAt: { type: "datetime", label: { en: "Created", ru: "Создан" }, create: false, edit: false, sortable: true }
|
|
24
|
+
},
|
|
25
|
+
actions: {
|
|
26
|
+
revoke: {
|
|
27
|
+
label: { en: "Revoke", ru: "Отозвать" },
|
|
28
|
+
variant: "destructive",
|
|
29
|
+
confirm: true,
|
|
30
|
+
permission: "api-tokens.revoke",
|
|
31
|
+
async handler(ctx) {
|
|
32
|
+
const db = ctx.prisma as PrismaClient;
|
|
33
|
+
return db.apiToken.update({
|
|
34
|
+
where: { id: ctx.id },
|
|
35
|
+
data: { revokedAt: new Date() }
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export const notificationsResource = defineResource({
|
|
43
|
+
name: "notifications",
|
|
44
|
+
label: { en: "Notifications", ru: "Уведомления" },
|
|
45
|
+
model: "notification",
|
|
46
|
+
titleField: "title",
|
|
47
|
+
icon: "Bell",
|
|
48
|
+
i18n: { defaultLocale: "en", locales: ["en", "ru"] },
|
|
49
|
+
listScope: {
|
|
50
|
+
type: "userOwns",
|
|
51
|
+
field: "userId",
|
|
52
|
+
bypassPermissions: ["notifications.read.all", "*"]
|
|
53
|
+
},
|
|
54
|
+
permissions: {
|
|
55
|
+
read: "notifications.read",
|
|
56
|
+
create: "notifications.create",
|
|
57
|
+
update: "notifications.update",
|
|
58
|
+
delete: "notifications.delete",
|
|
59
|
+
markRead: "notifications.update"
|
|
60
|
+
},
|
|
61
|
+
fields: {
|
|
62
|
+
id: { type: "id", label: "ID", create: false, edit: false, list: false },
|
|
63
|
+
title: { type: "text", label: { en: "Title", ru: "Заголовок" }, searchable: true },
|
|
64
|
+
body: { type: "textarea", label: { en: "Body", ru: "Текст" }, list: false },
|
|
65
|
+
readAt: { type: "datetime", label: { en: "Read at", ru: "Прочитано" }, create: false, edit: false },
|
|
66
|
+
createdAt: { type: "datetime", label: { en: "Created", ru: "Создано" }, create: false, edit: false, sortable: true }
|
|
67
|
+
},
|
|
68
|
+
actions: {
|
|
69
|
+
"mark-read": {
|
|
70
|
+
label: { en: "Mark read", ru: "Прочитано" },
|
|
71
|
+
variant: "primary",
|
|
72
|
+
permission: "notifications.update",
|
|
73
|
+
async handler(ctx) {
|
|
74
|
+
const db = ctx.prisma as PrismaClient;
|
|
75
|
+
return db.notification.update({
|
|
76
|
+
where: { id: ctx.id },
|
|
77
|
+
data: { readAt: new Date() }
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
"mark-unread": {
|
|
82
|
+
label: { en: "Mark unread", ru: "Не прочитано" },
|
|
83
|
+
variant: "default",
|
|
84
|
+
permission: "notifications.update",
|
|
85
|
+
async handler(ctx) {
|
|
86
|
+
const db = ctx.prisma as PrismaClient;
|
|
87
|
+
return db.notification.update({
|
|
88
|
+
where: { id: ctx.id },
|
|
89
|
+
data: { readAt: null }
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
export const jobLogsResource = defineResource({
|
|
97
|
+
name: "job-logs",
|
|
98
|
+
label: "Job Logs",
|
|
99
|
+
model: "jobLog",
|
|
100
|
+
titleField: "name",
|
|
101
|
+
icon: "Gauge",
|
|
102
|
+
permissions: { read: "jobs.read" },
|
|
103
|
+
fields: {
|
|
104
|
+
id: { type: "id", label: "ID", create: false, edit: false, list: false },
|
|
105
|
+
name: { type: "text", label: "Job", searchable: true },
|
|
106
|
+
status: { type: "badge", label: "Status", filterable: true },
|
|
107
|
+
payload: { type: "json", label: "Payload", list: false },
|
|
108
|
+
error: { type: "textarea", label: "Error", list: false },
|
|
109
|
+
createdAt: { type: "datetime", label: "Created", create: false, edit: false, sortable: true }
|
|
110
|
+
}
|
|
111
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { PrismaClient } from "@prisma/client";
|
|
2
|
+
import { defineResource } from "@openadminjs/core";
|
|
3
|
+
|
|
4
|
+
export default defineResource({
|
|
5
|
+
name: "posts",
|
|
6
|
+
label: { en: "Posts", ru: "Записи" },
|
|
7
|
+
model: "post",
|
|
8
|
+
titleField: "title",
|
|
9
|
+
icon: "FileText",
|
|
10
|
+
i18n: {
|
|
11
|
+
defaultLocale: "en",
|
|
12
|
+
locales: ["en", "ru"]
|
|
13
|
+
},
|
|
14
|
+
seo: {
|
|
15
|
+
public: true,
|
|
16
|
+
slugField: "slug",
|
|
17
|
+
pathPattern: "/posts/:slug",
|
|
18
|
+
titleField: "title",
|
|
19
|
+
descriptionField: "content",
|
|
20
|
+
alternateSlugFields: { ru: "slug" }
|
|
21
|
+
},
|
|
22
|
+
permissions: {
|
|
23
|
+
read: "posts.read",
|
|
24
|
+
create: "posts.create",
|
|
25
|
+
update: "posts.update",
|
|
26
|
+
delete: "posts.delete",
|
|
27
|
+
publish: "posts.publish"
|
|
28
|
+
},
|
|
29
|
+
fields: {
|
|
30
|
+
id: { type: "id", label: { en: "ID", ru: "ID" }, create: false, edit: false, list: false },
|
|
31
|
+
title: {
|
|
32
|
+
type: "text",
|
|
33
|
+
label: { en: "Title", ru: "Заголовок" },
|
|
34
|
+
required: true,
|
|
35
|
+
searchable: true,
|
|
36
|
+
sortable: true
|
|
37
|
+
},
|
|
38
|
+
slug: {
|
|
39
|
+
type: "slug",
|
|
40
|
+
label: { en: "Slug", ru: "Слаг" },
|
|
41
|
+
from: "title",
|
|
42
|
+
searchable: true
|
|
43
|
+
},
|
|
44
|
+
status: {
|
|
45
|
+
type: "select",
|
|
46
|
+
label: { en: "Status", ru: "Статус" },
|
|
47
|
+
options: ["draft", "published", "archived"],
|
|
48
|
+
filterable: true,
|
|
49
|
+
sortable: true
|
|
50
|
+
},
|
|
51
|
+
content: { type: "richtext", label: { en: "Content", ru: "Текст" }, list: false },
|
|
52
|
+
categoryId: {
|
|
53
|
+
type: "relation",
|
|
54
|
+
label: { en: "Category", ru: "Категория" },
|
|
55
|
+
resource: "categories",
|
|
56
|
+
displayField: "name",
|
|
57
|
+
filterable: true
|
|
58
|
+
},
|
|
59
|
+
coverImageId: {
|
|
60
|
+
type: "image",
|
|
61
|
+
label: { en: "Cover image", ru: "Обложка" },
|
|
62
|
+
resource: "files",
|
|
63
|
+
list: false
|
|
64
|
+
},
|
|
65
|
+
createdAt: {
|
|
66
|
+
type: "datetime",
|
|
67
|
+
label: { en: "Created at", ru: "Создано" },
|
|
68
|
+
create: false,
|
|
69
|
+
edit: false,
|
|
70
|
+
sortable: true
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
actions: {
|
|
74
|
+
publish: {
|
|
75
|
+
label: { en: "Publish", ru: "Опубликовать" },
|
|
76
|
+
variant: "primary",
|
|
77
|
+
confirm: true,
|
|
78
|
+
permission: "posts.publish",
|
|
79
|
+
async handler(ctx) {
|
|
80
|
+
const db = ctx.prisma as PrismaClient;
|
|
81
|
+
return db.post.update({
|
|
82
|
+
where: { id: ctx.id },
|
|
83
|
+
data: { status: "published" }
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ResourceConfig } from "@openadminjs/core";
|
|
2
|
+
import posts from "./posts.resource";
|
|
3
|
+
import categories from "./categories.resource";
|
|
4
|
+
import users from "./users.resource";
|
|
5
|
+
import { auditLogsResource, filesResource, settingsResource } from "./system.resource";
|
|
6
|
+
import { apiTokensResource, jobLogsResource, notificationsResource } from "./operations.resource";
|
|
7
|
+
import { ordersResource, productsResource, transactionsResource, webhookLogsResource } from "./commerce.resource";
|
|
8
|
+
|
|
9
|
+
export const resources = [
|
|
10
|
+
posts,
|
|
11
|
+
categories,
|
|
12
|
+
users,
|
|
13
|
+
filesResource,
|
|
14
|
+
auditLogsResource,
|
|
15
|
+
settingsResource,
|
|
16
|
+
apiTokensResource,
|
|
17
|
+
notificationsResource,
|
|
18
|
+
jobLogsResource,
|
|
19
|
+
productsResource,
|
|
20
|
+
ordersResource,
|
|
21
|
+
transactionsResource,
|
|
22
|
+
webhookLogsResource
|
|
23
|
+
] satisfies ResourceConfig[];
|
|
24
|
+
|
|
25
|
+
export function getResource(name: string): ResourceConfig | undefined {
|
|
26
|
+
return resources.find((resource) => resource.name === name);
|
|
27
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { registerResourceHooks } from "./resource-hooks.registry";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Side-effect module: import from `app.module` so hooks are registered at startup.
|
|
5
|
+
* Add `registerResourceHooks` calls here — handlers stay on the server and never ship in JSON metadata.
|
|
6
|
+
*/
|
|
7
|
+
registerResourceHooks(
|
|
8
|
+
"posts",
|
|
9
|
+
{
|
|
10
|
+
beforeCreate({ data }) {
|
|
11
|
+
if (typeof data.title === "string") data.title = data.title.trim();
|
|
12
|
+
},
|
|
13
|
+
beforeUpdate({ data }) {
|
|
14
|
+
if (typeof data.title === "string") data.title = data.title.trim();
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
{ source: "core" }
|
|
18
|
+
);
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { describe, expect, it, beforeEach } from "vitest";
|
|
2
|
+
import { runBeforeCreate } from "./resource-hooks.runner";
|
|
3
|
+
import {
|
|
4
|
+
registerResourceHooks,
|
|
5
|
+
resetResourceHookRegistryForTests,
|
|
6
|
+
unregisterResourceHooksBySource
|
|
7
|
+
} from "./resource-hooks.registry";
|
|
8
|
+
import type { ResourceConfig } from "@openadminjs/core";
|
|
9
|
+
|
|
10
|
+
const stubResource = { name: "x", label: "X", model: "M", permissions: { read: "x.read", create: "x.c" }, fields: {} } as unknown as ResourceConfig;
|
|
11
|
+
|
|
12
|
+
describe("resource hook registry", () => {
|
|
13
|
+
beforeEach(() => resetResourceHookRegistryForTests());
|
|
14
|
+
|
|
15
|
+
it("stacks hooks in registration order", async () => {
|
|
16
|
+
const order: string[] = [];
|
|
17
|
+
registerResourceHooks("posts", {
|
|
18
|
+
beforeCreate() {
|
|
19
|
+
order.push("a");
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
registerResourceHooks("posts", {
|
|
23
|
+
beforeCreate() {
|
|
24
|
+
order.push("b");
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
await runBeforeCreate("posts", stubResource, { id: "1", email: "e", permissions: [] }, {}, {});
|
|
28
|
+
expect(order).toEqual(["a", "b"]);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("replace clears prior hooks for that resource", async () => {
|
|
32
|
+
const order: string[] = [];
|
|
33
|
+
registerResourceHooks("posts", {
|
|
34
|
+
beforeCreate() {
|
|
35
|
+
order.push("first");
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
registerResourceHooks(
|
|
39
|
+
"posts",
|
|
40
|
+
{
|
|
41
|
+
beforeCreate() {
|
|
42
|
+
order.push("only");
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
{ replace: true }
|
|
46
|
+
);
|
|
47
|
+
await runBeforeCreate("posts", stubResource, { id: "1", email: "e", permissions: [] }, {}, {});
|
|
48
|
+
expect(order).toEqual(["only"]);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("unregisterResourceHooksBySource removes only matching source", async () => {
|
|
52
|
+
const order: string[] = [];
|
|
53
|
+
registerResourceHooks(
|
|
54
|
+
"posts",
|
|
55
|
+
{ beforeCreate() { order.push("core"); } },
|
|
56
|
+
{ source: "core" }
|
|
57
|
+
);
|
|
58
|
+
registerResourceHooks(
|
|
59
|
+
"posts",
|
|
60
|
+
{ beforeCreate() { order.push("p1"); } },
|
|
61
|
+
{ source: "plugin-a" }
|
|
62
|
+
);
|
|
63
|
+
registerResourceHooks(
|
|
64
|
+
"posts",
|
|
65
|
+
{ beforeCreate() { order.push("p2"); } },
|
|
66
|
+
{ source: "plugin-b" }
|
|
67
|
+
);
|
|
68
|
+
unregisterResourceHooksBySource("plugin-a");
|
|
69
|
+
await runBeforeCreate("posts", stubResource, { id: "1", email: "e", permissions: [] }, {}, {});
|
|
70
|
+
expect(order).toEqual(["core", "p2"]);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { ResourceLifecycleHooks } from "@openadminjs/plugin-sdk";
|
|
2
|
+
|
|
3
|
+
export type {
|
|
4
|
+
AfterCreateCtx,
|
|
5
|
+
AfterDeleteCtx,
|
|
6
|
+
AfterUpdateCtx,
|
|
7
|
+
BeforeCreateCtx,
|
|
8
|
+
BeforeDeleteCtx,
|
|
9
|
+
BeforeUpdateCtx,
|
|
10
|
+
ResourceHookUser,
|
|
11
|
+
ResourceLifecycleHooks
|
|
12
|
+
} from "@openadminjs/plugin-sdk";
|
|
13
|
+
|
|
14
|
+
type HookEntry = { hooks: ResourceLifecycleHooks; source?: string };
|
|
15
|
+
|
|
16
|
+
const registry = new Map<string, HookEntry[]>();
|
|
17
|
+
|
|
18
|
+
/** Clears all hooks (Vitest only). */
|
|
19
|
+
export function resetResourceHookRegistryForTests(): void {
|
|
20
|
+
registry.clear();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type RegisterResourceHooksOptions = {
|
|
24
|
+
/** Replace the whole chain for this resource (default: append). */
|
|
25
|
+
replace?: boolean;
|
|
26
|
+
/** e.g. plugin id or `core` */
|
|
27
|
+
source?: string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Register server-only hooks (not serialised to the admin client).
|
|
32
|
+
* Multiple callers stack in registration order unless `replace: true`.
|
|
33
|
+
*/
|
|
34
|
+
export function registerResourceHooks(
|
|
35
|
+
resourceName: string,
|
|
36
|
+
hooks: ResourceLifecycleHooks,
|
|
37
|
+
options?: RegisterResourceHooksOptions
|
|
38
|
+
): void {
|
|
39
|
+
const entry: HookEntry = { hooks, source: options?.source };
|
|
40
|
+
if (options?.replace) {
|
|
41
|
+
registry.set(resourceName, [entry]);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const list = registry.get(resourceName) ?? [];
|
|
45
|
+
list.push(entry);
|
|
46
|
+
registry.set(resourceName, list);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function getResourceHookChain(resourceName: string): readonly HookEntry[] {
|
|
50
|
+
return registry.get(resourceName) ?? [];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Remove all hook entries registered with this source (e.g. plugin manifest id).
|
|
55
|
+
* Core hooks use source `"core"` — never pass that for plugin toggles.
|
|
56
|
+
*/
|
|
57
|
+
export function unregisterResourceHooksBySource(source: string): void {
|
|
58
|
+
const names = [...registry.keys()];
|
|
59
|
+
for (const resourceName of names) {
|
|
60
|
+
const list = registry.get(resourceName);
|
|
61
|
+
if (!list?.length) continue;
|
|
62
|
+
const next = list.filter((e) => e.source !== source);
|
|
63
|
+
if (next.length === 0) registry.delete(resourceName);
|
|
64
|
+
else if (next.length !== list.length) registry.set(resourceName, next);
|
|
65
|
+
}
|
|
66
|
+
}
|