openadminjs 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +9 -0
- package/.github/FUNDING.yml +3 -0
- package/.github/ISSUE_TEMPLATE/bug_report.yml +10 -0
- package/.github/ISSUE_TEMPLATE/feature_request.yml +10 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +9 -0
- package/.github/dependabot.yml +10 -0
- package/.github/workflows/ci.yml +26 -0
- package/CHANGELOG.md +5 -0
- package/CODE_OF_CONDUCT.md +3 -0
- package/CONTRIBUTING.md +11 -0
- package/LICENSE +21 -0
- package/README.md +175 -0
- package/ROADMAP.md +7 -0
- package/SECURITY.md +11 -0
- package/apps/admin/app/api/auth/login/route.ts +51 -0
- package/apps/admin/app/api/auth/logout/route.ts +11 -0
- package/apps/admin/app/api/auth/refresh/route.ts +46 -0
- package/apps/admin/app/api-tokens/page.tsx +253 -0
- package/apps/admin/app/audit-logs/page.tsx +5 -0
- package/apps/admin/app/dashboard/page.tsx +392 -0
- package/apps/admin/app/files/page.tsx +5 -0
- package/apps/admin/app/globals.css +206 -0
- package/apps/admin/app/jobs/page.tsx +19 -0
- package/apps/admin/app/layout.tsx +57 -0
- package/apps/admin/app/login/page.test.tsx +18 -0
- package/apps/admin/app/login/page.tsx +161 -0
- package/apps/admin/app/login/safe-next-param.ts +4 -0
- package/apps/admin/app/notifications/page.tsx +146 -0
- package/apps/admin/app/page.tsx +5 -0
- package/apps/admin/app/plugins/page.tsx +348 -0
- package/apps/admin/app/profile/page.tsx +116 -0
- package/apps/admin/app/resources/[resource]/[id]/edit/page.tsx +45 -0
- package/apps/admin/app/resources/[resource]/[id]/page.tsx +449 -0
- package/apps/admin/app/resources/[resource]/create/page.tsx +34 -0
- package/apps/admin/app/resources/[resource]/page.tsx +100 -0
- package/apps/admin/app/settings/page.tsx +233 -0
- package/apps/admin/components/ai-assistant-widget.tsx +684 -0
- package/apps/admin/components/app-shell.tsx +305 -0
- package/apps/admin/components/auth-guard.test.tsx +55 -0
- package/apps/admin/components/auth-guard.tsx +39 -0
- package/apps/admin/components/jobs-panel.tsx +103 -0
- package/apps/admin/components/logo.tsx +30 -0
- package/apps/admin/components/resource-form.tsx +349 -0
- package/apps/admin/components/resource-table.tsx +277 -0
- package/apps/admin/lib/ai-events.ts +23 -0
- package/apps/admin/lib/api.test.ts +118 -0
- package/apps/admin/lib/api.ts +135 -0
- package/apps/admin/lib/auth-flow.e2e.test.ts +79 -0
- package/apps/admin/lib/brand.ts +14 -0
- package/apps/admin/lib/locale.ts +49 -0
- package/apps/admin/lib/tokens.ts +93 -0
- package/apps/admin/middleware.ts +58 -0
- package/apps/admin/next-env.d.ts +6 -0
- package/apps/admin/next.config.mjs +7 -0
- package/apps/admin/package.json +44 -0
- package/apps/admin/postcss.config.mjs +6 -0
- package/apps/admin/public/brand/apple-touch-icon.png +0 -0
- package/apps/admin/public/brand/favicon.svg +1 -0
- package/apps/admin/public/brand/og-image.png +0 -0
- package/apps/admin/public/brand/openadminjs-icon-new.png +0 -0
- package/apps/admin/public/brand/openadminjs-logo-monochrome.png +0 -0
- package/apps/admin/public/brand/openadminjs-logo-new.png +0 -0
- package/apps/admin/tailwind.config.ts +37 -0
- package/apps/admin/tsconfig.json +23 -0
- package/apps/admin/vitest.config.ts +7 -0
- package/apps/api/package.json +56 -0
- package/apps/api/plugins.manifest.example.json +22 -0
- package/apps/api/plugins.manifest.json +4 -0
- package/apps/api/src/access/catalog.ts +112 -0
- package/apps/api/src/access/derive-permissions.test.ts +26 -0
- package/apps/api/src/access/derive-permissions.ts +36 -0
- package/apps/api/src/access/public-catalog.ts +28 -0
- package/apps/api/src/admin/admin-ai.controller.ts +125 -0
- package/apps/api/src/admin/admin-ai.events.ts +23 -0
- package/apps/api/src/admin/admin-ai.service.ts +1238 -0
- package/apps/api/src/admin/admin-analytics.service.ts +164 -0
- package/apps/api/src/admin/admin-plugins.controller.ts +32 -0
- package/apps/api/src/admin/admin-plugins.service.ts +253 -0
- package/apps/api/src/admin/admin-resource.service.test.ts +118 -0
- package/apps/api/src/admin/admin-resource.service.ts +375 -0
- package/apps/api/src/admin/admin.controller.ts +72 -0
- package/apps/api/src/admin/admin.module.ts +30 -0
- package/apps/api/src/admin/dto/plugins.dto.ts +37 -0
- package/apps/api/src/admin/validate-resource-payload.test.ts +44 -0
- package/apps/api/src/admin/validate-resource-payload.ts +103 -0
- package/apps/api/src/app.module.ts +37 -0
- package/apps/api/src/auth/auth.controller.ts +70 -0
- package/apps/api/src/auth/auth.dto.ts +49 -0
- package/apps/api/src/auth/auth.module.ts +30 -0
- package/apps/api/src/auth/auth.service.test.ts +75 -0
- package/apps/api/src/auth/auth.service.ts +231 -0
- package/apps/api/src/common/auth-realm.decorator.ts +6 -0
- package/apps/api/src/common/auth.guard.test.ts +61 -0
- package/apps/api/src/common/auth.guard.ts +78 -0
- package/apps/api/src/common/casl-ability.factory.test.ts +33 -0
- package/apps/api/src/common/casl-ability.factory.ts +41 -0
- package/apps/api/src/common/current-user.decorator.ts +6 -0
- package/apps/api/src/common/permission.decorator.ts +7 -0
- package/apps/api/src/common/permissions.guard.ts +31 -0
- package/apps/api/src/common/prisma.service.ts +13 -0
- package/apps/api/src/health/health.controller.ts +25 -0
- package/apps/api/src/mail/mail.module.ts +9 -0
- package/apps/api/src/mail/mail.service.ts +115 -0
- package/apps/api/src/main.ts +37 -0
- package/apps/api/src/plugins/bootstrap.ts +4 -0
- package/apps/api/src/plugins/bundled/hello.plugin.ts +19 -0
- package/apps/api/src/plugins/bundled/registry.ts +7 -0
- package/apps/api/src/plugins/manifest-path.ts +35 -0
- package/apps/api/src/plugins/manifest.schema.test.ts +28 -0
- package/apps/api/src/plugins/manifest.schema.ts +38 -0
- package/apps/api/src/plugins/plugin-loader.ts +109 -0
- package/apps/api/src/queue/queue.controller.ts +28 -0
- package/apps/api/src/queue/queue.module.ts +23 -0
- package/apps/api/src/queue/queue.processor.ts +47 -0
- package/apps/api/src/queue/queue.service.ts +50 -0
- package/apps/api/src/resources/categories.resource.ts +21 -0
- package/apps/api/src/resources/commerce.resource.ts +157 -0
- package/apps/api/src/resources/operations.resource.ts +111 -0
- package/apps/api/src/resources/posts.resource.ts +88 -0
- package/apps/api/src/resources/registry.ts +27 -0
- package/apps/api/src/resources/resource-hooks.install.ts +18 -0
- package/apps/api/src/resources/resource-hooks.registry.test.ts +72 -0
- package/apps/api/src/resources/resource-hooks.registry.ts +66 -0
- package/apps/api/src/resources/resource-hooks.runner.ts +86 -0
- package/apps/api/src/resources/system.resource.ts +51 -0
- package/apps/api/src/resources/users.resource.ts +19 -0
- package/apps/api/src/store/payment/payment.controller.ts +98 -0
- package/apps/api/src/store/payment/payment.module.ts +14 -0
- package/apps/api/src/store/payment/payment.provider.ts +38 -0
- package/apps/api/src/store/payment/payment.service.ts +235 -0
- package/apps/api/src/store/store.controller.ts +26 -0
- package/apps/api/src/store/store.module.ts +12 -0
- package/apps/api/src/test-setup.ts +1 -0
- package/apps/api/tsconfig.json +11 -0
- package/apps/api/vitest.config.ts +21 -0
- package/apps/web/README.md +12 -0
- package/apps/web/app/globals.css +12 -0
- package/apps/web/app/layout.tsx +18 -0
- package/apps/web/app/page.tsx +27 -0
- package/apps/web/app/posts/[slug]/page.tsx +38 -0
- package/apps/web/app/posts/page.tsx +20 -0
- package/apps/web/app/robots.txt/route.ts +9 -0
- package/apps/web/app/sitemap.xml/route.ts +20 -0
- package/apps/web/components/public-fields.tsx +22 -0
- package/apps/web/lib/openadmin-client.ts +82 -0
- package/apps/web/lib/seo.test.ts +41 -0
- package/apps/web/lib/seo.ts +53 -0
- package/apps/web/next-env.d.ts +6 -0
- package/apps/web/next.config.mjs +5 -0
- package/apps/web/package.json +30 -0
- package/apps/web/postcss.config.mjs +6 -0
- package/apps/web/public/brand/apple-touch-icon.png +0 -0
- package/apps/web/public/brand/favicon.svg +1 -0
- package/apps/web/public/brand/og-image.png +0 -0
- package/apps/web/public/brand/openadminjs-icon-new.png +0 -0
- package/apps/web/public/brand/openadminjs-logo-monochrome.png +0 -0
- package/apps/web/public/brand/openadminjs-logo-new.png +0 -0
- package/apps/web/tailwind.config.ts +21 -0
- package/apps/web/test/next-stub.ts +7 -0
- package/apps/web/tsconfig.json +23 -0
- package/apps/web/vitest.config.ts +19 -0
- package/docs/content/security.md +7 -0
- package/eslint.config.mjs +11 -0
- package/examples/README.md +80 -0
- package/examples/basic-admin/README.md +24 -0
- package/examples/basic-admin/package.json +17 -0
- package/examples/basic-admin/prisma/models.fragment.prisma +12 -0
- package/examples/basic-admin/src/index.test.ts +8 -0
- package/examples/basic-admin/src/index.ts +5 -0
- package/examples/basic-admin/src/resources/lead.resource.ts +30 -0
- package/examples/basic-admin/tsconfig.json +7 -0
- package/examples/basic-admin/vitest.config.ts +16 -0
- package/examples/blog-admin/README.md +18 -0
- package/examples/blog-admin/package.json +17 -0
- package/examples/blog-admin/prisma/models.fragment.prisma +30 -0
- package/examples/blog-admin/src/index.test.ts +8 -0
- package/examples/blog-admin/src/index.ts +5 -0
- package/examples/blog-admin/src/resources/authors.resource.ts +21 -0
- package/examples/blog-admin/src/resources/tags.resource.ts +20 -0
- package/examples/blog-admin/tsconfig.json +7 -0
- package/examples/blog-admin/vitest.config.ts +16 -0
- package/examples/crm-admin/README.md +17 -0
- package/examples/crm-admin/package.json +17 -0
- package/examples/crm-admin/prisma/models.fragment.prisma +50 -0
- package/examples/crm-admin/src/index.test.ts +9 -0
- package/examples/crm-admin/src/index.ts +7 -0
- package/examples/crm-admin/src/resources/activities.resource.ts +29 -0
- package/examples/crm-admin/src/resources/companies.resource.ts +21 -0
- package/examples/crm-admin/src/resources/contacts.resource.ts +24 -0
- package/examples/crm-admin/src/resources/deals.resource.ts +30 -0
- package/examples/crm-admin/tsconfig.json +7 -0
- package/examples/crm-admin/vitest.config.ts +16 -0
- package/examples/ecommerce-admin/README.md +17 -0
- package/examples/ecommerce-admin/package.json +17 -0
- package/examples/ecommerce-admin/prisma/models.fragment.prisma +43 -0
- package/examples/ecommerce-admin/src/index.test.ts +8 -0
- package/examples/ecommerce-admin/src/index.ts +7 -0
- package/examples/ecommerce-admin/src/resources/customers.resource.ts +21 -0
- package/examples/ecommerce-admin/src/resources/order-items.resource.ts +22 -0
- package/examples/ecommerce-admin/src/resources/orders.resource.ts +27 -0
- package/examples/ecommerce-admin/src/resources/products.resource.ts +23 -0
- package/examples/ecommerce-admin/tsconfig.json +7 -0
- package/examples/ecommerce-admin/vitest.config.ts +16 -0
- package/examples/marketplace-admin/README.md +17 -0
- package/examples/marketplace-admin/package.json +17 -0
- package/examples/marketplace-admin/prisma/models.fragment.prisma +32 -0
- package/examples/marketplace-admin/src/index.test.ts +8 -0
- package/examples/marketplace-admin/src/index.ts +6 -0
- package/examples/marketplace-admin/src/resources/listings.resource.ts +29 -0
- package/examples/marketplace-admin/src/resources/payouts.resource.ts +28 -0
- package/examples/marketplace-admin/src/resources/sellers.resource.ts +28 -0
- package/examples/marketplace-admin/tsconfig.json +7 -0
- package/examples/marketplace-admin/vitest.config.ts +16 -0
- package/examples/support-admin/README.md +18 -0
- package/examples/support-admin/package.json +17 -0
- package/examples/support-admin/prisma/models.fragment.prisma +20 -0
- package/examples/support-admin/src/index.test.ts +8 -0
- package/examples/support-admin/src/index.ts +5 -0
- package/examples/support-admin/src/resources/ticket-messages.resource.ts +22 -0
- package/examples/support-admin/src/resources/tickets.resource.ts +35 -0
- package/examples/support-admin/tsconfig.json +7 -0
- package/examples/support-admin/vitest.config.ts +16 -0
- package/package.json +33 -0
- package/packages/auth/package.json +17 -0
- package/packages/auth/src/index.test.ts +10 -0
- package/packages/auth/src/index.ts +17 -0
- package/packages/auth/tsconfig.json +8 -0
- package/packages/brand/apps/admin/public/brand/apple-touch-icon.png +0 -0
- package/packages/brand/apps/admin/public/brand/favicon.svg +1 -0
- package/packages/brand/apps/admin/public/brand/og-image.png +0 -0
- package/packages/brand/apps/admin/public/brand/openadminjs-icon-new.png +0 -0
- package/packages/brand/apps/admin/public/brand/openadminjs-logo-monochrome.png +0 -0
- package/packages/brand/apps/admin/public/brand/openadminjs-logo-new.png +0 -0
- package/packages/brand/apps/web/public/brand/apple-touch-icon.png +0 -0
- package/packages/brand/apps/web/public/brand/favicon.svg +1 -0
- package/packages/brand/apps/web/public/brand/og-image.png +0 -0
- package/packages/brand/apps/web/public/brand/openadminjs-icon-new.png +0 -0
- package/packages/brand/apps/web/public/brand/openadminjs-logo-monochrome.png +0 -0
- package/packages/brand/apps/web/public/brand/openadminjs-logo-new.png +0 -0
- package/packages/brand/package.json +19 -0
- package/packages/brand/site/assets/brand/favicon.svg +1 -0
- package/packages/brand/site/assets/brand/og-image.svg +1 -0
- package/packages/brand/site/assets/brand/openadminjs-icon.svg +1 -0
- package/packages/brand/site/assets/brand/openadminjs-logo-dark.svg +1 -0
- package/packages/brand/site/assets/brand/openadminjs-logo-horizontal.svg +1 -0
- package/packages/brand/site/assets/brand/openadminjs-logo-monochrome.svg +1 -0
- package/packages/brand/site/assets/brand/openadminjs-logo.svg +1 -0
- package/packages/brand/src/generate-assets.mjs +182 -0
- package/packages/brand/src/index.test.ts +9 -0
- package/packages/brand/src/index.ts +7 -0
- package/packages/brand/tsconfig.json +7 -0
- package/packages/cli/package.json +44 -0
- package/packages/cli/src/create-project.ts +227 -0
- package/packages/cli/src/index.test.ts +8 -0
- package/packages/cli/src/index.ts +90 -0
- package/packages/cli/src/resource-slug.test.ts +10 -0
- package/packages/cli/src/resource-slug.ts +4 -0
- package/packages/cli/template/.env.example +4 -0
- package/packages/cli/template/README.md +13 -0
- package/packages/cli/template/apps/web/README.md +12 -0
- package/packages/cli/template/apps/web/app/globals.css +12 -0
- package/packages/cli/template/apps/web/app/layout.tsx +18 -0
- package/packages/cli/template/apps/web/app/page.tsx +27 -0
- package/packages/cli/template/apps/web/app/posts/[slug]/page.tsx +38 -0
- package/packages/cli/template/apps/web/app/posts/page.tsx +20 -0
- package/packages/cli/template/apps/web/app/robots.txt/route.ts +9 -0
- package/packages/cli/template/apps/web/app/sitemap.xml/route.ts +20 -0
- package/packages/cli/template/apps/web/components/public-fields.tsx +22 -0
- package/packages/cli/template/apps/web/lib/openadmin-client.ts +71 -0
- package/packages/cli/template/apps/web/lib/seo.ts +42 -0
- package/packages/cli/template/apps/web/next-env.d.ts +2 -0
- package/packages/cli/template/apps/web/next.config.mjs +5 -0
- package/packages/cli/template/apps/web/package.json +29 -0
- package/packages/cli/template/apps/web/postcss.config.mjs +6 -0
- package/packages/cli/template/apps/web/public/brand/apple-touch-icon.png +0 -0
- package/packages/cli/template/apps/web/public/brand/favicon.svg +1 -0
- package/packages/cli/template/apps/web/public/brand/og-image.png +0 -0
- package/packages/cli/template/apps/web/public/brand/openadminjs-icon-new.png +0 -0
- package/packages/cli/template/apps/web/public/brand/openadminjs-logo-monochrome.png +0 -0
- package/packages/cli/template/apps/web/public/brand/openadminjs-logo-new.png +0 -0
- package/packages/cli/template/apps/web/tailwind.config.ts +21 -0
- package/packages/cli/template/apps/web/tsconfig.json +23 -0
- package/packages/cli/template/package.json +19 -0
- package/packages/cli/template/pnpm-workspace.yaml +3 -0
- package/packages/cli/tsconfig.json +10 -0
- package/packages/core/package.json +20 -0
- package/packages/core/src/index.js +1 -0
- package/packages/core/src/index.test.ts +27 -0
- package/packages/core/src/index.ts +61 -0
- package/packages/core/tsconfig.json +8 -0
- package/packages/create-openadminjs/package.json +25 -0
- package/packages/create-openadminjs/src/index.ts +70 -0
- package/packages/create-openadminjs/src/package-name.test.ts +13 -0
- package/packages/create-openadminjs/src/package-name.ts +8 -0
- package/packages/create-openadminjs/src/render-files.test.ts +26 -0
- package/packages/create-openadminjs/src/render-files.ts +21 -0
- package/packages/create-openadminjs/template/.env.example +4 -0
- package/packages/create-openadminjs/template/README.md +13 -0
- package/packages/create-openadminjs/template/apps/web/README.md +12 -0
- package/packages/create-openadminjs/template/apps/web/app/globals.css +12 -0
- package/packages/create-openadminjs/template/apps/web/app/layout.tsx +18 -0
- package/packages/create-openadminjs/template/apps/web/app/page.tsx +27 -0
- package/packages/create-openadminjs/template/apps/web/app/posts/[slug]/page.tsx +38 -0
- package/packages/create-openadminjs/template/apps/web/app/posts/page.tsx +20 -0
- package/packages/create-openadminjs/template/apps/web/app/robots.txt/route.ts +9 -0
- package/packages/create-openadminjs/template/apps/web/app/sitemap.xml/route.ts +20 -0
- package/packages/create-openadminjs/template/apps/web/components/public-fields.tsx +22 -0
- package/packages/create-openadminjs/template/apps/web/lib/openadmin-client.ts +71 -0
- package/packages/create-openadminjs/template/apps/web/lib/seo.ts +42 -0
- package/packages/create-openadminjs/template/apps/web/next-env.d.ts +2 -0
- package/packages/create-openadminjs/template/apps/web/next.config.mjs +5 -0
- package/packages/create-openadminjs/template/apps/web/package.json +29 -0
- package/packages/create-openadminjs/template/apps/web/postcss.config.mjs +6 -0
- package/packages/create-openadminjs/template/apps/web/public/brand/apple-touch-icon.png +0 -0
- package/packages/create-openadminjs/template/apps/web/public/brand/favicon.svg +1 -0
- package/packages/create-openadminjs/template/apps/web/public/brand/og-image.png +0 -0
- package/packages/create-openadminjs/template/apps/web/public/brand/openadminjs-icon-new.png +0 -0
- package/packages/create-openadminjs/template/apps/web/public/brand/openadminjs-logo-monochrome.png +0 -0
- package/packages/create-openadminjs/template/apps/web/public/brand/openadminjs-logo-new.png +0 -0
- package/packages/create-openadminjs/template/apps/web/tailwind.config.ts +21 -0
- package/packages/create-openadminjs/template/apps/web/tsconfig.json +23 -0
- package/packages/create-openadminjs/template/package.json +19 -0
- package/packages/create-openadminjs/template/pnpm-workspace.yaml +3 -0
- package/packages/create-openadminjs/tsconfig.json +10 -0
- package/packages/mail/package.json +18 -0
- package/packages/mail/src/index.test.ts +23 -0
- package/packages/mail/src/index.ts +246 -0
- package/packages/mail/tsconfig.json +5 -0
- package/packages/notifications/package.json +16 -0
- package/packages/notifications/src/index.test.ts +9 -0
- package/packages/notifications/src/index.ts +5 -0
- package/packages/notifications/tsconfig.json +5 -0
- package/packages/payments/package.json +15 -0
- package/packages/payments/src/index.ts +256 -0
- package/packages/payments/tsconfig.json +9 -0
- package/packages/permissions/package.json +17 -0
- package/packages/permissions/src/blueprints.js +57 -0
- package/packages/permissions/src/blueprints.test.ts +62 -0
- package/packages/permissions/src/blueprints.ts +89 -0
- package/packages/permissions/src/index.js +11 -0
- package/packages/permissions/src/index.test.ts +34 -0
- package/packages/permissions/src/index.ts +22 -0
- package/packages/permissions/tsconfig.json +8 -0
- package/packages/plugin-sdk/package.json +26 -0
- package/packages/plugin-sdk/src/hooks.ts +44 -0
- package/packages/plugin-sdk/src/index.ts +37 -0
- package/packages/plugin-sdk/src/sdk.test.ts +13 -0
- package/packages/plugin-sdk/tsconfig.json +8 -0
- package/packages/plugin-sdk/vitest.config.ts +5 -0
- package/packages/queue/package.json +16 -0
- package/packages/queue/src/index.test.ts +12 -0
- package/packages/queue/src/index.ts +6 -0
- package/packages/queue/tsconfig.json +5 -0
- package/packages/resource/package.json +17 -0
- package/packages/resource/src/index.js +177 -0
- package/packages/resource/src/index.test.ts +151 -0
- package/packages/resource/src/index.ts +344 -0
- package/packages/resource/tsconfig.json +8 -0
- package/packages/storage/package.json +16 -0
- package/packages/storage/src/index.test.ts +10 -0
- package/packages/storage/src/index.ts +23 -0
- package/packages/storage/tsconfig.json +5 -0
- package/pnpm-workspace.yaml +4 -0
- package/prisma/migrations/20260505151751_baseline_init_all_tables/migration.sql +371 -0
- package/prisma/migrations/migration_lock.toml +3 -0
- package/prisma/schema.prisma +291 -0
- package/prisma/seed.ts +210 -0
- package/scripts/check-static-site.mjs +17 -0
- package/scripts/e2e-smoke.mjs +17 -0
- package/scripts/make-executable.mjs +4 -0
- package/site/.nojekyll +0 -0
- package/site/assets/brand/apple-touch-icon.png +0 -0
- package/site/assets/brand/favicon.svg +1 -0
- package/site/assets/brand/og-image.png +0 -0
- package/site/assets/brand/openadminjs-icon-new.png +0 -0
- package/site/assets/brand/openadminjs-logo-monochrome.png +0 -0
- package/site/assets/brand/openadminjs-logo-new.png +0 -0
- package/site/assets/css/styles.css +1521 -0
- package/site/assets/js/main.js +193 -0
- package/site/assets/partners/arcbyte.svg +11 -0
- package/site/assets/partners/gridstack.svg +8 -0
- package/site/assets/partners/nebula.svg +12 -0
- package/site/assets/partners/orbitlab.svg +7 -0
- package/site/assets/partners/pulseforge.svg +11 -0
- package/site/assets/partners/vertex.svg +6 -0
- package/site/docs.html +1452 -0
- package/site/index.html +357 -0
- package/tsconfig.base.json +23 -0
|
@@ -0,0 +1,151 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,344 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { defaultFileValidation } from "./index";
|
|
3
|
+
|
|
4
|
+
describe("defaultFileValidation", () => {
|
|
5
|
+
it("defines sensible defaults", () => {
|
|
6
|
+
expect(defaultFileValidation.maxSizeBytes).toBe(10 * 1024 * 1024);
|
|
7
|
+
expect(defaultFileValidation.mimeTypes).toContain("image/png");
|
|
8
|
+
expect(defaultFileValidation.extensions).toContain(".pdf");
|
|
9
|
+
});
|
|
10
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type FileValidation = {
|
|
2
|
+
maxSizeBytes: number;
|
|
3
|
+
mimeTypes: string[];
|
|
4
|
+
extensions: string[];
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type StoredFile = {
|
|
8
|
+
filename: string;
|
|
9
|
+
path: string;
|
|
10
|
+
mimeType: string;
|
|
11
|
+
size: number;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export interface StorageDriver {
|
|
15
|
+
put(file: Buffer, meta: StoredFile): Promise<StoredFile>;
|
|
16
|
+
delete(path: string): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const defaultFileValidation: FileValidation = {
|
|
20
|
+
maxSizeBytes: 10 * 1024 * 1024,
|
|
21
|
+
mimeTypes: ["image/png", "image/jpeg", "image/webp", "application/pdf", "text/plain"],
|
|
22
|
+
extensions: [".png", ".jpg", ".jpeg", ".webp", ".pdf", ".txt"]
|
|
23
|
+
};
|