openadminjs 0.1.3 → 0.1.5
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 +17 -82
- package/dist/create-project.d.ts +34 -0
- package/dist/create-project.js +245 -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 +35 -24
- 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 -348
- 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/postcss.config.mjs +0 -6
- package/apps/admin/public/brand/apple-touch-icon.png +0 -0
- package/apps/admin/public/brand/favicon.svg +0 -1
- 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 +0 -37
- package/apps/admin/tsconfig.json +0 -23
- package/apps/admin/vitest.config.ts +0 -7
- package/apps/api/package.json +0 -56
- package/apps/api/plugins.manifest.example.json +0 -22
- 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 -1238
- 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 -253
- 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 -37
- 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 -37
- 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/hello.plugin.ts +0 -19
- package/apps/api/src/plugins/bundled/registry.ts +0 -7
- package/apps/api/src/plugins/manifest-path.ts +0 -35
- package/apps/api/src/plugins/manifest.schema.test.ts +0 -28
- package/apps/api/src/plugins/manifest.schema.ts +0 -38
- package/apps/api/src/plugins/plugin-loader.ts +0 -109
- 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 -86
- 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/README.md +0 -12
- package/apps/web/app/globals.css +0 -12
- package/apps/web/app/layout.tsx +0 -18
- package/apps/web/app/page.tsx +0 -27
- package/apps/web/app/posts/[slug]/page.tsx +0 -38
- package/apps/web/app/posts/page.tsx +0 -20
- package/apps/web/app/robots.txt/route.ts +0 -9
- package/apps/web/app/sitemap.xml/route.ts +0 -20
- package/apps/web/components/public-fields.tsx +0 -22
- 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/next.config.mjs +0 -5
- 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/tailwind.config.ts +0 -21
- 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 -227
- package/packages/cli/src/index.test.ts +0 -8
- package/packages/cli/src/index.ts +0 -122
- package/packages/cli/src/resource-slug.test.ts +0 -10
- package/packages/cli/src/resource-slug.ts +0 -4
- package/packages/cli/template/.env.example +0 -4
- package/packages/cli/template/README.md +0 -13
- 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/lib/openadmin-client.ts +0 -71
- package/packages/cli/template/apps/web/lib/seo.ts +0 -42
- package/packages/cli/template/apps/web/next-env.d.ts +0 -2
- package/packages/cli/template/apps/web/next.config.mjs +0 -5
- package/packages/cli/template/apps/web/package.json +0 -29
- 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/template/package.json +0 -19
- package/packages/cli/template/pnpm-workspace.yaml +0 -3
- 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 -70
- 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 -4
- 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 -44
- package/packages/plugin-sdk/src/index.ts +0 -37
- 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 -1449
- package/site/index.html +0 -357
- package/tsconfig.base.json +0 -23
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
// ──────────────────────────────────────────────────────────────────────────────
|
|
2
|
-
// @openadminjs/mail — email abstraction layer with template engine
|
|
3
|
-
//
|
|
4
|
-
// Usage (with SMTP):
|
|
5
|
-
// const mailer = new SmtpMailDriver({ host: "smtp.gmail.com", port: 587, ... });
|
|
6
|
-
//
|
|
7
|
-
// Usage (with mock for dev/tests):
|
|
8
|
-
// const mailer = new MockMailDriver();
|
|
9
|
-
// ──────────────────────────────────────────────────────────────────────────────
|
|
10
|
-
|
|
11
|
-
export type MailAddress = string | { name: string; address: string };
|
|
12
|
-
|
|
13
|
-
export type MailAttachment = {
|
|
14
|
-
filename: string;
|
|
15
|
-
content: string | Buffer;
|
|
16
|
-
contentType?: string;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export type MailMessage = {
|
|
20
|
-
to: MailAddress | MailAddress[];
|
|
21
|
-
from?: MailAddress;
|
|
22
|
-
replyTo?: MailAddress;
|
|
23
|
-
subject: string;
|
|
24
|
-
/** Plain text body */
|
|
25
|
-
text?: string;
|
|
26
|
-
/** HTML body — use renderTemplate() to build from a template */
|
|
27
|
-
html?: string;
|
|
28
|
-
/** Template name (resolved by the registered template engine) */
|
|
29
|
-
template?: string;
|
|
30
|
-
/** Data passed to the template engine */
|
|
31
|
-
data?: Record<string, unknown>;
|
|
32
|
-
attachments?: MailAttachment[];
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export type SentInfo = {
|
|
36
|
-
messageId: string;
|
|
37
|
-
accepted: MailAddress[];
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export interface MailDriver {
|
|
41
|
-
send(message: MailMessage): Promise<SentInfo>;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// ──────────────────────────────────────────────
|
|
45
|
-
// Minimal built-in template engine
|
|
46
|
-
// ──────────────────────────────────────────────
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Renders a template string with `{{variable}}` placeholders.
|
|
50
|
-
* Supports nested keys via dot notation: `{{user.name}}`.
|
|
51
|
-
*/
|
|
52
|
-
export function renderTemplate(template: string, data: Record<string, unknown> = {}): string {
|
|
53
|
-
return template.replace(/\{\{([\w.]+)}}/g, (_, key: string) => {
|
|
54
|
-
const value = key.split(".").reduce<unknown>((obj, k) => {
|
|
55
|
-
if (obj != null && typeof obj === "object") return (obj as Record<string, unknown>)[k];
|
|
56
|
-
return undefined;
|
|
57
|
-
}, data);
|
|
58
|
-
return value != null ? String(value) : "";
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// ──────────────────────────────────────────────
|
|
63
|
-
// Built-in HTML email templates
|
|
64
|
-
// ──────────────────────────────────────────────
|
|
65
|
-
|
|
66
|
-
const BASE_LAYOUT = `<!DOCTYPE html>
|
|
67
|
-
<html lang="en">
|
|
68
|
-
<head>
|
|
69
|
-
<meta charset="UTF-8" />
|
|
70
|
-
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
71
|
-
<title>{{subject}}</title>
|
|
72
|
-
<style>
|
|
73
|
-
body{margin:0;padding:0;background:#f1f5f9;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif}
|
|
74
|
-
.wrap{max-width:560px;margin:40px auto;background:#fff;border-radius:16px;overflow:hidden;box-shadow:0 4px 24px rgba(0,0,0,.06)}
|
|
75
|
-
.header{background:linear-gradient(135deg,#2454ff,#0ea5a4);padding:32px 40px}
|
|
76
|
-
.header h1{color:#fff;margin:0;font-size:22px;font-weight:700}
|
|
77
|
-
.body{padding:32px 40px}
|
|
78
|
-
.body p{color:#475569;line-height:1.7;margin:0 0 16px}
|
|
79
|
-
.btn{display:inline-block;padding:12px 28px;background:#2454ff;color:#fff;border-radius:10px;text-decoration:none;font-weight:600;font-size:14px}
|
|
80
|
-
.footer{padding:20px 40px;background:#f8fafc;text-align:center}
|
|
81
|
-
.footer p{color:#94a3b8;font-size:12px;margin:0}
|
|
82
|
-
.divider{height:1px;background:#e2e8f0;margin:20px 0}
|
|
83
|
-
.highlight{background:#eef3ff;border-radius:8px;padding:16px;font-family:monospace;word-break:break-all;color:#2454ff;font-size:14px}
|
|
84
|
-
</style>
|
|
85
|
-
</head>
|
|
86
|
-
<body>
|
|
87
|
-
<div class="wrap">
|
|
88
|
-
<div class="header"><h1>{{appName}}</h1></div>
|
|
89
|
-
<div class="body">{{bodyContent}}</div>
|
|
90
|
-
<div class="footer"><p>© {{year}} {{appName}}. This email was sent automatically.</p></div>
|
|
91
|
-
</div>
|
|
92
|
-
</body>
|
|
93
|
-
</html>`;
|
|
94
|
-
|
|
95
|
-
export const EMAIL_TEMPLATES: Record<string, string> = {
|
|
96
|
-
welcome: BASE_LAYOUT.replace(
|
|
97
|
-
"{{bodyContent}}",
|
|
98
|
-
`<p>Hi <strong>{{name}}</strong>,</p>
|
|
99
|
-
<p>Welcome to <strong>{{appName}}</strong>! Your account has been created successfully.</p>
|
|
100
|
-
<p><a href="{{loginUrl}}" class="btn">Sign in to your account</a></p>
|
|
101
|
-
<div class="divider"></div>
|
|
102
|
-
<p>If you didn't create this account, you can safely ignore this email.</p>`
|
|
103
|
-
),
|
|
104
|
-
|
|
105
|
-
"password-reset": BASE_LAYOUT.replace(
|
|
106
|
-
"{{bodyContent}}",
|
|
107
|
-
`<p>Hi {{name}},</p>
|
|
108
|
-
<p>You requested a password reset. Click the button below to set a new password:</p>
|
|
109
|
-
<p><a href="{{resetUrl}}" class="btn">Reset password</a></p>
|
|
110
|
-
<div class="divider"></div>
|
|
111
|
-
<p>This link expires in <strong>{{expiresIn}}</strong>. If you didn't request a reset, ignore this email.</p>`
|
|
112
|
-
),
|
|
113
|
-
|
|
114
|
-
"email-verification": BASE_LAYOUT.replace(
|
|
115
|
-
"{{bodyContent}}",
|
|
116
|
-
`<p>Hi {{name}},</p>
|
|
117
|
-
<p>Please verify your email address to complete your registration:</p>
|
|
118
|
-
<p><a href="{{verifyUrl}}" class="btn">Verify email address</a></p>
|
|
119
|
-
<div class="divider"></div>
|
|
120
|
-
<p>This link expires in <strong>{{expiresIn}}</strong>.</p>`
|
|
121
|
-
),
|
|
122
|
-
|
|
123
|
-
"order-confirmation": BASE_LAYOUT.replace(
|
|
124
|
-
"{{bodyContent}}",
|
|
125
|
-
`<p>Hi {{customerName}},</p>
|
|
126
|
-
<p>Thank you for your order! Here's a summary:</p>
|
|
127
|
-
<div class="highlight">Order #{{orderId}} — {{currency}} {{totalDisplay}}</div>
|
|
128
|
-
<p style="margin-top:16px">You can check your order status at any time:</p>
|
|
129
|
-
<p><a href="{{orderUrl}}" class="btn">View order</a></p>`
|
|
130
|
-
),
|
|
131
|
-
|
|
132
|
-
"order-refunded": BASE_LAYOUT.replace(
|
|
133
|
-
"{{bodyContent}}",
|
|
134
|
-
`<p>Hi {{customerName}},</p>
|
|
135
|
-
<p>Your refund for order <strong>#{{orderId}}</strong> has been processed.</p>
|
|
136
|
-
<div class="highlight">Refund amount: {{currency}} {{totalDisplay}}</div>
|
|
137
|
-
<p>The funds will be returned to your original payment method within 5–10 business days.</p>`
|
|
138
|
-
)
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
// ──────────────────────────────────────────────
|
|
142
|
-
// Mock driver (dev / testing)
|
|
143
|
-
// ──────────────────────────────────────────────
|
|
144
|
-
|
|
145
|
-
export type SentMailRecord = MailMessage & { sentAt: Date };
|
|
146
|
-
|
|
147
|
-
export class MockMailDriver implements MailDriver {
|
|
148
|
-
readonly sent: SentMailRecord[] = [];
|
|
149
|
-
|
|
150
|
-
async send(message: MailMessage): Promise<SentInfo> {
|
|
151
|
-
const resolved = this.resolve(message);
|
|
152
|
-
this.sent.push({ ...resolved, sentAt: new Date() });
|
|
153
|
-
return {
|
|
154
|
-
messageId: `mock_${Date.now()}@localhost`,
|
|
155
|
-
accepted: Array.isArray(message.to) ? message.to : [message.to]
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
private resolve(message: MailMessage): MailMessage {
|
|
160
|
-
if (message.template && EMAIL_TEMPLATES[message.template]) {
|
|
161
|
-
const data = { year: new Date().getFullYear(), ...(message.data ?? {}) };
|
|
162
|
-
return { ...message, html: renderTemplate(EMAIL_TEMPLATES[message.template]!, data) };
|
|
163
|
-
}
|
|
164
|
-
return message;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
last(): SentMailRecord | undefined {
|
|
168
|
-
return this.sent[this.sent.length - 1];
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
clear() {
|
|
172
|
-
this.sent.length = 0;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// ──────────────────────────────────────────────
|
|
177
|
-
// SMTP driver (nodemailer-based)
|
|
178
|
-
// ──────────────────────────────────────────────
|
|
179
|
-
|
|
180
|
-
export type SmtpConfig = {
|
|
181
|
-
host: string;
|
|
182
|
-
port: number;
|
|
183
|
-
secure?: boolean;
|
|
184
|
-
auth?: { user: string; pass: string };
|
|
185
|
-
from?: MailAddress;
|
|
186
|
-
appName?: string;
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
export class SmtpMailDriver implements MailDriver {
|
|
190
|
-
private readonly config: SmtpConfig;
|
|
191
|
-
// Transporter is created lazily so nodemailer is not required unless used
|
|
192
|
-
private transporter: unknown = null;
|
|
193
|
-
|
|
194
|
-
constructor(config: SmtpConfig) {
|
|
195
|
-
this.config = config;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
private async getTransporter() {
|
|
199
|
-
if (!this.transporter) {
|
|
200
|
-
const nodemailer = (await import("nodemailer")) as typeof import("nodemailer");
|
|
201
|
-
this.transporter = nodemailer.createTransport({
|
|
202
|
-
host: this.config.host,
|
|
203
|
-
port: this.config.port,
|
|
204
|
-
secure: this.config.secure ?? this.config.port === 465,
|
|
205
|
-
auth: this.config.auth
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
return this.transporter as Awaited<ReturnType<typeof import("nodemailer").createTransport>>;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
async send(message: MailMessage): Promise<SentInfo> {
|
|
212
|
-
const transporter = await this.getTransporter();
|
|
213
|
-
const resolved = this.resolve(message);
|
|
214
|
-
const info = await transporter.sendMail({
|
|
215
|
-
from: resolved.from ?? this.config.from ?? `noreply@${this.config.host}`,
|
|
216
|
-
to: Array.isArray(resolved.to) ? resolved.to.join(", ") : resolved.to,
|
|
217
|
-
replyTo: resolved.replyTo as string | undefined,
|
|
218
|
-
subject: resolved.subject,
|
|
219
|
-
text: resolved.text,
|
|
220
|
-
html: resolved.html,
|
|
221
|
-
attachments: resolved.attachments
|
|
222
|
-
});
|
|
223
|
-
return { messageId: info.messageId as string, accepted: info.accepted as MailAddress[] };
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
private resolve(message: MailMessage): MailMessage {
|
|
227
|
-
if (message.template && EMAIL_TEMPLATES[message.template]) {
|
|
228
|
-
const data: Record<string, unknown> = {
|
|
229
|
-
appName: this.config.appName ?? "OpenAdminJS",
|
|
230
|
-
year: new Date().getFullYear(),
|
|
231
|
-
...(message.data ?? {})
|
|
232
|
-
};
|
|
233
|
-
return { ...message, html: renderTemplate(EMAIL_TEMPLATES[message.template]!, data) };
|
|
234
|
-
}
|
|
235
|
-
return message;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// ──────────────────────────────────────────────
|
|
240
|
-
// Factory
|
|
241
|
-
// ──────────────────────────────────────────────
|
|
242
|
-
|
|
243
|
-
export function createMailDriver(config?: SmtpConfig): MailDriver {
|
|
244
|
-
if (config?.host) return new SmtpMailDriver(config);
|
|
245
|
-
return new MockMailDriver();
|
|
246
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@openadminjs/notifications",
|
|
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
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import type { NotificationMessage } from "./index";
|
|
3
|
-
|
|
4
|
-
describe("NotificationMessage", () => {
|
|
5
|
-
it("accepts optional body", () => {
|
|
6
|
-
const msg: NotificationMessage = { userId: "u1", title: "Hello" };
|
|
7
|
-
expect(msg.body).toBeUndefined();
|
|
8
|
-
});
|
|
9
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@openadminjs/payments",
|
|
3
|
-
"version": "0.1.0",
|
|
4
|
-
"type": "module",
|
|
5
|
-
"main": "src/index.ts",
|
|
6
|
-
"types": "src/index.ts",
|
|
7
|
-
"description": "Payment provider abstractions for OpenAdminJS (Stripe, Mock, extensible)",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"build": "tsc -p tsconfig.json"
|
|
10
|
-
},
|
|
11
|
-
"devDependencies": {
|
|
12
|
-
"typescript": "^5.7.2",
|
|
13
|
-
"stripe": "^17.0.0"
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
// ──────────────────────────────────────────────────────────────────────────────
|
|
2
|
-
// @openadminjs/payments — payment provider abstraction layer
|
|
3
|
-
//
|
|
4
|
-
// Usage:
|
|
5
|
-
// import { MockPaymentProvider, type PaymentProvider } from "@openadminjs/payments";
|
|
6
|
-
// const provider = process.env.STRIPE_SECRET_KEY
|
|
7
|
-
// ? new StripePaymentProvider(process.env.STRIPE_SECRET_KEY)
|
|
8
|
-
// : new MockPaymentProvider();
|
|
9
|
-
// ──────────────────────────────────────────────────────────────────────────────
|
|
10
|
-
|
|
11
|
-
export type Currency = string; // ISO 4217, e.g. "USD", "EUR"
|
|
12
|
-
|
|
13
|
-
export type OrderLineItem = {
|
|
14
|
-
name: string;
|
|
15
|
-
description?: string;
|
|
16
|
-
/** Unit price in smallest currency unit (cents for USD) */
|
|
17
|
-
unitAmount: number;
|
|
18
|
-
quantity: number;
|
|
19
|
-
productId?: string;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export type CheckoutInput = {
|
|
23
|
-
/** Your internal order ID */
|
|
24
|
-
orderId: string;
|
|
25
|
-
lineItems: OrderLineItem[];
|
|
26
|
-
currency: Currency;
|
|
27
|
-
/** Where to redirect after successful payment */
|
|
28
|
-
successUrl: string;
|
|
29
|
-
/** Where to redirect on cancel */
|
|
30
|
-
cancelUrl: string;
|
|
31
|
-
/** Customer email (optional, pre-fills checkout form) */
|
|
32
|
-
customerEmail?: string;
|
|
33
|
-
metadata?: Record<string, string>;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export type CheckoutResult = {
|
|
37
|
-
/** URL to redirect the user to for payment */
|
|
38
|
-
checkoutUrl: string;
|
|
39
|
-
/** Provider-side session / intent ID */
|
|
40
|
-
providerSessionId: string;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export type WebhookEventType =
|
|
44
|
-
| "payment.succeeded"
|
|
45
|
-
| "payment.failed"
|
|
46
|
-
| "payment.refunded"
|
|
47
|
-
| "checkout.expired"
|
|
48
|
-
| "unknown";
|
|
49
|
-
|
|
50
|
-
export type WebhookEvent = {
|
|
51
|
-
type: WebhookEventType;
|
|
52
|
-
orderId: string | null;
|
|
53
|
-
providerEventId: string;
|
|
54
|
-
amount?: number;
|
|
55
|
-
currency?: Currency;
|
|
56
|
-
raw: unknown;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export type RefundInput = {
|
|
60
|
-
providerTransactionId: string;
|
|
61
|
-
/** Amount in cents. If omitted → full refund. */
|
|
62
|
-
amount?: number;
|
|
63
|
-
reason?: string;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
export type RefundResult = {
|
|
67
|
-
providerRefundId: string;
|
|
68
|
-
amount: number;
|
|
69
|
-
status: "succeeded" | "pending" | "failed";
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
// ──────────────────────────────────────────────
|
|
73
|
-
// Provider interface
|
|
74
|
-
// ──────────────────────────────────────────────
|
|
75
|
-
|
|
76
|
-
export interface PaymentProvider {
|
|
77
|
-
readonly name: string;
|
|
78
|
-
|
|
79
|
-
/** Create a hosted checkout session and return a redirect URL. */
|
|
80
|
-
createCheckout(input: CheckoutInput): Promise<CheckoutResult>;
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Verify and parse an inbound webhook payload.
|
|
84
|
-
* @param rawBody - raw Buffer/string as received by the HTTP server
|
|
85
|
-
* @param signature - value of the provider-specific signature header
|
|
86
|
-
*/
|
|
87
|
-
verifyWebhook(rawBody: Buffer | string, signature: string): Promise<WebhookEvent>;
|
|
88
|
-
|
|
89
|
-
/** Issue a full or partial refund. */
|
|
90
|
-
refund(input: RefundInput): Promise<RefundResult>;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// ──────────────────────────────────────────────
|
|
94
|
-
// Mock provider (dev / testing)
|
|
95
|
-
// ──────────────────────────────────────────────
|
|
96
|
-
|
|
97
|
-
export class MockPaymentProvider implements PaymentProvider {
|
|
98
|
-
readonly name = "mock";
|
|
99
|
-
|
|
100
|
-
async createCheckout(input: CheckoutInput): Promise<CheckoutResult> {
|
|
101
|
-
const sessionId = `mock_sess_${Date.now()}`;
|
|
102
|
-
const params = new URLSearchParams({ session: sessionId, orderId: input.orderId });
|
|
103
|
-
return {
|
|
104
|
-
checkoutUrl: `${input.successUrl}?${params.toString()}`,
|
|
105
|
-
providerSessionId: sessionId
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
async verifyWebhook(rawBody: Buffer | string, _signature: string): Promise<WebhookEvent> {
|
|
110
|
-
try {
|
|
111
|
-
const body = JSON.parse(typeof rawBody === "string" ? rawBody : rawBody.toString("utf-8")) as {
|
|
112
|
-
type?: string;
|
|
113
|
-
orderId?: string;
|
|
114
|
-
id?: string;
|
|
115
|
-
amount?: number;
|
|
116
|
-
currency?: string;
|
|
117
|
-
};
|
|
118
|
-
return {
|
|
119
|
-
type: (body.type as WebhookEventType) ?? "payment.succeeded",
|
|
120
|
-
orderId: body.orderId ?? null,
|
|
121
|
-
providerEventId: body.id ?? `mock_evt_${Date.now()}`,
|
|
122
|
-
amount: body.amount,
|
|
123
|
-
currency: body.currency,
|
|
124
|
-
raw: body
|
|
125
|
-
};
|
|
126
|
-
} catch {
|
|
127
|
-
return {
|
|
128
|
-
type: "unknown",
|
|
129
|
-
orderId: null,
|
|
130
|
-
providerEventId: `mock_evt_${Date.now()}`,
|
|
131
|
-
raw: rawBody
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
async refund(input: RefundInput): Promise<RefundResult> {
|
|
137
|
-
return {
|
|
138
|
-
providerRefundId: `mock_re_${Date.now()}`,
|
|
139
|
-
amount: input.amount ?? 0,
|
|
140
|
-
status: "succeeded"
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// ──────────────────────────────────────────────
|
|
146
|
-
// Stripe provider
|
|
147
|
-
// ──────────────────────────────────────────────
|
|
148
|
-
|
|
149
|
-
export class StripePaymentProvider implements PaymentProvider {
|
|
150
|
-
readonly name = "stripe";
|
|
151
|
-
|
|
152
|
-
// We import Stripe lazily so the package doesn't crash when stripe is not installed
|
|
153
|
-
private stripeInstance: unknown = null;
|
|
154
|
-
|
|
155
|
-
constructor(private readonly secretKey: string, private readonly webhookSecret?: string) {}
|
|
156
|
-
|
|
157
|
-
private async getStripe(): Promise<import("stripe").default> {
|
|
158
|
-
if (!this.stripeInstance) {
|
|
159
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
160
|
-
const { default: Stripe } = (await import("stripe")) as { default: typeof import("stripe").default };
|
|
161
|
-
this.stripeInstance = new Stripe(this.secretKey, { apiVersion: "2025-02-24.acacia" });
|
|
162
|
-
}
|
|
163
|
-
return this.stripeInstance as import("stripe").default;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
async createCheckout(input: CheckoutInput): Promise<CheckoutResult> {
|
|
167
|
-
const stripe = await this.getStripe();
|
|
168
|
-
const session = await stripe.checkout.sessions.create({
|
|
169
|
-
payment_method_types: ["card"],
|
|
170
|
-
mode: "payment",
|
|
171
|
-
line_items: input.lineItems.map((item) => ({
|
|
172
|
-
quantity: item.quantity,
|
|
173
|
-
price_data: {
|
|
174
|
-
currency: input.currency.toLowerCase(),
|
|
175
|
-
unit_amount: item.unitAmount,
|
|
176
|
-
product_data: {
|
|
177
|
-
name: item.name,
|
|
178
|
-
description: item.description
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
})),
|
|
182
|
-
customer_email: input.customerEmail,
|
|
183
|
-
success_url: input.successUrl,
|
|
184
|
-
cancel_url: input.cancelUrl,
|
|
185
|
-
metadata: { orderId: input.orderId, ...input.metadata }
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
return {
|
|
189
|
-
checkoutUrl: session.url ?? input.cancelUrl,
|
|
190
|
-
providerSessionId: session.id
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
async verifyWebhook(rawBody: Buffer | string, signature: string): Promise<WebhookEvent> {
|
|
195
|
-
if (!this.webhookSecret) throw new Error("STRIPE_WEBHOOK_SECRET is not set");
|
|
196
|
-
const stripe = await this.getStripe();
|
|
197
|
-
const event = stripe.webhooks.constructEvent(rawBody, signature, this.webhookSecret);
|
|
198
|
-
|
|
199
|
-
const typeMap: Record<string, WebhookEventType> = {
|
|
200
|
-
"checkout.session.completed": "payment.succeeded",
|
|
201
|
-
"checkout.session.expired": "checkout.expired",
|
|
202
|
-
"payment_intent.payment_failed": "payment.failed",
|
|
203
|
-
"charge.refunded": "payment.refunded"
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
const session = event.data.object as unknown as Record<string, unknown>;
|
|
207
|
-
const orderId = (session.metadata as Record<string, string> | null)?.orderId ?? null;
|
|
208
|
-
const amount = typeof session.amount_total === "number" ? session.amount_total : undefined;
|
|
209
|
-
const currency = typeof session.currency === "string" ? session.currency.toUpperCase() : undefined;
|
|
210
|
-
|
|
211
|
-
return {
|
|
212
|
-
type: typeMap[event.type] ?? "unknown",
|
|
213
|
-
orderId,
|
|
214
|
-
providerEventId: event.id,
|
|
215
|
-
amount,
|
|
216
|
-
currency,
|
|
217
|
-
raw: event
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
async refund(input: RefundInput): Promise<RefundResult> {
|
|
222
|
-
const stripe = await this.getStripe();
|
|
223
|
-
const params: {
|
|
224
|
-
payment_intent: string;
|
|
225
|
-
reason: "duplicate" | "fraudulent" | "requested_by_customer";
|
|
226
|
-
amount?: number;
|
|
227
|
-
} = {
|
|
228
|
-
payment_intent: input.providerTransactionId,
|
|
229
|
-
reason: (input.reason as "duplicate" | "fraudulent" | "requested_by_customer") ?? "requested_by_customer"
|
|
230
|
-
};
|
|
231
|
-
if (input.amount) params.amount = input.amount;
|
|
232
|
-
const refund = await stripe.refunds.create(params as never);
|
|
233
|
-
return {
|
|
234
|
-
providerRefundId: refund.id,
|
|
235
|
-
amount: refund.amount,
|
|
236
|
-
status: refund.status === "succeeded" ? "succeeded" : refund.status === "pending" ? "pending" : "failed"
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// ──────────────────────────────────────────────
|
|
242
|
-
// Factory helper
|
|
243
|
-
// ──────────────────────────────────────────────
|
|
244
|
-
|
|
245
|
-
export type ProviderName = "stripe" | "mock";
|
|
246
|
-
|
|
247
|
-
export function createPaymentProvider(
|
|
248
|
-
provider: ProviderName = "mock",
|
|
249
|
-
config: { stripeSecretKey?: string; stripeWebhookSecret?: string } = {}
|
|
250
|
-
): PaymentProvider {
|
|
251
|
-
if (provider === "stripe") {
|
|
252
|
-
if (!config.stripeSecretKey) throw new Error("STRIPE_SECRET_KEY is required for Stripe provider");
|
|
253
|
-
return new StripePaymentProvider(config.stripeSecretKey, config.stripeWebhookSecret);
|
|
254
|
-
}
|
|
255
|
-
return new MockPaymentProvider();
|
|
256
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@openadminjs/permissions",
|
|
3
|
-
"version": "0.1.0",
|
|
4
|
-
"type": "module",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"build": "tsc -p tsconfig.json",
|
|
9
|
-
"lint": "tsc -p tsconfig.json --noEmit",
|
|
10
|
-
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
11
|
-
"test": "vitest run"
|
|
12
|
-
},
|
|
13
|
-
"devDependencies": {
|
|
14
|
-
"typescript": "^5.7.2",
|
|
15
|
-
"vitest": "^2.1.8"
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
export const DEFAULT_AUTH_REALM = "admin";
|
|
2
|
-
export function realmOf(blueprint) {
|
|
3
|
-
return blueprint.realm ?? DEFAULT_AUTH_REALM;
|
|
4
|
-
}
|
|
5
|
-
export function roleMatrixKey(realm, roleName) {
|
|
6
|
-
return `${realm}:${roleName}`;
|
|
7
|
-
}
|
|
8
|
-
function collectRolePermissions(blueprints, realm, roleName, wildcardSlugs, stack, memo) {
|
|
9
|
-
const memoKey = roleMatrixKey(realm, roleName);
|
|
10
|
-
if (memo.has(memoKey))
|
|
11
|
-
return new Set(memo.get(memoKey));
|
|
12
|
-
if (stack.has(memoKey)) {
|
|
13
|
-
throw new Error(`Circular role inheritance involving "${realm}:${roleName}"`);
|
|
14
|
-
}
|
|
15
|
-
const bp = blueprints.find((b) => b.name === roleName && realmOf(b) === realm);
|
|
16
|
-
if (!bp) {
|
|
17
|
-
throw new Error(`Unknown role blueprint: "${roleName}" in realm "${realm}"`);
|
|
18
|
-
}
|
|
19
|
-
stack.add(memoKey);
|
|
20
|
-
const out = new Set();
|
|
21
|
-
for (const parent of bp.inherits ?? []) {
|
|
22
|
-
for (const p of collectRolePermissions(blueprints, realm, parent, wildcardSlugs, stack, memo)) {
|
|
23
|
-
out.add(p);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
for (const p of bp.permissions ?? []) {
|
|
27
|
-
if (p === "*") {
|
|
28
|
-
out.add("*");
|
|
29
|
-
for (const s of wildcardSlugs)
|
|
30
|
-
out.add(s);
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
out.add(p);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
stack.delete(memoKey);
|
|
37
|
-
memo.set(memoKey, out);
|
|
38
|
-
return out;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Resolves inherits + wildcard expansion within one realm.
|
|
42
|
-
* When `slugsByRealm` is set, `"*"` expands only that realm's slug list (so admin superusers do not silently gain storefront-only slugs unless you assign them).
|
|
43
|
-
*/
|
|
44
|
-
export function expandRolePermissions(blueprints, realm, roleName, allPermissionSlugs, slugsByRealm) {
|
|
45
|
-
const wildcardSlugs = slugsByRealm?.[realm] ?? allPermissionSlugs;
|
|
46
|
-
return collectRolePermissions(blueprints, realm, roleName, wildcardSlugs, new Set(), new Map());
|
|
47
|
-
}
|
|
48
|
-
/** Every blueprint gets a frozen permission array keyed as `realm:roleName`. */
|
|
49
|
-
export function materializeAllRoles(blueprints, allPermissionSlugs, slugsByRealm) {
|
|
50
|
-
const map = new Map();
|
|
51
|
-
for (const bp of blueprints) {
|
|
52
|
-
const r = realmOf(bp);
|
|
53
|
-
const set = expandRolePermissions(blueprints, r, bp.name, allPermissionSlugs, slugsByRealm);
|
|
54
|
-
map.set(roleMatrixKey(r, bp.name), [...set].sort());
|
|
55
|
-
}
|
|
56
|
-
return map;
|
|
57
|
-
}
|