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,177 +0,0 @@
|
|
|
1
|
-
export const sensitiveFieldPatterns = [
|
|
2
|
-
"password",
|
|
3
|
-
"passwordHash",
|
|
4
|
-
"token",
|
|
5
|
-
"accessToken",
|
|
6
|
-
"refreshToken",
|
|
7
|
-
"secret",
|
|
8
|
-
"apiKey",
|
|
9
|
-
"privateKey",
|
|
10
|
-
"resetToken",
|
|
11
|
-
"verificationToken",
|
|
12
|
-
"otp",
|
|
13
|
-
"twoFactorSecret"
|
|
14
|
-
];
|
|
15
|
-
export function defineResource(config) {
|
|
16
|
-
validateResource(config);
|
|
17
|
-
return withSafeFields(config);
|
|
18
|
-
}
|
|
19
|
-
export function isSensitiveField(name, field) {
|
|
20
|
-
if (field?.sensitive || field?.type === "password" || field?.type === "hidden")
|
|
21
|
-
return true;
|
|
22
|
-
const lower = name.toLowerCase();
|
|
23
|
-
return sensitiveFieldPatterns.some((pattern) => lower.includes(pattern.toLowerCase()));
|
|
24
|
-
}
|
|
25
|
-
export function withSafeFields(config) {
|
|
26
|
-
const fields = Object.fromEntries(Object.entries(config.fields).map(([name, field]) => {
|
|
27
|
-
if (!isSensitiveField(name, field))
|
|
28
|
-
return [name, field];
|
|
29
|
-
return [
|
|
30
|
-
name,
|
|
31
|
-
{
|
|
32
|
-
...field,
|
|
33
|
-
list: false,
|
|
34
|
-
detail: false,
|
|
35
|
-
create: field.type === "password" ? field.create : false,
|
|
36
|
-
edit: field.type === "password" ? field.edit : false,
|
|
37
|
-
sensitive: true
|
|
38
|
-
}
|
|
39
|
-
];
|
|
40
|
-
}));
|
|
41
|
-
return { ...config, fields };
|
|
42
|
-
}
|
|
43
|
-
export function validateResource(config) {
|
|
44
|
-
if (!config.name || !/^[a-z][a-z0-9-]*$/.test(config.name)) {
|
|
45
|
-
throw new Error(`Invalid resource name "${config.name}". Use kebab-case.`);
|
|
46
|
-
}
|
|
47
|
-
if (!config.model || !/^[A-Za-z][A-Za-z0-9_]*$/.test(config.model)) {
|
|
48
|
-
throw new Error(`Invalid Prisma model name for resource "${config.name}".`);
|
|
49
|
-
}
|
|
50
|
-
if (!config.permissions.read) {
|
|
51
|
-
throw new Error(`Resource "${config.name}" must define permissions.read.`);
|
|
52
|
-
}
|
|
53
|
-
if (!Object.keys(config.fields).length) {
|
|
54
|
-
throw new Error(`Resource "${config.name}" must define at least one field.`);
|
|
55
|
-
}
|
|
56
|
-
const ls = config.listScope;
|
|
57
|
-
if (ls && "field" in ls && ls.type === "userOwns") {
|
|
58
|
-
if (!ls.field?.trim()) {
|
|
59
|
-
throw new Error(`Resource "${config.name}" listScope.userOwns requires a non-empty field.`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
export function visibleFields(resource, mode, permissions) {
|
|
64
|
-
return Object.fromEntries(Object.entries(resource.fields).filter(([name, field]) => {
|
|
65
|
-
if (isSensitiveField(name, field))
|
|
66
|
-
return false;
|
|
67
|
-
if (field[mode] === false)
|
|
68
|
-
return false;
|
|
69
|
-
const permissionKey = mode === "detail" || mode === "list" ? "read" : mode === "edit" ? "update" : "create";
|
|
70
|
-
const permission = field.permissions?.[permissionKey];
|
|
71
|
-
return permission ? permissions.includes(permission) : true;
|
|
72
|
-
}));
|
|
73
|
-
}
|
|
74
|
-
export function pickLocalizedLabel(label, locale, fallbackLocale = "en") {
|
|
75
|
-
if (label == null || label === "")
|
|
76
|
-
return "";
|
|
77
|
-
if (typeof label === "string")
|
|
78
|
-
return label;
|
|
79
|
-
return label[locale] ?? label[fallbackLocale] ?? Object.values(label)[0] ?? "";
|
|
80
|
-
}
|
|
81
|
-
export function effectiveLocale(resource, requested) {
|
|
82
|
-
const fb = resource.i18n?.defaultLocale ?? "en";
|
|
83
|
-
const locales = resource.i18n?.locales;
|
|
84
|
-
if (!requested)
|
|
85
|
-
return fb;
|
|
86
|
-
if (!locales?.length)
|
|
87
|
-
return requested;
|
|
88
|
-
return locales.includes(requested) ? requested : fb;
|
|
89
|
-
}
|
|
90
|
-
export function resolveResourceForLocale(resource, locale) {
|
|
91
|
-
const fb = resource.i18n?.defaultLocale ?? "en";
|
|
92
|
-
const loc = effectiveLocale(resource, locale);
|
|
93
|
-
const fields = Object.fromEntries(Object.entries(resource.fields).map(([key, field]) => [
|
|
94
|
-
key,
|
|
95
|
-
{
|
|
96
|
-
...field,
|
|
97
|
-
label: pickLocalizedLabel(field.label, loc, fb) || field.label
|
|
98
|
-
}
|
|
99
|
-
]));
|
|
100
|
-
const actions = resource.actions
|
|
101
|
-
? Object.fromEntries(Object.entries(resource.actions).map(([key, action]) => [
|
|
102
|
-
key,
|
|
103
|
-
{
|
|
104
|
-
...action,
|
|
105
|
-
label: pickLocalizedLabel(action.label, loc, fb) || action.label
|
|
106
|
-
}
|
|
107
|
-
]))
|
|
108
|
-
: undefined;
|
|
109
|
-
return {
|
|
110
|
-
...resource,
|
|
111
|
-
label: pickLocalizedLabel(resource.label, loc, fb),
|
|
112
|
-
fields,
|
|
113
|
-
actions
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
export function shouldApplyListScope(resource, userPermissions) {
|
|
117
|
-
const ls = resource.listScope;
|
|
118
|
-
if (!ls || ls.type === "none" || !("field" in ls))
|
|
119
|
-
return false;
|
|
120
|
-
if (userPermissions.includes("*"))
|
|
121
|
-
return false;
|
|
122
|
-
for (const p of ls.bypassPermissions ?? []) {
|
|
123
|
-
if (userPermissions.includes(p))
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
return true;
|
|
127
|
-
}
|
|
128
|
-
export function listScopeWhereClause(resource, userId) {
|
|
129
|
-
const ls = resource.listScope;
|
|
130
|
-
if (!ls || ls.type === "none" || !("field" in ls))
|
|
131
|
-
return undefined;
|
|
132
|
-
return { [ls.field]: userId };
|
|
133
|
-
}
|
|
134
|
-
export function mergeWhereClauses(...parts) {
|
|
135
|
-
const clauses = parts.filter(Boolean);
|
|
136
|
-
if (!clauses.length)
|
|
137
|
-
return undefined;
|
|
138
|
-
if (clauses.length === 1)
|
|
139
|
-
return clauses[0];
|
|
140
|
-
return { AND: clauses };
|
|
141
|
-
}
|
|
142
|
-
export function buildSeoPagePayload(opts) {
|
|
143
|
-
const { siteUrl, basePath, seo, record, resourceLabel } = opts;
|
|
144
|
-
const titleField = seo?.titleField ?? "title";
|
|
145
|
-
const descField = seo?.descriptionField ?? "description";
|
|
146
|
-
const slugField = seo?.slugField ?? "slug";
|
|
147
|
-
const title = String(record[titleField] ?? resourceLabel);
|
|
148
|
-
const description = String(record[descField] ?? record["excerpt"] ?? `${resourceLabel} page`);
|
|
149
|
-
const slug = String(record[slugField] ?? record["id"]);
|
|
150
|
-
const path = (seo?.pathPattern ?? `${basePath}/:slug`).replace(":slug", encodeURIComponent(slug));
|
|
151
|
-
const canonicalUrl = new URL(path.startsWith("/") ? path : `/${path}`, siteUrl).toString();
|
|
152
|
-
const ogImageField = seo?.ogImageField;
|
|
153
|
-
const imageUrl = ogImageField && record[ogImageField] ? String(record[ogImageField]) : undefined;
|
|
154
|
-
const languages = {};
|
|
155
|
-
if (seo?.alternateSlugFields) {
|
|
156
|
-
for (const [loc, field] of Object.entries(seo.alternateSlugFields)) {
|
|
157
|
-
const altSlug = record[field];
|
|
158
|
-
if (altSlug != null && String(altSlug)) {
|
|
159
|
-
const altPath = (seo.pathPattern ?? `${basePath}/:slug`).replace(":slug", encodeURIComponent(String(altSlug)));
|
|
160
|
-
languages[loc] = new URL(altPath.startsWith("/") ? altPath : `/${altPath}`, siteUrl).toString();
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return {
|
|
165
|
-
title,
|
|
166
|
-
description,
|
|
167
|
-
canonicalUrl,
|
|
168
|
-
openGraph: {
|
|
169
|
-
title,
|
|
170
|
-
description,
|
|
171
|
-
url: canonicalUrl,
|
|
172
|
-
type: "article",
|
|
173
|
-
...(imageUrl ? { images: [{ url: imageUrl }] } : {})
|
|
174
|
-
},
|
|
175
|
-
...(Object.keys(languages).length ? { alternates: { languages } } : {})
|
|
176
|
-
};
|
|
177
|
-
}
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
defineResource,
|
|
4
|
-
isSensitiveField,
|
|
5
|
-
resolveResourceForLocale,
|
|
6
|
-
validateResource,
|
|
7
|
-
visibleFields,
|
|
8
|
-
withSafeFields
|
|
9
|
-
} from "./index";
|
|
10
|
-
|
|
11
|
-
describe("defineResource", () => {
|
|
12
|
-
it("hides sensitive fields by default", () => {
|
|
13
|
-
const resource = defineResource({
|
|
14
|
-
name: "users",
|
|
15
|
-
label: "Users",
|
|
16
|
-
model: "User",
|
|
17
|
-
permissions: { read: "users.read" },
|
|
18
|
-
fields: {
|
|
19
|
-
id: { type: "id" },
|
|
20
|
-
email: { type: "email" },
|
|
21
|
-
passwordHash: { type: "text" }
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
expect(isSensitiveField("passwordHash", resource.fields.passwordHash)).toBe(true);
|
|
26
|
-
expect(visibleFields(resource, "list", [])).not.toHaveProperty("passwordHash");
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("requires read permission", () => {
|
|
30
|
-
expect(() =>
|
|
31
|
-
defineResource({
|
|
32
|
-
name: "posts",
|
|
33
|
-
label: "Posts",
|
|
34
|
-
model: "Post",
|
|
35
|
-
permissions: {},
|
|
36
|
-
fields: { id: { type: "id" } }
|
|
37
|
-
})
|
|
38
|
-
).toThrow("permissions.read");
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("rejects invalid resource names", () => {
|
|
42
|
-
expect(() =>
|
|
43
|
-
defineResource({
|
|
44
|
-
name: "BadName",
|
|
45
|
-
label: "X",
|
|
46
|
-
model: "X",
|
|
47
|
-
permissions: { read: "x.read" },
|
|
48
|
-
fields: { id: { type: "id" } }
|
|
49
|
-
})
|
|
50
|
-
).toThrow("Invalid resource name");
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("rejects invalid prisma model names", () => {
|
|
54
|
-
expect(() =>
|
|
55
|
-
defineResource({
|
|
56
|
-
name: "items",
|
|
57
|
-
label: "Items",
|
|
58
|
-
model: "9bad",
|
|
59
|
-
permissions: { read: "items.read" },
|
|
60
|
-
fields: { id: { type: "id" } }
|
|
61
|
-
})
|
|
62
|
-
).toThrow("Invalid Prisma model name");
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it("rejects empty fields", () => {
|
|
66
|
-
expect(() =>
|
|
67
|
-
validateResource({
|
|
68
|
-
name: "items",
|
|
69
|
-
label: "Items",
|
|
70
|
-
model: "Item",
|
|
71
|
-
permissions: { read: "items.read" },
|
|
72
|
-
fields: {}
|
|
73
|
-
})
|
|
74
|
-
).toThrow("at least one field");
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
describe("visibleFields", () => {
|
|
79
|
-
it("respects field-level read permission", () => {
|
|
80
|
-
const resource = defineResource({
|
|
81
|
-
name: "posts",
|
|
82
|
-
label: "Posts",
|
|
83
|
-
model: "Post",
|
|
84
|
-
permissions: { read: "posts.read" },
|
|
85
|
-
fields: {
|
|
86
|
-
id: { type: "id", list: true },
|
|
87
|
-
title: { type: "text", list: true, permissions: { read: "posts.title" } },
|
|
88
|
-
body: { type: "textarea", list: true }
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
const list = visibleFields(resource, "list", ["posts.read"]);
|
|
93
|
-
expect(list).toHaveProperty("id");
|
|
94
|
-
expect(list).not.toHaveProperty("title");
|
|
95
|
-
expect(list).toHaveProperty("body");
|
|
96
|
-
|
|
97
|
-
const withTitle = visibleFields(resource, "list", ["posts.read", "posts.title"]);
|
|
98
|
-
expect(withTitle).toHaveProperty("title");
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it("hides fields with list: false", () => {
|
|
102
|
-
const resource = defineResource({
|
|
103
|
-
name: "posts",
|
|
104
|
-
label: "Posts",
|
|
105
|
-
model: "Post",
|
|
106
|
-
permissions: { read: "posts.read" },
|
|
107
|
-
fields: {
|
|
108
|
-
id: { type: "id", list: true },
|
|
109
|
-
secret: { type: "text", list: false }
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
expect(visibleFields(resource, "list", ["posts.read"])).not.toHaveProperty("secret");
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
describe("resolveResourceForLocale", () => {
|
|
117
|
-
it("resolves labels for requested locale", () => {
|
|
118
|
-
const resource = defineResource({
|
|
119
|
-
name: "items",
|
|
120
|
-
label: { en: "Items", ru: "Элементы" },
|
|
121
|
-
model: "Item",
|
|
122
|
-
i18n: { defaultLocale: "en", locales: ["en", "ru"] },
|
|
123
|
-
permissions: { read: "items.read" },
|
|
124
|
-
fields: {
|
|
125
|
-
id: { type: "id", list: true },
|
|
126
|
-
title: { type: "text", list: true, label: { en: "Title", ru: "Название" } }
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
const ru = resolveResourceForLocale(resource, "ru");
|
|
130
|
-
expect(ru.label).toBe("Элементы");
|
|
131
|
-
expect(ru.fields.title?.label).toBe("Название");
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
describe("withSafeFields", () => {
|
|
136
|
-
it("strips list/detail for sensitive fields but keeps password fields configurable", () => {
|
|
137
|
-
const raw = {
|
|
138
|
-
name: "users",
|
|
139
|
-
label: "Users",
|
|
140
|
-
model: "User",
|
|
141
|
-
permissions: { read: "users.read" },
|
|
142
|
-
fields: {
|
|
143
|
-
id: { type: "id" },
|
|
144
|
-
password: { type: "password", create: true, edit: true }
|
|
145
|
-
}
|
|
146
|
-
} satisfies Parameters<typeof withSafeFields>[0];
|
|
147
|
-
const safe = withSafeFields(raw);
|
|
148
|
-
expect(safe.fields.password?.list).toBe(false);
|
|
149
|
-
expect(safe.fields.password?.detail).toBe(false);
|
|
150
|
-
});
|
|
151
|
-
});
|
|
@@ -1,344 +0,0 @@
|
|
|
1
|
-
export type FieldType =
|
|
2
|
-
| "id"
|
|
3
|
-
| "text"
|
|
4
|
-
| "textarea"
|
|
5
|
-
| "number"
|
|
6
|
-
| "boolean"
|
|
7
|
-
| "select"
|
|
8
|
-
| "multiselect"
|
|
9
|
-
| "datetime"
|
|
10
|
-
| "date"
|
|
11
|
-
| "relation"
|
|
12
|
-
| "image"
|
|
13
|
-
| "file"
|
|
14
|
-
| "richtext"
|
|
15
|
-
| "json"
|
|
16
|
-
| "password"
|
|
17
|
-
| "email"
|
|
18
|
-
| "url"
|
|
19
|
-
| "money"
|
|
20
|
-
| "slug"
|
|
21
|
-
| "color"
|
|
22
|
-
| "badge"
|
|
23
|
-
| "markdown"
|
|
24
|
-
| "code"
|
|
25
|
-
| "hidden"
|
|
26
|
-
| "computed";
|
|
27
|
-
|
|
28
|
-
export type PermissionMap = {
|
|
29
|
-
read?: string;
|
|
30
|
-
create?: string;
|
|
31
|
-
update?: string;
|
|
32
|
-
delete?: string;
|
|
33
|
-
[action: string]: string | undefined;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export type FieldPermission = {
|
|
37
|
-
read?: string;
|
|
38
|
-
create?: string;
|
|
39
|
-
update?: string;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/** Plain string or per-locale map (BCP-47 keys). */
|
|
43
|
-
export type LocalizedLabel = string | Record<string, string>;
|
|
44
|
-
|
|
45
|
-
export type ResourceI18nConfig = {
|
|
46
|
-
defaultLocale?: string;
|
|
47
|
-
locales?: readonly string[];
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export type ListScopeConfig =
|
|
51
|
-
| { type?: "none" }
|
|
52
|
-
| {
|
|
53
|
-
type: "userOwns";
|
|
54
|
-
field: string;
|
|
55
|
-
bypassPermissions?: readonly string[];
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export type ResourceSeoConfig = {
|
|
59
|
-
public?: boolean;
|
|
60
|
-
slugField?: string;
|
|
61
|
-
pathPattern?: string;
|
|
62
|
-
titleField?: string;
|
|
63
|
-
descriptionField?: string;
|
|
64
|
-
ogImageField?: string;
|
|
65
|
-
alternateSlugFields?: Record<string, string>;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export type ResourceField = {
|
|
69
|
-
type: FieldType;
|
|
70
|
-
label?: LocalizedLabel;
|
|
71
|
-
required?: boolean;
|
|
72
|
-
list?: boolean;
|
|
73
|
-
create?: boolean;
|
|
74
|
-
edit?: boolean;
|
|
75
|
-
detail?: boolean;
|
|
76
|
-
searchable?: boolean;
|
|
77
|
-
sortable?: boolean;
|
|
78
|
-
filterable?: boolean;
|
|
79
|
-
options?: readonly string[];
|
|
80
|
-
/** For `relation` fields: the name of the related resource (e.g. "categories"). */
|
|
81
|
-
resource?: string;
|
|
82
|
-
/** For `relation` fields: which field of the related record to display as label. Defaults to "name". */
|
|
83
|
-
displayField?: string;
|
|
84
|
-
from?: string;
|
|
85
|
-
permissions?: FieldPermission;
|
|
86
|
-
sensitive?: boolean;
|
|
87
|
-
defaultValue?: unknown;
|
|
88
|
-
/** Minimum value for `number`/`money` fields. */
|
|
89
|
-
min?: number;
|
|
90
|
-
/** Maximum value for `number`/`money` fields. */
|
|
91
|
-
max?: number;
|
|
92
|
-
/** Minimum character length for string fields. */
|
|
93
|
-
minLength?: number;
|
|
94
|
-
/** Maximum character length for string fields. */
|
|
95
|
-
maxLength?: number;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
export type ResourceActionContext = {
|
|
99
|
-
id: string;
|
|
100
|
-
prisma: unknown;
|
|
101
|
-
user: { id: string; email: string; permissions: string[] };
|
|
102
|
-
input?: unknown;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
export type ResourceAction = {
|
|
106
|
-
label: LocalizedLabel;
|
|
107
|
-
variant?: "default" | "primary" | "destructive";
|
|
108
|
-
confirm?: boolean;
|
|
109
|
-
permission: string;
|
|
110
|
-
handler?: (context: ResourceActionContext) => Promise<unknown>;
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
export type ResourceConfig = {
|
|
114
|
-
name: string;
|
|
115
|
-
label: LocalizedLabel;
|
|
116
|
-
model: string;
|
|
117
|
-
titleField?: string;
|
|
118
|
-
icon?: string;
|
|
119
|
-
permissions: PermissionMap;
|
|
120
|
-
fields: Record<string, ResourceField>;
|
|
121
|
-
actions?: Record<string, ResourceAction>;
|
|
122
|
-
i18n?: ResourceI18nConfig;
|
|
123
|
-
seo?: ResourceSeoConfig;
|
|
124
|
-
listScope?: ListScopeConfig;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
export const sensitiveFieldPatterns = [
|
|
128
|
-
"password",
|
|
129
|
-
"passwordHash",
|
|
130
|
-
"token",
|
|
131
|
-
"accessToken",
|
|
132
|
-
"refreshToken",
|
|
133
|
-
"secret",
|
|
134
|
-
"apiKey",
|
|
135
|
-
"privateKey",
|
|
136
|
-
"resetToken",
|
|
137
|
-
"verificationToken",
|
|
138
|
-
"otp",
|
|
139
|
-
"twoFactorSecret"
|
|
140
|
-
] as const;
|
|
141
|
-
|
|
142
|
-
export function defineResource<TFields extends Record<string, ResourceField>>(
|
|
143
|
-
config: Omit<ResourceConfig, "fields"> & { fields: TFields }
|
|
144
|
-
): ResourceConfig {
|
|
145
|
-
validateResource(config);
|
|
146
|
-
return withSafeFields(config);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export function isSensitiveField(name: string, field?: ResourceField): boolean {
|
|
150
|
-
if (field?.sensitive || field?.type === "password" || field?.type === "hidden") return true;
|
|
151
|
-
const lower = name.toLowerCase();
|
|
152
|
-
return sensitiveFieldPatterns.some((pattern) => lower.includes(pattern.toLowerCase()));
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export function withSafeFields<TFields extends Record<string, ResourceField>>(
|
|
156
|
-
config: Omit<ResourceConfig, "fields"> & { fields: TFields }
|
|
157
|
-
): ResourceConfig {
|
|
158
|
-
const fields = Object.fromEntries(
|
|
159
|
-
Object.entries(config.fields).map(([name, field]) => {
|
|
160
|
-
if (!isSensitiveField(name, field)) return [name, field];
|
|
161
|
-
return [
|
|
162
|
-
name,
|
|
163
|
-
{
|
|
164
|
-
...field,
|
|
165
|
-
list: false,
|
|
166
|
-
detail: false,
|
|
167
|
-
create: field.type === "password" ? field.create : false,
|
|
168
|
-
edit: field.type === "password" ? field.edit : false,
|
|
169
|
-
sensitive: true
|
|
170
|
-
}
|
|
171
|
-
];
|
|
172
|
-
})
|
|
173
|
-
);
|
|
174
|
-
|
|
175
|
-
return { ...config, fields };
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
export function validateResource(config: ResourceConfig): void {
|
|
179
|
-
if (!config.name || !/^[a-z][a-z0-9-]*$/.test(config.name)) {
|
|
180
|
-
throw new Error(`Invalid resource name "${config.name}". Use kebab-case.`);
|
|
181
|
-
}
|
|
182
|
-
if (!config.model || !/^[A-Za-z][A-Za-z0-9_]*$/.test(config.model)) {
|
|
183
|
-
throw new Error(`Invalid Prisma model name for resource "${config.name}".`);
|
|
184
|
-
}
|
|
185
|
-
if (!config.permissions.read) {
|
|
186
|
-
throw new Error(`Resource "${config.name}" must define permissions.read.`);
|
|
187
|
-
}
|
|
188
|
-
if (!Object.keys(config.fields).length) {
|
|
189
|
-
throw new Error(`Resource "${config.name}" must define at least one field.`);
|
|
190
|
-
}
|
|
191
|
-
const ls = config.listScope;
|
|
192
|
-
if (ls && "field" in ls && ls.type === "userOwns") {
|
|
193
|
-
if (!ls.field?.trim()) {
|
|
194
|
-
throw new Error(`Resource "${config.name}" listScope.userOwns requires a non-empty field.`);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
export function visibleFields(
|
|
200
|
-
resource: ResourceConfig,
|
|
201
|
-
mode: "list" | "create" | "edit" | "detail",
|
|
202
|
-
permissions: readonly string[]
|
|
203
|
-
): Record<string, ResourceField> {
|
|
204
|
-
return Object.fromEntries(
|
|
205
|
-
Object.entries(resource.fields).filter(([name, field]) => {
|
|
206
|
-
if (isSensitiveField(name, field)) return false;
|
|
207
|
-
if (field[mode] === false) return false;
|
|
208
|
-
const permissionKey = mode === "detail" || mode === "list" ? "read" : mode === "edit" ? "update" : "create";
|
|
209
|
-
const permission = field.permissions?.[permissionKey];
|
|
210
|
-
return permission ? permissions.includes(permission) : true;
|
|
211
|
-
})
|
|
212
|
-
);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
export function pickLocalizedLabel(label: LocalizedLabel | undefined, locale: string, fallbackLocale = "en"): string {
|
|
216
|
-
if (label == null || label === "") return "";
|
|
217
|
-
if (typeof label === "string") return label;
|
|
218
|
-
return label[locale] ?? label[fallbackLocale] ?? Object.values(label)[0] ?? "";
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
export function effectiveLocale(resource: ResourceConfig, requested: string | undefined): string {
|
|
222
|
-
const fb = resource.i18n?.defaultLocale ?? "en";
|
|
223
|
-
const locales = resource.i18n?.locales;
|
|
224
|
-
if (!requested) return fb;
|
|
225
|
-
if (!locales?.length) return requested;
|
|
226
|
-
return locales.includes(requested) ? requested : fb;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
export function resolveResourceForLocale(resource: ResourceConfig, locale: string | undefined): ResourceConfig {
|
|
230
|
-
const fb = resource.i18n?.defaultLocale ?? "en";
|
|
231
|
-
const loc = effectiveLocale(resource, locale);
|
|
232
|
-
const fields: Record<string, ResourceField> = Object.fromEntries(
|
|
233
|
-
Object.entries(resource.fields).map(([key, field]) => [
|
|
234
|
-
key,
|
|
235
|
-
{
|
|
236
|
-
...field,
|
|
237
|
-
label: pickLocalizedLabel(field.label, loc, fb) || field.label
|
|
238
|
-
}
|
|
239
|
-
])
|
|
240
|
-
);
|
|
241
|
-
|
|
242
|
-
const actions: Record<string, ResourceAction> | undefined = resource.actions
|
|
243
|
-
? Object.fromEntries(
|
|
244
|
-
Object.entries(resource.actions).map(([key, action]) => [
|
|
245
|
-
key,
|
|
246
|
-
{
|
|
247
|
-
...action,
|
|
248
|
-
label: pickLocalizedLabel(action.label, loc, fb) || action.label
|
|
249
|
-
}
|
|
250
|
-
])
|
|
251
|
-
)
|
|
252
|
-
: undefined;
|
|
253
|
-
|
|
254
|
-
return {
|
|
255
|
-
...resource,
|
|
256
|
-
label: pickLocalizedLabel(resource.label, loc, fb),
|
|
257
|
-
fields,
|
|
258
|
-
actions
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
export function shouldApplyListScope(resource: ResourceConfig, userPermissions: readonly string[]): boolean {
|
|
263
|
-
const ls = resource.listScope;
|
|
264
|
-
if (!ls || ls.type === "none" || !("field" in ls)) return false;
|
|
265
|
-
if (userPermissions.includes("*")) return false;
|
|
266
|
-
for (const p of ls.bypassPermissions ?? []) {
|
|
267
|
-
if (userPermissions.includes(p)) return false;
|
|
268
|
-
}
|
|
269
|
-
return true;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
export function listScopeWhereClause(resource: ResourceConfig, userId: string): Record<string, unknown> | undefined {
|
|
273
|
-
const ls = resource.listScope;
|
|
274
|
-
if (!ls || ls.type === "none" || !("field" in ls)) return undefined;
|
|
275
|
-
return { [ls.field]: userId };
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
export function mergeWhereClauses(...parts: (Record<string, unknown> | undefined)[]): Record<string, unknown> | undefined {
|
|
279
|
-
const clauses = parts.filter(Boolean) as Record<string, unknown>[];
|
|
280
|
-
if (!clauses.length) return undefined;
|
|
281
|
-
if (clauses.length === 1) return clauses[0];
|
|
282
|
-
return { AND: clauses };
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
export type SeoPagePayload = {
|
|
286
|
-
title: string;
|
|
287
|
-
description: string;
|
|
288
|
-
canonicalUrl: string;
|
|
289
|
-
openGraph: {
|
|
290
|
-
title: string;
|
|
291
|
-
description: string;
|
|
292
|
-
url: string;
|
|
293
|
-
type: string;
|
|
294
|
-
images?: { url: string }[];
|
|
295
|
-
};
|
|
296
|
-
alternates?: { languages?: Record<string, string> };
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
export function buildSeoPagePayload(opts: {
|
|
300
|
-
siteUrl: string;
|
|
301
|
-
basePath: string;
|
|
302
|
-
seo?: ResourceSeoConfig;
|
|
303
|
-
record: Record<string, unknown>;
|
|
304
|
-
resourceLabel: string;
|
|
305
|
-
}): SeoPagePayload {
|
|
306
|
-
const { siteUrl, basePath, seo, record, resourceLabel } = opts;
|
|
307
|
-
const titleField = seo?.titleField ?? "title";
|
|
308
|
-
const descField = seo?.descriptionField ?? "description";
|
|
309
|
-
const slugField = seo?.slugField ?? "slug";
|
|
310
|
-
const title = String(record[titleField] ?? resourceLabel);
|
|
311
|
-
const description = String(record[descField] ?? record["excerpt"] ?? `${resourceLabel} page`);
|
|
312
|
-
const slug = String(record[slugField] ?? record["id"]);
|
|
313
|
-
const path = (seo?.pathPattern ?? `${basePath}/:slug`).replace(":slug", encodeURIComponent(slug));
|
|
314
|
-
const canonicalUrl = new URL(path.startsWith("/") ? path : `/${path}`, siteUrl).toString();
|
|
315
|
-
|
|
316
|
-
const ogImageField = seo?.ogImageField;
|
|
317
|
-
const imageUrl =
|
|
318
|
-
ogImageField && record[ogImageField] ? String(record[ogImageField]) : undefined;
|
|
319
|
-
|
|
320
|
-
const languages: Record<string, string> = {};
|
|
321
|
-
if (seo?.alternateSlugFields) {
|
|
322
|
-
for (const [loc, field] of Object.entries(seo.alternateSlugFields)) {
|
|
323
|
-
const altSlug = record[field];
|
|
324
|
-
if (altSlug != null && String(altSlug)) {
|
|
325
|
-
const altPath = (seo.pathPattern ?? `${basePath}/:slug`).replace(":slug", encodeURIComponent(String(altSlug)));
|
|
326
|
-
languages[loc] = new URL(altPath.startsWith("/") ? altPath : `/${altPath}`, siteUrl).toString();
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
return {
|
|
332
|
-
title,
|
|
333
|
-
description,
|
|
334
|
-
canonicalUrl,
|
|
335
|
-
openGraph: {
|
|
336
|
-
title,
|
|
337
|
-
description,
|
|
338
|
-
url: canonicalUrl,
|
|
339
|
-
type: "article",
|
|
340
|
-
...(imageUrl ? { images: [{ url: imageUrl }] } : {})
|
|
341
|
-
},
|
|
342
|
-
...(Object.keys(languages).length ? { alternates: { languages } } : {})
|
|
343
|
-
};
|
|
344
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@openadminjs/storage",
|
|
3
|
-
"version": "0.1.0",
|
|
4
|
-
"type": "module",
|
|
5
|
-
"main": "src/index.ts",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"build": "tsc -p tsconfig.json",
|
|
8
|
-
"lint": "tsc -p tsconfig.json --noEmit",
|
|
9
|
-
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
10
|
-
"test": "vitest run"
|
|
11
|
-
},
|
|
12
|
-
"devDependencies": {
|
|
13
|
-
"typescript": "^5.7.2",
|
|
14
|
-
"vitest": "^2.1.8"
|
|
15
|
-
}
|
|
16
|
-
}
|