openadminjs 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -113
- package/dist/create-project.d.ts +34 -0
- package/dist/create-project.js +229 -0
- package/dist/create-project.test.d.ts +1 -0
- package/dist/create-project.test.js +46 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +138 -0
- package/dist/index.test.d.ts +1 -0
- package/dist/index.test.js +7 -0
- package/dist/resource-slug.d.ts +2 -0
- package/dist/resource-slug.js +4 -0
- package/dist/resource-slug.test.d.ts +1 -0
- package/dist/resource-slug.test.js +9 -0
- package/package.json +36 -24
- package/{packages/cli/template → template}/.env.example +2 -2
- package/.env.example +0 -9
- package/.github/FUNDING.yml +0 -3
- package/.github/ISSUE_TEMPLATE/bug_report.yml +0 -10
- package/.github/ISSUE_TEMPLATE/feature_request.yml +0 -10
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -9
- package/.github/dependabot.yml +0 -10
- package/.github/workflows/ci.yml +0 -26
- package/CHANGELOG.md +0 -5
- package/CODE_OF_CONDUCT.md +0 -3
- package/CONTRIBUTING.md +0 -11
- package/LICENSE +0 -21
- package/ROADMAP.md +0 -7
- package/SECURITY.md +0 -11
- package/apps/admin/app/api/auth/login/route.ts +0 -51
- package/apps/admin/app/api/auth/logout/route.ts +0 -11
- package/apps/admin/app/api/auth/refresh/route.ts +0 -46
- package/apps/admin/app/api-tokens/page.tsx +0 -253
- package/apps/admin/app/audit-logs/page.tsx +0 -5
- package/apps/admin/app/dashboard/page.tsx +0 -392
- package/apps/admin/app/files/page.tsx +0 -5
- package/apps/admin/app/globals.css +0 -206
- package/apps/admin/app/jobs/page.tsx +0 -19
- package/apps/admin/app/layout.tsx +0 -57
- package/apps/admin/app/login/page.test.tsx +0 -18
- package/apps/admin/app/login/page.tsx +0 -161
- package/apps/admin/app/login/safe-next-param.ts +0 -4
- package/apps/admin/app/notifications/page.tsx +0 -146
- package/apps/admin/app/page.tsx +0 -5
- package/apps/admin/app/plugins/page.tsx +0 -407
- package/apps/admin/app/profile/page.tsx +0 -116
- package/apps/admin/app/resources/[resource]/[id]/edit/page.tsx +0 -45
- package/apps/admin/app/resources/[resource]/[id]/page.tsx +0 -449
- package/apps/admin/app/resources/[resource]/create/page.tsx +0 -34
- package/apps/admin/app/resources/[resource]/page.tsx +0 -100
- package/apps/admin/app/settings/page.tsx +0 -233
- package/apps/admin/components/ai-assistant-widget.tsx +0 -684
- package/apps/admin/components/app-shell.tsx +0 -305
- package/apps/admin/components/auth-guard.test.tsx +0 -55
- package/apps/admin/components/auth-guard.tsx +0 -39
- package/apps/admin/components/jobs-panel.tsx +0 -103
- package/apps/admin/components/logo.tsx +0 -30
- package/apps/admin/components/resource-form.tsx +0 -349
- package/apps/admin/components/resource-table.tsx +0 -277
- package/apps/admin/lib/ai-events.ts +0 -23
- package/apps/admin/lib/api.test.ts +0 -118
- package/apps/admin/lib/api.ts +0 -135
- package/apps/admin/lib/auth-flow.e2e.test.ts +0 -79
- package/apps/admin/lib/brand.ts +0 -14
- package/apps/admin/lib/locale.ts +0 -49
- package/apps/admin/lib/tokens.ts +0 -93
- package/apps/admin/middleware.ts +0 -58
- package/apps/admin/next-env.d.ts +0 -6
- package/apps/admin/next.config.mjs +0 -7
- package/apps/admin/package.json +0 -44
- package/apps/admin/tailwind.config.ts +0 -37
- package/apps/admin/vitest.config.ts +0 -7
- package/apps/api/package.json +0 -56
- package/apps/api/plugins.manifest.example.json +0 -34
- package/apps/api/plugins.manifest.json +0 -4
- package/apps/api/src/access/catalog.ts +0 -112
- package/apps/api/src/access/derive-permissions.test.ts +0 -26
- package/apps/api/src/access/derive-permissions.ts +0 -36
- package/apps/api/src/access/public-catalog.ts +0 -28
- package/apps/api/src/admin/admin-ai.controller.ts +0 -125
- package/apps/api/src/admin/admin-ai.events.ts +0 -23
- package/apps/api/src/admin/admin-ai.service.ts +0 -1271
- package/apps/api/src/admin/admin-analytics.service.ts +0 -164
- package/apps/api/src/admin/admin-plugins.controller.ts +0 -32
- package/apps/api/src/admin/admin-plugins.service.ts +0 -267
- package/apps/api/src/admin/admin-resource.service.test.ts +0 -118
- package/apps/api/src/admin/admin-resource.service.ts +0 -375
- package/apps/api/src/admin/admin.controller.ts +0 -72
- package/apps/api/src/admin/admin.module.ts +0 -30
- package/apps/api/src/admin/dto/plugins.dto.ts +0 -55
- package/apps/api/src/admin/validate-resource-payload.test.ts +0 -44
- package/apps/api/src/admin/validate-resource-payload.ts +0 -103
- package/apps/api/src/app.module.ts +0 -45
- package/apps/api/src/auth/auth.controller.ts +0 -70
- package/apps/api/src/auth/auth.dto.ts +0 -49
- package/apps/api/src/auth/auth.module.ts +0 -30
- package/apps/api/src/auth/auth.service.test.ts +0 -75
- package/apps/api/src/auth/auth.service.ts +0 -231
- package/apps/api/src/common/auth-realm.decorator.ts +0 -6
- package/apps/api/src/common/auth.guard.test.ts +0 -61
- package/apps/api/src/common/auth.guard.ts +0 -78
- package/apps/api/src/common/casl-ability.factory.test.ts +0 -33
- package/apps/api/src/common/casl-ability.factory.ts +0 -41
- package/apps/api/src/common/current-user.decorator.ts +0 -6
- package/apps/api/src/common/permission.decorator.ts +0 -7
- package/apps/api/src/common/permissions.guard.ts +0 -31
- package/apps/api/src/common/prisma.service.ts +0 -13
- package/apps/api/src/health/health.controller.ts +0 -25
- package/apps/api/src/mail/mail.module.ts +0 -9
- package/apps/api/src/mail/mail.service.ts +0 -115
- package/apps/api/src/main.ts +0 -37
- package/apps/api/src/plugins/bootstrap.ts +0 -4
- package/apps/api/src/plugins/bundled/admin-widget.plugin.ts +0 -25
- package/apps/api/src/plugins/bundled/hello.plugin.ts +0 -19
- package/apps/api/src/plugins/bundled/image-optimizer.plugin.ts +0 -22
- package/apps/api/src/plugins/bundled/registry.ts +0 -13
- package/apps/api/src/plugins/bundled/seo.plugin.ts +0 -25
- package/apps/api/src/plugins/manifest-path.ts +0 -35
- package/apps/api/src/plugins/manifest.schema.test.ts +0 -36
- package/apps/api/src/plugins/manifest.schema.ts +0 -58
- package/apps/api/src/plugins/plugin-api.interceptor.ts +0 -47
- package/apps/api/src/plugins/plugin-loader.ts +0 -134
- package/apps/api/src/plugins/plugin-runtime.test.ts +0 -24
- package/apps/api/src/plugins/plugin-runtime.ts +0 -85
- package/apps/api/src/queue/queue.controller.ts +0 -28
- package/apps/api/src/queue/queue.module.ts +0 -23
- package/apps/api/src/queue/queue.processor.ts +0 -47
- package/apps/api/src/queue/queue.service.ts +0 -50
- package/apps/api/src/resources/categories.resource.ts +0 -21
- package/apps/api/src/resources/commerce.resource.ts +0 -157
- package/apps/api/src/resources/operations.resource.ts +0 -111
- package/apps/api/src/resources/posts.resource.ts +0 -88
- package/apps/api/src/resources/registry.ts +0 -27
- package/apps/api/src/resources/resource-hooks.install.ts +0 -18
- package/apps/api/src/resources/resource-hooks.registry.test.ts +0 -72
- package/apps/api/src/resources/resource-hooks.registry.ts +0 -66
- package/apps/api/src/resources/resource-hooks.runner.ts +0 -93
- package/apps/api/src/resources/system.resource.ts +0 -51
- package/apps/api/src/resources/users.resource.ts +0 -19
- package/apps/api/src/store/payment/payment.controller.ts +0 -98
- package/apps/api/src/store/payment/payment.module.ts +0 -14
- package/apps/api/src/store/payment/payment.provider.ts +0 -38
- package/apps/api/src/store/payment/payment.service.ts +0 -235
- package/apps/api/src/store/store.controller.ts +0 -26
- package/apps/api/src/store/store.module.ts +0 -12
- package/apps/api/src/test-setup.ts +0 -1
- package/apps/api/tsconfig.json +0 -11
- package/apps/api/vitest.config.ts +0 -21
- package/apps/web/lib/openadmin-client.ts +0 -82
- package/apps/web/lib/seo.test.ts +0 -41
- package/apps/web/lib/seo.ts +0 -53
- package/apps/web/next-env.d.ts +0 -6
- package/apps/web/package.json +0 -30
- package/apps/web/postcss.config.mjs +0 -6
- package/apps/web/public/brand/apple-touch-icon.png +0 -0
- package/apps/web/public/brand/favicon.svg +0 -1
- 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/test/next-stub.ts +0 -7
- package/apps/web/tsconfig.json +0 -23
- package/apps/web/vitest.config.ts +0 -19
- package/docs/content/security.md +0 -7
- package/eslint.config.mjs +0 -11
- package/examples/README.md +0 -80
- package/examples/basic-admin/README.md +0 -24
- package/examples/basic-admin/package.json +0 -17
- package/examples/basic-admin/prisma/models.fragment.prisma +0 -12
- package/examples/basic-admin/src/index.test.ts +0 -8
- package/examples/basic-admin/src/index.ts +0 -5
- package/examples/basic-admin/src/resources/lead.resource.ts +0 -30
- package/examples/basic-admin/tsconfig.json +0 -7
- package/examples/basic-admin/vitest.config.ts +0 -16
- package/examples/blog-admin/README.md +0 -18
- package/examples/blog-admin/package.json +0 -17
- package/examples/blog-admin/prisma/models.fragment.prisma +0 -30
- package/examples/blog-admin/src/index.test.ts +0 -8
- package/examples/blog-admin/src/index.ts +0 -5
- package/examples/blog-admin/src/resources/authors.resource.ts +0 -21
- package/examples/blog-admin/src/resources/tags.resource.ts +0 -20
- package/examples/blog-admin/tsconfig.json +0 -7
- package/examples/blog-admin/vitest.config.ts +0 -16
- package/examples/crm-admin/README.md +0 -17
- package/examples/crm-admin/package.json +0 -17
- package/examples/crm-admin/prisma/models.fragment.prisma +0 -50
- package/examples/crm-admin/src/index.test.ts +0 -9
- package/examples/crm-admin/src/index.ts +0 -7
- package/examples/crm-admin/src/resources/activities.resource.ts +0 -29
- package/examples/crm-admin/src/resources/companies.resource.ts +0 -21
- package/examples/crm-admin/src/resources/contacts.resource.ts +0 -24
- package/examples/crm-admin/src/resources/deals.resource.ts +0 -30
- package/examples/crm-admin/tsconfig.json +0 -7
- package/examples/crm-admin/vitest.config.ts +0 -16
- package/examples/ecommerce-admin/README.md +0 -17
- package/examples/ecommerce-admin/package.json +0 -17
- package/examples/ecommerce-admin/prisma/models.fragment.prisma +0 -43
- package/examples/ecommerce-admin/src/index.test.ts +0 -8
- package/examples/ecommerce-admin/src/index.ts +0 -7
- package/examples/ecommerce-admin/src/resources/customers.resource.ts +0 -21
- package/examples/ecommerce-admin/src/resources/order-items.resource.ts +0 -22
- package/examples/ecommerce-admin/src/resources/orders.resource.ts +0 -27
- package/examples/ecommerce-admin/src/resources/products.resource.ts +0 -23
- package/examples/ecommerce-admin/tsconfig.json +0 -7
- package/examples/ecommerce-admin/vitest.config.ts +0 -16
- package/examples/marketplace-admin/README.md +0 -17
- package/examples/marketplace-admin/package.json +0 -17
- package/examples/marketplace-admin/prisma/models.fragment.prisma +0 -32
- package/examples/marketplace-admin/src/index.test.ts +0 -8
- package/examples/marketplace-admin/src/index.ts +0 -6
- package/examples/marketplace-admin/src/resources/listings.resource.ts +0 -29
- package/examples/marketplace-admin/src/resources/payouts.resource.ts +0 -28
- package/examples/marketplace-admin/src/resources/sellers.resource.ts +0 -28
- package/examples/marketplace-admin/tsconfig.json +0 -7
- package/examples/marketplace-admin/vitest.config.ts +0 -16
- package/examples/support-admin/README.md +0 -18
- package/examples/support-admin/package.json +0 -17
- package/examples/support-admin/prisma/models.fragment.prisma +0 -20
- package/examples/support-admin/src/index.test.ts +0 -8
- package/examples/support-admin/src/index.ts +0 -5
- package/examples/support-admin/src/resources/ticket-messages.resource.ts +0 -22
- package/examples/support-admin/src/resources/tickets.resource.ts +0 -35
- package/examples/support-admin/tsconfig.json +0 -7
- package/examples/support-admin/vitest.config.ts +0 -16
- package/packages/auth/package.json +0 -17
- package/packages/auth/src/index.test.ts +0 -10
- package/packages/auth/src/index.ts +0 -17
- package/packages/auth/tsconfig.json +0 -8
- package/packages/brand/apps/admin/public/brand/apple-touch-icon.png +0 -0
- package/packages/brand/apps/admin/public/brand/favicon.svg +0 -1
- 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 +0 -1
- 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 +0 -19
- package/packages/brand/site/assets/brand/favicon.svg +0 -1
- package/packages/brand/site/assets/brand/og-image.svg +0 -1
- package/packages/brand/site/assets/brand/openadminjs-icon.svg +0 -1
- package/packages/brand/site/assets/brand/openadminjs-logo-dark.svg +0 -1
- package/packages/brand/site/assets/brand/openadminjs-logo-horizontal.svg +0 -1
- package/packages/brand/site/assets/brand/openadminjs-logo-monochrome.svg +0 -1
- package/packages/brand/site/assets/brand/openadminjs-logo.svg +0 -1
- package/packages/brand/src/generate-assets.mjs +0 -182
- package/packages/brand/src/index.test.ts +0 -9
- package/packages/brand/src/index.ts +0 -7
- package/packages/brand/tsconfig.json +0 -7
- package/packages/cli/package.json +0 -44
- package/packages/cli/src/create-project.ts +0 -316
- package/packages/cli/src/index.test.ts +0 -8
- package/packages/cli/src/index.ts +0 -149
- package/packages/cli/src/resource-slug.test.ts +0 -10
- package/packages/cli/src/resource-slug.ts +0 -4
- package/packages/cli/template/apps/web/README.md +0 -12
- package/packages/cli/template/apps/web/app/globals.css +0 -12
- package/packages/cli/template/apps/web/app/layout.tsx +0 -18
- package/packages/cli/template/apps/web/app/page.tsx +0 -27
- package/packages/cli/template/apps/web/app/posts/[slug]/page.tsx +0 -38
- package/packages/cli/template/apps/web/app/posts/page.tsx +0 -20
- package/packages/cli/template/apps/web/app/robots.txt/route.ts +0 -9
- package/packages/cli/template/apps/web/app/sitemap.xml/route.ts +0 -20
- package/packages/cli/template/apps/web/components/public-fields.tsx +0 -22
- package/packages/cli/template/apps/web/next.config.mjs +0 -5
- package/packages/cli/template/apps/web/postcss.config.mjs +0 -6
- package/packages/cli/template/apps/web/public/brand/apple-touch-icon.png +0 -0
- package/packages/cli/template/apps/web/public/brand/favicon.svg +0 -1
- 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 +0 -21
- package/packages/cli/template/apps/web/tsconfig.json +0 -23
- package/packages/cli/tsconfig.json +0 -10
- package/packages/core/package.json +0 -20
- package/packages/core/src/index.js +0 -1
- package/packages/core/src/index.test.ts +0 -27
- package/packages/core/src/index.ts +0 -61
- package/packages/core/tsconfig.json +0 -8
- package/packages/create-openadminjs/package.json +0 -25
- package/packages/create-openadminjs/src/index.ts +0 -122
- package/packages/create-openadminjs/src/package-name.test.ts +0 -13
- package/packages/create-openadminjs/src/package-name.ts +0 -8
- package/packages/create-openadminjs/src/render-files.test.ts +0 -26
- package/packages/create-openadminjs/src/render-files.ts +0 -21
- package/packages/create-openadminjs/template/.env.example +0 -7
- package/packages/create-openadminjs/template/README.md +0 -13
- package/packages/create-openadminjs/template/apps/web/README.md +0 -12
- package/packages/create-openadminjs/template/apps/web/app/globals.css +0 -12
- package/packages/create-openadminjs/template/apps/web/app/layout.tsx +0 -18
- package/packages/create-openadminjs/template/apps/web/app/page.tsx +0 -27
- package/packages/create-openadminjs/template/apps/web/app/posts/[slug]/page.tsx +0 -38
- package/packages/create-openadminjs/template/apps/web/app/posts/page.tsx +0 -20
- package/packages/create-openadminjs/template/apps/web/app/robots.txt/route.ts +0 -9
- package/packages/create-openadminjs/template/apps/web/app/sitemap.xml/route.ts +0 -20
- package/packages/create-openadminjs/template/apps/web/components/public-fields.tsx +0 -22
- package/packages/create-openadminjs/template/apps/web/lib/openadmin-client.ts +0 -71
- package/packages/create-openadminjs/template/apps/web/lib/seo.ts +0 -42
- package/packages/create-openadminjs/template/apps/web/next-env.d.ts +0 -2
- package/packages/create-openadminjs/template/apps/web/next.config.mjs +0 -5
- package/packages/create-openadminjs/template/apps/web/package.json +0 -29
- package/packages/create-openadminjs/template/apps/web/postcss.config.mjs +0 -6
- 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 +0 -1
- 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 +0 -21
- package/packages/create-openadminjs/template/apps/web/tsconfig.json +0 -23
- package/packages/create-openadminjs/template/package.json +0 -19
- package/packages/create-openadminjs/template/pnpm-workspace.yaml +0 -3
- package/packages/create-openadminjs/tsconfig.json +0 -10
- package/packages/mail/package.json +0 -18
- package/packages/mail/src/index.test.ts +0 -23
- package/packages/mail/src/index.ts +0 -246
- package/packages/mail/tsconfig.json +0 -5
- package/packages/notifications/package.json +0 -16
- package/packages/notifications/src/index.test.ts +0 -9
- package/packages/notifications/src/index.ts +0 -5
- package/packages/notifications/tsconfig.json +0 -5
- package/packages/payments/package.json +0 -15
- package/packages/payments/src/index.ts +0 -256
- package/packages/payments/tsconfig.json +0 -9
- package/packages/permissions/package.json +0 -17
- package/packages/permissions/src/blueprints.js +0 -57
- package/packages/permissions/src/blueprints.test.ts +0 -62
- package/packages/permissions/src/blueprints.ts +0 -89
- package/packages/permissions/src/index.js +0 -11
- package/packages/permissions/src/index.test.ts +0 -34
- package/packages/permissions/src/index.ts +0 -22
- package/packages/permissions/tsconfig.json +0 -8
- package/packages/plugin-sdk/package.json +0 -26
- package/packages/plugin-sdk/src/hooks.ts +0 -135
- package/packages/plugin-sdk/src/index.ts +0 -42
- package/packages/plugin-sdk/src/sdk.test.ts +0 -13
- package/packages/plugin-sdk/tsconfig.json +0 -8
- package/packages/plugin-sdk/vitest.config.ts +0 -5
- package/packages/queue/package.json +0 -16
- package/packages/queue/src/index.test.ts +0 -12
- package/packages/queue/src/index.ts +0 -6
- package/packages/queue/tsconfig.json +0 -5
- package/packages/resource/package.json +0 -17
- package/packages/resource/src/index.js +0 -177
- package/packages/resource/src/index.test.ts +0 -151
- package/packages/resource/src/index.ts +0 -344
- package/packages/resource/tsconfig.json +0 -8
- package/packages/storage/package.json +0 -16
- package/packages/storage/src/index.test.ts +0 -10
- package/packages/storage/src/index.ts +0 -23
- package/packages/storage/tsconfig.json +0 -5
- package/pnpm-workspace.yaml +0 -4
- package/prisma/migrations/20260505151751_baseline_init_all_tables/migration.sql +0 -371
- package/prisma/migrations/migration_lock.toml +0 -3
- package/prisma/schema.prisma +0 -291
- package/prisma/seed.ts +0 -210
- package/scripts/check-static-site.mjs +0 -17
- package/scripts/e2e-smoke.mjs +0 -17
- package/scripts/make-executable.mjs +0 -4
- package/site/.nojekyll +0 -0
- package/site/assets/brand/apple-touch-icon.png +0 -0
- package/site/assets/brand/favicon.svg +0 -1
- 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 +0 -1521
- package/site/assets/js/main.js +0 -193
- package/site/assets/partners/arcbyte.svg +0 -11
- package/site/assets/partners/gridstack.svg +0 -8
- package/site/assets/partners/nebula.svg +0 -12
- package/site/assets/partners/orbitlab.svg +0 -7
- package/site/assets/partners/pulseforge.svg +0 -11
- package/site/assets/partners/vertex.svg +0 -6
- package/site/docs.html +0 -1459
- package/site/index.html +0 -357
- package/tsconfig.base.json +0 -23
- /package/{packages/cli/template → template}/README.md +0 -0
- /package/{apps → template/apps}/web/README.md +0 -0
- /package/{apps → template/apps}/web/app/globals.css +0 -0
- /package/{apps → template/apps}/web/app/layout.tsx +0 -0
- /package/{apps → template/apps}/web/app/page.tsx +0 -0
- /package/{apps → template/apps}/web/app/posts/[slug]/page.tsx +0 -0
- /package/{apps → template/apps}/web/app/posts/page.tsx +0 -0
- /package/{apps → template/apps}/web/app/robots.txt/route.ts +0 -0
- /package/{apps → template/apps}/web/app/sitemap.xml/route.ts +0 -0
- /package/{apps → template/apps}/web/components/public-fields.tsx +0 -0
- /package/{packages/cli/template → template}/apps/web/lib/openadmin-client.ts +0 -0
- /package/{packages/cli/template → template}/apps/web/lib/seo.ts +0 -0
- /package/{packages/cli/template → template}/apps/web/next-env.d.ts +0 -0
- /package/{apps → template/apps}/web/next.config.mjs +0 -0
- /package/{packages/cli/template → template}/apps/web/package.json +0 -0
- /package/{apps/admin → template/apps/web}/postcss.config.mjs +0 -0
- /package/{apps/admin → template/apps/web}/public/brand/apple-touch-icon.png +0 -0
- /package/{apps/admin → template/apps/web}/public/brand/favicon.svg +0 -0
- /package/{apps/admin → template/apps/web}/public/brand/og-image.png +0 -0
- /package/{apps/admin → template/apps/web}/public/brand/openadminjs-icon-new.png +0 -0
- /package/{apps/admin → template/apps/web}/public/brand/openadminjs-logo-monochrome.png +0 -0
- /package/{apps/admin → template/apps/web}/public/brand/openadminjs-logo-new.png +0 -0
- /package/{apps → template/apps}/web/tailwind.config.ts +0 -0
- /package/{apps/admin → template/apps/web}/tsconfig.json +0 -0
- /package/{packages/cli/template → template}/package.json +0 -0
- /package/{packages/cli/template → template}/pnpm-workspace.yaml +0 -0
|
@@ -1,41 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
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);
|
|
@@ -1,31 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
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
|
-
}
|
package/apps/api/src/main.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
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();
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { OpenAdminPlugin } from "@openadminjs/plugin-sdk";
|
|
2
|
-
|
|
3
|
-
export const adminWidgetBundledPlugin: OpenAdminPlugin = {
|
|
4
|
-
id: "io.openadminjs.admin-widget",
|
|
5
|
-
version: "0.1.0",
|
|
6
|
-
displayName: "Admin widget demo",
|
|
7
|
-
register({ registerSurface }) {
|
|
8
|
-
registerSurface({
|
|
9
|
-
adminUi: [
|
|
10
|
-
{
|
|
11
|
-
kind: "widget",
|
|
12
|
-
id: "ops-health",
|
|
13
|
-
title: "Ops Health",
|
|
14
|
-
config: { metric: "queueLag", severity: "info" }
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
kind: "menu",
|
|
18
|
-
id: "plugin-insights",
|
|
19
|
-
title: "Plugin Insights",
|
|
20
|
-
route: "/plugins/insights"
|
|
21
|
-
}
|
|
22
|
-
]
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { OpenAdminPlugin } from "@openadminjs/plugin-sdk";
|
|
2
|
-
|
|
3
|
-
export const imageOptimizerBundledPlugin: OpenAdminPlugin = {
|
|
4
|
-
id: "io.openadminjs.image-optimizer",
|
|
5
|
-
version: "0.1.0",
|
|
6
|
-
displayName: "Image optimizer demo",
|
|
7
|
-
register({ registerSurface }) {
|
|
8
|
-
registerSurface({
|
|
9
|
-
media: {
|
|
10
|
-
transform(ctx) {
|
|
11
|
-
if (!ctx.mimeType.startsWith("image/")) return ctx;
|
|
12
|
-
const filename = ctx.filename.replace(/\.(png|jpe?g|webp)$/i, "") + ".webp";
|
|
13
|
-
return {
|
|
14
|
-
...ctx,
|
|
15
|
-
filename,
|
|
16
|
-
mimeType: "image/webp"
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { OpenAdminPlugin } from "@openadminjs/plugin-sdk";
|
|
2
|
-
import { adminWidgetBundledPlugin } from "./admin-widget.plugin";
|
|
3
|
-
import { helloBundledPlugin } from "./hello.plugin";
|
|
4
|
-
import { imageOptimizerBundledPlugin } from "./image-optimizer.plugin";
|
|
5
|
-
import { seoBundledPlugin } from "./seo.plugin";
|
|
6
|
-
|
|
7
|
-
/** First-party plugins shipped inside the API package (no separate npm install). */
|
|
8
|
-
export const bundledOpenAdminPlugins: Record<string, OpenAdminPlugin> = {
|
|
9
|
-
hello: helloBundledPlugin,
|
|
10
|
-
seo: seoBundledPlugin,
|
|
11
|
-
"image-optimizer": imageOptimizerBundledPlugin,
|
|
12
|
-
"admin-widget": adminWidgetBundledPlugin
|
|
13
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { OpenAdminPlugin } from "@openadminjs/plugin-sdk";
|
|
2
|
-
|
|
3
|
-
export const seoBundledPlugin: OpenAdminPlugin = {
|
|
4
|
-
id: "io.openadminjs.seo",
|
|
5
|
-
version: "0.1.0",
|
|
6
|
-
displayName: "SEO metadata + sitemap demo",
|
|
7
|
-
register({ registerSurface }) {
|
|
8
|
-
registerSurface({
|
|
9
|
-
seo: {
|
|
10
|
-
metadata({ resourceName, record }) {
|
|
11
|
-
if (resourceName !== "posts") return {};
|
|
12
|
-
return {
|
|
13
|
-
title: record.title ?? "Untitled",
|
|
14
|
-
description: record.excerpt ?? "",
|
|
15
|
-
canonical: record.slug ? `/posts/${record.slug}` : undefined
|
|
16
|
-
};
|
|
17
|
-
},
|
|
18
|
-
sitemapEntry({ resourceName, record }) {
|
|
19
|
-
if (resourceName !== "posts" || !record.slug) return null;
|
|
20
|
-
return { url: `/posts/${record.slug}`, lastModified: typeof record.updatedAt === "string" ? record.updatedAt : undefined };
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
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 }, capabilities: ["resource.hooks"], trustMode: "sandboxed" }]
|
|
9
|
-
});
|
|
10
|
-
expect(r.success).toBe(true);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it("rejects unknown capability", () => {
|
|
14
|
-
const r = pluginManifestSchema.safeParse({
|
|
15
|
-
version: 1,
|
|
16
|
-
plugins: [{ id: "a.b", bundled: "hello", capabilities: ["unknown.cap"] }]
|
|
17
|
-
});
|
|
18
|
-
expect(r.success).toBe(false);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("rejects both bundled and package", () => {
|
|
22
|
-
const r = pluginManifestSchema.safeParse({
|
|
23
|
-
version: 1,
|
|
24
|
-
plugins: [{ id: "x", bundled: "hello", package: "@x/y" }]
|
|
25
|
-
});
|
|
26
|
-
expect(r.success).toBe(false);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("rejects neither bundled nor package", () => {
|
|
30
|
-
const r = pluginManifestSchema.safeParse({
|
|
31
|
-
version: 1,
|
|
32
|
-
plugins: [{ id: "x" }]
|
|
33
|
-
});
|
|
34
|
-
expect(r.success).toBe(false);
|
|
35
|
-
});
|
|
36
|
-
});
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
const capabilitySchema = z.enum([
|
|
4
|
-
"db.read",
|
|
5
|
-
"db.write",
|
|
6
|
-
"resource.hooks",
|
|
7
|
-
"api.hooks",
|
|
8
|
-
"api.routes",
|
|
9
|
-
"media.pipeline",
|
|
10
|
-
"seo.extend",
|
|
11
|
-
"jobs.run",
|
|
12
|
-
"admin.ui.extend"
|
|
13
|
-
]);
|
|
14
|
-
|
|
15
|
-
export const pluginManifestEntrySchema = z
|
|
16
|
-
.object({
|
|
17
|
-
id: z.string().min(1),
|
|
18
|
-
enabled: z.boolean().optional().default(true),
|
|
19
|
-
trustMode: z.enum(["trusted", "sandboxed"]).optional().default("trusted"),
|
|
20
|
-
capabilities: z.array(capabilitySchema).optional().default([]),
|
|
21
|
-
bundled: z
|
|
22
|
-
.string()
|
|
23
|
-
.regex(/^[a-z0-9-]+$/, "bundled id must be lowercase slug")
|
|
24
|
-
.optional(),
|
|
25
|
-
package: z
|
|
26
|
-
.string()
|
|
27
|
-
.min(1)
|
|
28
|
-
.regex(/^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/i, "invalid npm package name")
|
|
29
|
-
.optional(),
|
|
30
|
-
config: z.record(z.string(), z.unknown()).optional().default({}),
|
|
31
|
-
policy: z
|
|
32
|
-
.object({
|
|
33
|
-
allowedRoutes: z.array(z.string()).optional(),
|
|
34
|
-
maxJobRuntimeMs: z.number().int().positive().optional()
|
|
35
|
-
})
|
|
36
|
-
.optional(),
|
|
37
|
-
marketplace: z
|
|
38
|
-
.object({
|
|
39
|
-
listingUrl: z.string().optional(),
|
|
40
|
-
productId: z.string().optional(),
|
|
41
|
-
licenseKey: z.string().optional()
|
|
42
|
-
})
|
|
43
|
-
.optional()
|
|
44
|
-
})
|
|
45
|
-
.strict()
|
|
46
|
-
.refine((e) => Number(Boolean(e.bundled)) + Number(Boolean(e.package)) === 1, {
|
|
47
|
-
message: "Each plugin must set exactly one of: bundled, package"
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
export const pluginManifestSchema = z
|
|
51
|
-
.object({
|
|
52
|
-
version: z.literal(1),
|
|
53
|
-
plugins: z.array(pluginManifestEntrySchema)
|
|
54
|
-
})
|
|
55
|
-
.strict();
|
|
56
|
-
|
|
57
|
-
export type PluginManifest = z.infer<typeof pluginManifestSchema>;
|
|
58
|
-
export type PluginManifestEntry = z.infer<typeof pluginManifestEntrySchema>;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from "@nestjs/common";
|
|
2
|
-
import { Observable, tap } from "rxjs";
|
|
3
|
-
import { pluginRuntime } from "./plugin-runtime";
|
|
4
|
-
|
|
5
|
-
@Injectable()
|
|
6
|
-
export class PluginApiInterceptor implements NestInterceptor {
|
|
7
|
-
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown> {
|
|
8
|
-
if (context.getType() !== "http") return next.handle();
|
|
9
|
-
const request = context.switchToHttp().getRequest<{
|
|
10
|
-
method?: string;
|
|
11
|
-
route?: { path?: string };
|
|
12
|
-
path?: string;
|
|
13
|
-
body?: unknown;
|
|
14
|
-
query?: Record<string, unknown>;
|
|
15
|
-
user?: { id?: string; email?: string; permissions?: string[] };
|
|
16
|
-
}>();
|
|
17
|
-
const response = context.switchToHttp().getResponse<{ statusCode?: number }>();
|
|
18
|
-
const method = request.method ?? "GET";
|
|
19
|
-
const path = request.route?.path ?? request.path ?? "/";
|
|
20
|
-
const started = Date.now();
|
|
21
|
-
for (const hook of pluginRuntime.getApiHooks()) {
|
|
22
|
-
void hook.beforeRequest?.({
|
|
23
|
-
method,
|
|
24
|
-
path,
|
|
25
|
-
body: request.body,
|
|
26
|
-
query: request.query,
|
|
27
|
-
user: request.user?.id ? { id: request.user.id, email: request.user.email ?? "", permissions: request.user.permissions ?? [] } : undefined
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
return next.handle().pipe(
|
|
31
|
-
tap({
|
|
32
|
-
next: () => {
|
|
33
|
-
const durationMs = Date.now() - started;
|
|
34
|
-
for (const hook of pluginRuntime.getApiHooks()) {
|
|
35
|
-
void hook.afterRequest?.({
|
|
36
|
-
method,
|
|
37
|
-
path,
|
|
38
|
-
statusCode: response.statusCode ?? 200,
|
|
39
|
-
durationMs,
|
|
40
|
-
user: request.user?.id ? { id: request.user.id, email: request.user.email ?? "", permissions: request.user.permissions ?? [] } : undefined
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
})
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
}
|