@open-mercato/core 0.4.8-develop-28cee031d6 → 0.4.8-develop-84f3678a58
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/agentic/standalone-guide.md +235 -0
- package/dist/generated/entities/customer_role/index.js +27 -0
- package/dist/generated/entities/customer_role/index.js.map +7 -0
- package/dist/generated/entities/customer_role_acl/index.js +19 -0
- package/dist/generated/entities/customer_role_acl/index.js.map +7 -0
- package/dist/generated/entities/customer_user/index.js +37 -0
- package/dist/generated/entities/customer_user/index.js.map +7 -0
- package/dist/generated/entities/customer_user_acl/index.js +19 -0
- package/dist/generated/entities/customer_user_acl/index.js.map +7 -0
- package/dist/generated/entities/customer_user_email_verification/index.js +17 -0
- package/dist/generated/entities/customer_user_email_verification/index.js.map +7 -0
- package/dist/generated/entities/customer_user_invitation/index.js +33 -0
- package/dist/generated/entities/customer_user_invitation/index.js.map +7 -0
- package/dist/generated/entities/customer_user_password_reset/index.js +15 -0
- package/dist/generated/entities/customer_user_password_reset/index.js.map +7 -0
- package/dist/generated/entities/customer_user_role/index.js +13 -0
- package/dist/generated/entities/customer_user_role/index.js.map +7 -0
- package/dist/generated/entities/customer_user_session/index.js +21 -0
- package/dist/generated/entities/customer_user_session/index.js.map +7 -0
- package/dist/generated/entities/organization/index.js +2 -0
- package/dist/generated/entities/organization/index.js.map +2 -2
- package/dist/generated/entities.ids.generated.js +14 -1
- package/dist/generated/entities.ids.generated.js.map +2 -2
- package/dist/generated/entity-fields-registry.js +18 -0
- package/dist/generated/entity-fields-registry.js.map +2 -2
- package/dist/modules/auth/services/rbacService.js +3 -9
- package/dist/modules/auth/services/rbacService.js.map +2 -2
- package/dist/modules/customer_accounts/acl.js +12 -0
- package/dist/modules/customer_accounts/acl.js.map +7 -0
- package/dist/modules/customer_accounts/api/admin/roles/[id]/acl.js +87 -0
- package/dist/modules/customer_accounts/api/admin/roles/[id]/acl.js.map +7 -0
- package/dist/modules/customer_accounts/api/admin/roles/[id].js +216 -0
- package/dist/modules/customer_accounts/api/admin/roles/[id].js.map +7 -0
- package/dist/modules/customer_accounts/api/admin/roles.js +189 -0
- package/dist/modules/customer_accounts/api/admin/roles.js.map +7 -0
- package/dist/modules/customer_accounts/api/admin/users/[id]/reset-password.js +69 -0
- package/dist/modules/customer_accounts/api/admin/users/[id]/reset-password.js.map +7 -0
- package/dist/modules/customer_accounts/api/admin/users/[id]/verify-email.js +64 -0
- package/dist/modules/customer_accounts/api/admin/users/[id]/verify-email.js.map +7 -0
- package/dist/modules/customer_accounts/api/admin/users/[id].js +253 -0
- package/dist/modules/customer_accounts/api/admin/users/[id].js.map +7 -0
- package/dist/modules/customer_accounts/api/admin/users-invite.js +78 -0
- package/dist/modules/customer_accounts/api/admin/users-invite.js.map +7 -0
- package/dist/modules/customer_accounts/api/admin/users.js +251 -0
- package/dist/modules/customer_accounts/api/admin/users.js.map +7 -0
- package/dist/modules/customer_accounts/api/email/verify.js +59 -0
- package/dist/modules/customer_accounts/api/email/verify.js.map +7 -0
- package/dist/modules/customer_accounts/api/interceptors.js +5 -0
- package/dist/modules/customer_accounts/api/interceptors.js.map +7 -0
- package/dist/modules/customer_accounts/api/invitations/accept.js +114 -0
- package/dist/modules/customer_accounts/api/invitations/accept.js.map +7 -0
- package/dist/modules/customer_accounts/api/login.js +143 -0
- package/dist/modules/customer_accounts/api/login.js.map +7 -0
- package/dist/modules/customer_accounts/api/magic-link/request.js +78 -0
- package/dist/modules/customer_accounts/api/magic-link/request.js.map +7 -0
- package/dist/modules/customer_accounts/api/magic-link/verify.js +114 -0
- package/dist/modules/customer_accounts/api/magic-link/verify.js.map +7 -0
- package/dist/modules/customer_accounts/api/password/reset-confirm.js +59 -0
- package/dist/modules/customer_accounts/api/password/reset-confirm.js.map +7 -0
- package/dist/modules/customer_accounts/api/password/reset-request.js +77 -0
- package/dist/modules/customer_accounts/api/password/reset-request.js.map +7 -0
- package/dist/modules/customer_accounts/api/portal/events/stream.js +163 -0
- package/dist/modules/customer_accounts/api/portal/events/stream.js.map +7 -0
- package/dist/modules/customer_accounts/api/portal/feature-check.js +57 -0
- package/dist/modules/customer_accounts/api/portal/feature-check.js.map +7 -0
- package/dist/modules/customer_accounts/api/portal/logout.js +64 -0
- package/dist/modules/customer_accounts/api/portal/logout.js.map +7 -0
- package/dist/modules/customer_accounts/api/portal/notifications/[id]/dismiss.js +49 -0
- package/dist/modules/customer_accounts/api/portal/notifications/[id]/dismiss.js.map +7 -0
- package/dist/modules/customer_accounts/api/portal/notifications/[id]/read.js +49 -0
- package/dist/modules/customer_accounts/api/portal/notifications/[id]/read.js.map +7 -0
- package/dist/modules/customer_accounts/api/portal/notifications/mark-all-read.js +46 -0
- package/dist/modules/customer_accounts/api/portal/notifications/mark-all-read.js.map +7 -0
- package/dist/modules/customer_accounts/api/portal/notifications/unread-count.js +42 -0
- package/dist/modules/customer_accounts/api/portal/notifications/unread-count.js.map +7 -0
- package/dist/modules/customer_accounts/api/portal/notifications.js +105 -0
- package/dist/modules/customer_accounts/api/portal/notifications.js.map +7 -0
- package/dist/modules/customer_accounts/api/portal/password-change.js +57 -0
- package/dist/modules/customer_accounts/api/portal/password-change.js.map +7 -0
- package/dist/modules/customer_accounts/api/portal/profile.js +135 -0
- package/dist/modules/customer_accounts/api/portal/profile.js.map +7 -0
- package/dist/modules/customer_accounts/api/portal/sessions/[id].js +62 -0
- package/dist/modules/customer_accounts/api/portal/sessions/[id].js.map +7 -0
- package/dist/modules/customer_accounts/api/portal/sessions-refresh.js +75 -0
- package/dist/modules/customer_accounts/api/portal/sessions-refresh.js.map +7 -0
- package/dist/modules/customer_accounts/api/portal/sessions.js +77 -0
- package/dist/modules/customer_accounts/api/portal/sessions.js.map +7 -0
- package/dist/modules/customer_accounts/api/portal/users/[id]/roles.js +90 -0
- package/dist/modules/customer_accounts/api/portal/users/[id]/roles.js.map +7 -0
- package/dist/modules/customer_accounts/api/portal/users/[id].js +71 -0
- package/dist/modules/customer_accounts/api/portal/users/[id].js.map +7 -0
- package/dist/modules/customer_accounts/api/portal/users-invite.js +92 -0
- package/dist/modules/customer_accounts/api/portal/users-invite.js.map +7 -0
- package/dist/modules/customer_accounts/api/portal/users.js +79 -0
- package/dist/modules/customer_accounts/api/portal/users.js.map +7 -0
- package/dist/modules/customer_accounts/api/signup.js +121 -0
- package/dist/modules/customer_accounts/api/signup.js.map +7 -0
- package/dist/modules/customer_accounts/backend/customer_accounts/[id]/page.js +491 -0
- package/dist/modules/customer_accounts/backend/customer_accounts/[id]/page.js.map +7 -0
- package/dist/modules/customer_accounts/backend/customer_accounts/[id]/page.meta.js +15 -0
- package/dist/modules/customer_accounts/backend/customer_accounts/[id]/page.meta.js.map +7 -0
- package/dist/modules/customer_accounts/backend/customer_accounts/roles/[id]/page.js +343 -0
- package/dist/modules/customer_accounts/backend/customer_accounts/roles/[id]/page.js.map +7 -0
- package/dist/modules/customer_accounts/backend/customer_accounts/roles/[id]/page.meta.js +16 -0
- package/dist/modules/customer_accounts/backend/customer_accounts/roles/[id]/page.meta.js.map +7 -0
- package/dist/modules/customer_accounts/backend/customer_accounts/roles/create/page.js +180 -0
- package/dist/modules/customer_accounts/backend/customer_accounts/roles/create/page.js.map +7 -0
- package/dist/modules/customer_accounts/backend/customer_accounts/roles/create/page.meta.js +16 -0
- package/dist/modules/customer_accounts/backend/customer_accounts/roles/create/page.meta.js.map +7 -0
- package/dist/modules/customer_accounts/backend/customer_accounts/roles/page.js +176 -0
- package/dist/modules/customer_accounts/backend/customer_accounts/roles/page.js.map +7 -0
- package/dist/modules/customer_accounts/backend/customer_accounts/roles/page.meta.js +33 -0
- package/dist/modules/customer_accounts/backend/customer_accounts/roles/page.meta.js.map +7 -0
- package/dist/modules/customer_accounts/backend/page.js +466 -0
- package/dist/modules/customer_accounts/backend/page.js.map +7 -0
- package/dist/modules/customer_accounts/backend/page.meta.js +35 -0
- package/dist/modules/customer_accounts/backend/page.meta.js.map +7 -0
- package/dist/modules/customer_accounts/ce.js +26 -0
- package/dist/modules/customer_accounts/ce.js.map +7 -0
- package/dist/modules/customer_accounts/data/enrichers.js +85 -0
- package/dist/modules/customer_accounts/data/enrichers.js.map +7 -0
- package/dist/modules/customer_accounts/data/entities.js +377 -0
- package/dist/modules/customer_accounts/data/entities.js.map +7 -0
- package/dist/modules/customer_accounts/data/extensions.js +8 -0
- package/dist/modules/customer_accounts/data/extensions.js.map +7 -0
- package/dist/modules/customer_accounts/data/validators.js +111 -0
- package/dist/modules/customer_accounts/data/validators.js.map +7 -0
- package/dist/modules/customer_accounts/di.js +17 -0
- package/dist/modules/customer_accounts/di.js.map +7 -0
- package/dist/modules/customer_accounts/events.js +28 -0
- package/dist/modules/customer_accounts/events.js.map +7 -0
- package/dist/modules/customer_accounts/index.js +15 -0
- package/dist/modules/customer_accounts/index.js.map +7 -0
- package/dist/modules/customer_accounts/lib/customerAuth.js +71 -0
- package/dist/modules/customer_accounts/lib/customerAuth.js.map +7 -0
- package/dist/modules/customer_accounts/lib/customerAuthServer.js +29 -0
- package/dist/modules/customer_accounts/lib/customerAuthServer.js.map +7 -0
- package/dist/modules/customer_accounts/lib/rateLimiter.js +63 -0
- package/dist/modules/customer_accounts/lib/rateLimiter.js.map +7 -0
- package/dist/modules/customer_accounts/lib/tokenGenerator.js +12 -0
- package/dist/modules/customer_accounts/lib/tokenGenerator.js.map +7 -0
- package/dist/modules/customer_accounts/migrations/Migration20260313222043.js +49 -0
- package/dist/modules/customer_accounts/migrations/Migration20260313222043.js.map +7 -0
- package/dist/modules/customer_accounts/notifications.client.js +47 -0
- package/dist/modules/customer_accounts/notifications.client.js.map +7 -0
- package/dist/modules/customer_accounts/notifications.js +46 -0
- package/dist/modules/customer_accounts/notifications.js.map +7 -0
- package/dist/modules/customer_accounts/search.js +120 -0
- package/dist/modules/customer_accounts/search.js.map +7 -0
- package/dist/modules/customer_accounts/services/customerInvitationService.js +87 -0
- package/dist/modules/customer_accounts/services/customerInvitationService.js.map +7 -0
- package/dist/modules/customer_accounts/services/customerRbacService.js +109 -0
- package/dist/modules/customer_accounts/services/customerRbacService.js.map +7 -0
- package/dist/modules/customer_accounts/services/customerSessionService.js +75 -0
- package/dist/modules/customer_accounts/services/customerSessionService.js.map +7 -0
- package/dist/modules/customer_accounts/services/customerTokenService.js +91 -0
- package/dist/modules/customer_accounts/services/customerTokenService.js.map +7 -0
- package/dist/modules/customer_accounts/services/customerUserService.js +92 -0
- package/dist/modules/customer_accounts/services/customerUserService.js.map +7 -0
- package/dist/modules/customer_accounts/setup.js +179 -0
- package/dist/modules/customer_accounts/setup.js.map +7 -0
- package/dist/modules/customer_accounts/subscribers/autoLinkCrm.js +54 -0
- package/dist/modules/customer_accounts/subscribers/autoLinkCrm.js.map +7 -0
- package/dist/modules/customer_accounts/subscribers/autoLinkCrmReverse.js +68 -0
- package/dist/modules/customer_accounts/subscribers/autoLinkCrmReverse.js.map +7 -0
- package/dist/modules/customer_accounts/subscribers/notifyStaffOnSignup.js +29 -0
- package/dist/modules/customer_accounts/subscribers/notifyStaffOnSignup.js.map +7 -0
- package/dist/modules/customer_accounts/translations.js +9 -0
- package/dist/modules/customer_accounts/translations.js.map +7 -0
- package/dist/modules/customer_accounts/widgets/injection/account-status/widget.client.js +63 -0
- package/dist/modules/customer_accounts/widgets/injection/account-status/widget.client.js.map +7 -0
- package/dist/modules/customer_accounts/widgets/injection/account-status/widget.js +17 -0
- package/dist/modules/customer_accounts/widgets/injection/account-status/widget.js.map +7 -0
- package/dist/modules/customer_accounts/widgets/injection/company-users/widget.client.js +55 -0
- package/dist/modules/customer_accounts/widgets/injection/company-users/widget.client.js.map +7 -0
- package/dist/modules/customer_accounts/widgets/injection/company-users/widget.js +17 -0
- package/dist/modules/customer_accounts/widgets/injection/company-users/widget.js.map +7 -0
- package/dist/modules/customer_accounts/widgets/injection-table.js +26 -0
- package/dist/modules/customer_accounts/widgets/injection-table.js.map +7 -0
- package/dist/modules/customer_accounts/workers/cleanupExpiredSessions.js +23 -0
- package/dist/modules/customer_accounts/workers/cleanupExpiredSessions.js.map +7 -0
- package/dist/modules/customer_accounts/workers/cleanupExpiredTokens.js +38 -0
- package/dist/modules/customer_accounts/workers/cleanupExpiredTokens.js.map +7 -0
- package/dist/modules/directory/api/get/organizations/lookup.js +83 -0
- package/dist/modules/directory/api/get/organizations/lookup.js.map +7 -0
- package/dist/modules/directory/commands/organizations.js +32 -1
- package/dist/modules/directory/commands/organizations.js.map +2 -2
- package/dist/modules/directory/data/entities.js +6 -2
- package/dist/modules/directory/data/entities.js.map +2 -2
- package/dist/modules/directory/data/validators.js +3 -0
- package/dist/modules/directory/data/validators.js.map +2 -2
- package/dist/modules/directory/migrations/Migration20260314143323.js +15 -0
- package/dist/modules/directory/migrations/Migration20260314143323.js.map +7 -0
- package/dist/modules/directory/setup.js +36 -0
- package/dist/modules/directory/setup.js.map +2 -2
- package/dist/modules/payment_gateways/migrations/Migration20260313222043.js +15 -0
- package/dist/modules/payment_gateways/migrations/Migration20260313222043.js.map +7 -0
- package/dist/modules/portal/frontend/[orgSlug]/portal/dashboard/page.js +131 -0
- package/dist/modules/portal/frontend/[orgSlug]/portal/dashboard/page.js.map +7 -0
- package/dist/modules/portal/frontend/[orgSlug]/portal/login/page.js +96 -0
- package/dist/modules/portal/frontend/[orgSlug]/portal/login/page.js.map +7 -0
- package/dist/modules/portal/frontend/[orgSlug]/portal/page.js +94 -0
- package/dist/modules/portal/frontend/[orgSlug]/portal/page.js.map +7 -0
- package/dist/modules/portal/frontend/[orgSlug]/portal/profile/page.js +89 -0
- package/dist/modules/portal/frontend/[orgSlug]/portal/profile/page.js.map +7 -0
- package/dist/modules/portal/frontend/[orgSlug]/portal/signup/page.js +104 -0
- package/dist/modules/portal/frontend/[orgSlug]/portal/signup/page.js.map +7 -0
- package/dist/modules/portal/index.js +11 -0
- package/dist/modules/portal/index.js.map +7 -0
- package/dist/modules/portal/setup.js +23 -0
- package/dist/modules/portal/setup.js.map +7 -0
- package/generated/entities/customer_role/index.ts +12 -0
- package/generated/entities/customer_role_acl/index.ts +8 -0
- package/generated/entities/customer_user/index.ts +17 -0
- package/generated/entities/customer_user_acl/index.ts +8 -0
- package/generated/entities/customer_user_email_verification/index.ts +7 -0
- package/generated/entities/customer_user_invitation/index.ts +15 -0
- package/generated/entities/customer_user_password_reset/index.ts +6 -0
- package/generated/entities/customer_user_role/index.ts +5 -0
- package/generated/entities/customer_user_session/index.ts +9 -0
- package/generated/entities/organization/index.ts +1 -0
- package/generated/entities.ids.generated.ts +14 -1
- package/generated/entity-fields-registry.ts +18 -0
- package/package.json +3 -3
- package/src/modules/auth/services/rbacService.ts +3 -9
- package/src/modules/customer_accounts/AGENTS.md +377 -0
- package/src/modules/customer_accounts/acl.ts +8 -0
- package/src/modules/customer_accounts/api/admin/roles/[id]/acl.ts +98 -0
- package/src/modules/customer_accounts/api/admin/roles/[id].ts +246 -0
- package/src/modules/customer_accounts/api/admin/roles.ts +212 -0
- package/src/modules/customer_accounts/api/admin/users/[id]/reset-password.ts +78 -0
- package/src/modules/customer_accounts/api/admin/users/[id]/verify-email.ts +72 -0
- package/src/modules/customer_accounts/api/admin/users/[id].ts +289 -0
- package/src/modules/customer_accounts/api/admin/users-invite.ts +86 -0
- package/src/modules/customer_accounts/api/admin/users.ts +280 -0
- package/src/modules/customer_accounts/api/email/verify.ts +66 -0
- package/src/modules/customer_accounts/api/interceptors.ts +3 -0
- package/src/modules/customer_accounts/api/invitations/accept.ts +128 -0
- package/src/modules/customer_accounts/api/login.ts +163 -0
- package/src/modules/customer_accounts/api/magic-link/request.ts +87 -0
- package/src/modules/customer_accounts/api/magic-link/verify.ts +132 -0
- package/src/modules/customer_accounts/api/password/reset-confirm.ts +69 -0
- package/src/modules/customer_accounts/api/password/reset-request.ts +87 -0
- package/src/modules/customer_accounts/api/portal/events/stream.ts +209 -0
- package/src/modules/customer_accounts/api/portal/feature-check.ts +60 -0
- package/src/modules/customer_accounts/api/portal/logout.ts +71 -0
- package/src/modules/customer_accounts/api/portal/notifications/[id]/dismiss.ts +54 -0
- package/src/modules/customer_accounts/api/portal/notifications/[id]/read.ts +54 -0
- package/src/modules/customer_accounts/api/portal/notifications/mark-all-read.ts +49 -0
- package/src/modules/customer_accounts/api/portal/notifications/unread-count.ts +45 -0
- package/src/modules/customer_accounts/api/portal/notifications.ts +115 -0
- package/src/modules/customer_accounts/api/portal/password-change.ts +65 -0
- package/src/modules/customer_accounts/api/portal/profile.ts +151 -0
- package/src/modules/customer_accounts/api/portal/sessions/[id].ts +70 -0
- package/src/modules/customer_accounts/api/portal/sessions-refresh.ts +87 -0
- package/src/modules/customer_accounts/api/portal/sessions.ts +84 -0
- package/src/modules/customer_accounts/api/portal/users/[id]/roles.ts +106 -0
- package/src/modules/customer_accounts/api/portal/users/[id].ts +81 -0
- package/src/modules/customer_accounts/api/portal/users-invite.ts +103 -0
- package/src/modules/customer_accounts/api/portal/users.ts +86 -0
- package/src/modules/customer_accounts/api/signup.ts +136 -0
- package/src/modules/customer_accounts/backend/customer_accounts/[id]/page.meta.ts +11 -0
- package/src/modules/customer_accounts/backend/customer_accounts/[id]/page.tsx +607 -0
- package/src/modules/customer_accounts/backend/customer_accounts/roles/[id]/page.meta.ts +12 -0
- package/src/modules/customer_accounts/backend/customer_accounts/roles/[id]/page.tsx +385 -0
- package/src/modules/customer_accounts/backend/customer_accounts/roles/create/page.meta.ts +12 -0
- package/src/modules/customer_accounts/backend/customer_accounts/roles/create/page.tsx +203 -0
- package/src/modules/customer_accounts/backend/customer_accounts/roles/page.meta.ts +31 -0
- package/src/modules/customer_accounts/backend/customer_accounts/roles/page.tsx +217 -0
- package/src/modules/customer_accounts/backend/page.meta.ts +33 -0
- package/src/modules/customer_accounts/backend/page.tsx +535 -0
- package/src/modules/customer_accounts/ce.ts +22 -0
- package/src/modules/customer_accounts/data/enrichers.ts +117 -0
- package/src/modules/customer_accounts/data/entities.ts +302 -0
- package/src/modules/customer_accounts/data/extensions.ts +4 -0
- package/src/modules/customer_accounts/data/validators.ts +128 -0
- package/src/modules/customer_accounts/di.ts +15 -0
- package/src/modules/customer_accounts/events.ts +28 -0
- package/src/modules/customer_accounts/i18n/de.json +176 -0
- package/src/modules/customer_accounts/i18n/en.json +176 -0
- package/src/modules/customer_accounts/i18n/es.json +176 -0
- package/src/modules/customer_accounts/i18n/pl.json +176 -0
- package/src/modules/customer_accounts/index.ts +13 -0
- package/src/modules/customer_accounts/lib/customerAuth.ts +85 -0
- package/src/modules/customer_accounts/lib/customerAuthServer.ts +54 -0
- package/src/modules/customer_accounts/lib/rateLimiter.ts +36 -0
- package/src/modules/customer_accounts/lib/tokenGenerator.ts +9 -0
- package/src/modules/customer_accounts/migrations/.snapshot-open-mercato.json +1255 -0
- package/src/modules/customer_accounts/migrations/Migration20260313222043.ts +62 -0
- package/src/modules/customer_accounts/notifications.client.ts +46 -0
- package/src/modules/customer_accounts/notifications.ts +44 -0
- package/src/modules/customer_accounts/search.ts +134 -0
- package/src/modules/customer_accounts/services/customerInvitationService.ts +109 -0
- package/src/modules/customer_accounts/services/customerRbacService.ts +144 -0
- package/src/modules/customer_accounts/services/customerSessionService.ts +90 -0
- package/src/modules/customer_accounts/services/customerTokenService.ts +98 -0
- package/src/modules/customer_accounts/services/customerUserService.ts +105 -0
- package/src/modules/customer_accounts/setup.ts +212 -0
- package/src/modules/customer_accounts/subscribers/autoLinkCrm.ts +65 -0
- package/src/modules/customer_accounts/subscribers/autoLinkCrmReverse.ts +78 -0
- package/src/modules/customer_accounts/subscribers/notifyStaffOnSignup.ts +32 -0
- package/src/modules/customer_accounts/translations.ts +5 -0
- package/src/modules/customer_accounts/widgets/injection/account-status/widget.client.tsx +89 -0
- package/src/modules/customer_accounts/widgets/injection/account-status/widget.ts +16 -0
- package/src/modules/customer_accounts/widgets/injection/company-users/widget.client.tsx +78 -0
- package/src/modules/customer_accounts/widgets/injection/company-users/widget.ts +16 -0
- package/src/modules/customer_accounts/widgets/injection-table.ts +24 -0
- package/src/modules/customer_accounts/workers/cleanupExpiredSessions.ts +33 -0
- package/src/modules/customer_accounts/workers/cleanupExpiredTokens.ts +51 -0
- package/src/modules/directory/api/get/organizations/lookup.ts +92 -0
- package/src/modules/directory/commands/organizations.ts +34 -1
- package/src/modules/directory/data/entities.ts +5 -1
- package/src/modules/directory/data/validators.ts +4 -0
- package/src/modules/directory/migrations/.snapshot-open-mercato.json +20 -1
- package/src/modules/directory/migrations/Migration20260314143323.ts +15 -0
- package/src/modules/directory/setup.ts +41 -0
- package/src/modules/payment_gateways/migrations/.snapshot-open-mercato.json +4 -1
- package/src/modules/payment_gateways/migrations/Migration20260313222043.ts +17 -0
- package/src/modules/portal/frontend/[orgSlug]/portal/dashboard/page.tsx +158 -0
- package/src/modules/portal/frontend/[orgSlug]/portal/login/page.tsx +120 -0
- package/src/modules/portal/frontend/[orgSlug]/portal/page.tsx +118 -0
- package/src/modules/portal/frontend/[orgSlug]/portal/profile/page.tsx +112 -0
- package/src/modules/portal/frontend/[orgSlug]/portal/signup/page.tsx +138 -0
- package/src/modules/portal/i18n/de.json +93 -0
- package/src/modules/portal/i18n/en.json +93 -0
- package/src/modules/portal/i18n/es.json +93 -0
- package/src/modules/portal/i18n/pl.json +93 -0
- package/src/modules/portal/index.ts +9 -0
- package/src/modules/portal/setup.ts +23 -0
- package/src/modules/shipping_carriers/migrations/.snapshot-open-mercato.json +226 -0
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import Link from 'next/link'
|
|
5
|
+
import { useRouter } from 'next/navigation'
|
|
6
|
+
import { Page, PageBody } from '@open-mercato/ui/backend/Page'
|
|
7
|
+
import { FormHeader } from '@open-mercato/ui/backend/forms'
|
|
8
|
+
import { Button } from '@open-mercato/ui/primitives/button'
|
|
9
|
+
import { Spinner } from '@open-mercato/ui/primitives/spinner'
|
|
10
|
+
import { apiCall, readApiResultOrThrow } from '@open-mercato/ui/backend/utils/apiCall'
|
|
11
|
+
import { flash } from '@open-mercato/ui/backend/FlashMessages'
|
|
12
|
+
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
13
|
+
import { useConfirmDialog } from '@open-mercato/ui/backend/confirm-dialog'
|
|
14
|
+
import { useGuardedMutation } from '@open-mercato/ui/backend/injection/useGuardedMutation'
|
|
15
|
+
|
|
16
|
+
type RoleDetail = {
|
|
17
|
+
id: string
|
|
18
|
+
name: string
|
|
19
|
+
slug: string
|
|
20
|
+
description: string | null
|
|
21
|
+
isDefault: boolean
|
|
22
|
+
isSystem: boolean
|
|
23
|
+
customerAssignable: boolean
|
|
24
|
+
features: string[]
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const PORTAL_FEATURES = [
|
|
28
|
+
{ id: 'portal.profile.view', labelKey: 'customer_accounts.admin.portalFeatures.profile.view', fallback: 'View profile' },
|
|
29
|
+
{ id: 'portal.profile.edit', labelKey: 'customer_accounts.admin.portalFeatures.profile.edit', fallback: 'Edit profile' },
|
|
30
|
+
{ id: 'portal.orders.view', labelKey: 'customer_accounts.admin.portalFeatures.orders.view', fallback: 'View orders' },
|
|
31
|
+
{ id: 'portal.orders.create', labelKey: 'customer_accounts.admin.portalFeatures.orders.create', fallback: 'Create orders' },
|
|
32
|
+
{ id: 'portal.invoices.view', labelKey: 'customer_accounts.admin.portalFeatures.invoices.view', fallback: 'View invoices' },
|
|
33
|
+
{ id: 'portal.quotes.view', labelKey: 'customer_accounts.admin.portalFeatures.quotes.view', fallback: 'View quotes' },
|
|
34
|
+
{ id: 'portal.quotes.request', labelKey: 'customer_accounts.admin.portalFeatures.quotes.request', fallback: 'Request quotes' },
|
|
35
|
+
{ id: 'portal.addresses.view', labelKey: 'customer_accounts.admin.portalFeatures.addresses.view', fallback: 'View addresses' },
|
|
36
|
+
{ id: 'portal.addresses.manage', labelKey: 'customer_accounts.admin.portalFeatures.addresses.manage', fallback: 'Manage addresses' },
|
|
37
|
+
{ id: 'portal.users.view', labelKey: 'customer_accounts.admin.portalFeatures.users.view', fallback: 'View team members' },
|
|
38
|
+
{ id: 'portal.users.invite', labelKey: 'customer_accounts.admin.portalFeatures.users.invite', fallback: 'Invite team members' },
|
|
39
|
+
{ id: 'portal.users.manage', labelKey: 'customer_accounts.admin.portalFeatures.users.manage', fallback: 'Manage team members' },
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
const FEATURE_GROUPS: Array<{ id: string; labelKey: string; fallback: string; features: string[] }> = (() => {
|
|
43
|
+
const groups = new Map<string, string[]>()
|
|
44
|
+
for (const feature of PORTAL_FEATURES) {
|
|
45
|
+
const parts = feature.id.split('.')
|
|
46
|
+
const groupKey = parts.length >= 2 ? `${parts[0]}.${parts[1]}` : parts[0]
|
|
47
|
+
const existing = groups.get(groupKey)
|
|
48
|
+
if (existing) {
|
|
49
|
+
existing.push(feature.id)
|
|
50
|
+
} else {
|
|
51
|
+
groups.set(groupKey, [feature.id])
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return Array.from(groups.entries()).map(([groupId, features]) => {
|
|
55
|
+
const scope = groupId.split('.').slice(1).join('')
|
|
56
|
+
const fallback = scope.replace(/^\w/, (ch) => ch.toUpperCase())
|
|
57
|
+
return {
|
|
58
|
+
id: groupId,
|
|
59
|
+
labelKey: `customer_accounts.admin.portalFeatures.groups.${scope}`,
|
|
60
|
+
fallback,
|
|
61
|
+
features,
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
})()
|
|
65
|
+
|
|
66
|
+
export default function CustomerRoleDetailPage({ params }: { params?: { id?: string } }) {
|
|
67
|
+
const id = params?.id
|
|
68
|
+
const t = useT()
|
|
69
|
+
const router = useRouter()
|
|
70
|
+
const { confirm, ConfirmDialogElement } = useConfirmDialog()
|
|
71
|
+
const [data, setData] = React.useState<RoleDetail | null>(null)
|
|
72
|
+
const [isLoading, setIsLoading] = React.useState(true)
|
|
73
|
+
const [error, setError] = React.useState<string | null>(null)
|
|
74
|
+
const [isSaving, setIsSaving] = React.useState(false)
|
|
75
|
+
|
|
76
|
+
const [editName, setEditName] = React.useState('')
|
|
77
|
+
const [editDescription, setEditDescription] = React.useState('')
|
|
78
|
+
const [editIsDefault, setEditIsDefault] = React.useState(false)
|
|
79
|
+
const [editCustomerAssignable, setEditCustomerAssignable] = React.useState(false)
|
|
80
|
+
const [editFeatures, setEditFeatures] = React.useState<string[]>([])
|
|
81
|
+
|
|
82
|
+
const mutationContextId = `customer_accounts:role:${id ?? 'pending'}`
|
|
83
|
+
const { runMutation, retryLastMutation } = useGuardedMutation<{
|
|
84
|
+
entityType: string
|
|
85
|
+
entityId?: string
|
|
86
|
+
}>({
|
|
87
|
+
contextId: mutationContextId,
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
const runMutationWithContext = React.useCallback(
|
|
91
|
+
async <T,>(operation: () => Promise<T>, mutationPayload?: Record<string, unknown>): Promise<T> => {
|
|
92
|
+
return runMutation({
|
|
93
|
+
operation,
|
|
94
|
+
mutationPayload,
|
|
95
|
+
context: { entityType: 'customer_accounts:role', entityId: id },
|
|
96
|
+
})
|
|
97
|
+
},
|
|
98
|
+
[id, runMutation],
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
React.useEffect(() => {
|
|
102
|
+
if (!id) {
|
|
103
|
+
setError(t('customer_accounts.admin.roleDetail.error.notFound', 'Role not found'))
|
|
104
|
+
setIsLoading(false)
|
|
105
|
+
return
|
|
106
|
+
}
|
|
107
|
+
let cancelled = false
|
|
108
|
+
async function load() {
|
|
109
|
+
setIsLoading(true)
|
|
110
|
+
setError(null)
|
|
111
|
+
try {
|
|
112
|
+
const payload = await readApiResultOrThrow<RoleDetail>(
|
|
113
|
+
`/api/customer_accounts/admin/roles/${encodeURIComponent(id!)}`,
|
|
114
|
+
undefined,
|
|
115
|
+
{ errorMessage: t('customer_accounts.admin.roleDetail.error.load', 'Failed to load role') },
|
|
116
|
+
)
|
|
117
|
+
if (cancelled) return
|
|
118
|
+
setData(payload)
|
|
119
|
+
setEditName(payload.name)
|
|
120
|
+
setEditDescription(payload.description || '')
|
|
121
|
+
setEditIsDefault(payload.isDefault)
|
|
122
|
+
setEditCustomerAssignable(payload.customerAssignable)
|
|
123
|
+
setEditFeatures(Array.isArray(payload.features) ? payload.features : [])
|
|
124
|
+
} catch (err) {
|
|
125
|
+
if (cancelled) return
|
|
126
|
+
const message = err instanceof Error ? err.message : t('customer_accounts.admin.roleDetail.error.load', 'Failed to load role')
|
|
127
|
+
setError(message)
|
|
128
|
+
} finally {
|
|
129
|
+
if (!cancelled) setIsLoading(false)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
load()
|
|
133
|
+
return () => { cancelled = true }
|
|
134
|
+
}, [id, t])
|
|
135
|
+
|
|
136
|
+
const handleFeatureToggle = React.useCallback((featureId: string) => {
|
|
137
|
+
setEditFeatures((prev) =>
|
|
138
|
+
prev.includes(featureId)
|
|
139
|
+
? prev.filter((existingId) => existingId !== featureId)
|
|
140
|
+
: [...prev, featureId],
|
|
141
|
+
)
|
|
142
|
+
}, [])
|
|
143
|
+
|
|
144
|
+
const handleGroupToggle = React.useCallback((featureIds: string[]) => {
|
|
145
|
+
setEditFeatures((prev) => {
|
|
146
|
+
const allSelected = featureIds.every((featureId) => prev.includes(featureId))
|
|
147
|
+
if (allSelected) {
|
|
148
|
+
return prev.filter((featureId) => !featureIds.includes(featureId))
|
|
149
|
+
}
|
|
150
|
+
const next = [...prev]
|
|
151
|
+
for (const featureId of featureIds) {
|
|
152
|
+
if (!next.includes(featureId)) next.push(featureId)
|
|
153
|
+
}
|
|
154
|
+
return next
|
|
155
|
+
})
|
|
156
|
+
}, [])
|
|
157
|
+
|
|
158
|
+
const handleSave = React.useCallback(async () => {
|
|
159
|
+
if (!data || !id) return
|
|
160
|
+
setIsSaving(true)
|
|
161
|
+
try {
|
|
162
|
+
await runMutationWithContext(async () => {
|
|
163
|
+
const call = await apiCall(
|
|
164
|
+
`/api/customer_accounts/admin/roles/${encodeURIComponent(id)}`,
|
|
165
|
+
{
|
|
166
|
+
method: 'PUT',
|
|
167
|
+
headers: { 'content-type': 'application/json' },
|
|
168
|
+
body: JSON.stringify({
|
|
169
|
+
name: editName.trim(),
|
|
170
|
+
description: editDescription.trim() || null,
|
|
171
|
+
isDefault: editIsDefault,
|
|
172
|
+
customerAssignable: editCustomerAssignable,
|
|
173
|
+
features: editFeatures,
|
|
174
|
+
}),
|
|
175
|
+
},
|
|
176
|
+
)
|
|
177
|
+
if (!call.ok) {
|
|
178
|
+
flash(t('customer_accounts.admin.roleDetail.error.save', 'Failed to save role'), 'error')
|
|
179
|
+
return
|
|
180
|
+
}
|
|
181
|
+
flash(t('customer_accounts.admin.roleDetail.flash.saved', 'Role updated'), 'success')
|
|
182
|
+
setData((prev) => prev ? {
|
|
183
|
+
...prev,
|
|
184
|
+
name: editName.trim(),
|
|
185
|
+
description: editDescription.trim() || null,
|
|
186
|
+
isDefault: editIsDefault,
|
|
187
|
+
customerAssignable: editCustomerAssignable,
|
|
188
|
+
features: editFeatures,
|
|
189
|
+
} : prev)
|
|
190
|
+
}, { name: editName, description: editDescription, isDefault: editIsDefault, customerAssignable: editCustomerAssignable, features: editFeatures })
|
|
191
|
+
} catch (err) {
|
|
192
|
+
const message = err instanceof Error ? err.message : t('customer_accounts.admin.roleDetail.error.save', 'Failed to save role')
|
|
193
|
+
flash(message, 'error')
|
|
194
|
+
} finally {
|
|
195
|
+
setIsSaving(false)
|
|
196
|
+
}
|
|
197
|
+
}, [data, editCustomerAssignable, editDescription, editFeatures, editIsDefault, editName, id, runMutationWithContext, t])
|
|
198
|
+
|
|
199
|
+
const handleDelete = React.useCallback(async () => {
|
|
200
|
+
if (!data || !id) return
|
|
201
|
+
if (data.isSystem) {
|
|
202
|
+
flash(t('customer_accounts.admin.roles.error.deleteSystem', 'System roles cannot be deleted'), 'error')
|
|
203
|
+
return
|
|
204
|
+
}
|
|
205
|
+
const confirmed = await confirm({
|
|
206
|
+
title: t('customer_accounts.admin.roles.confirm.delete', 'Delete role "{{name}}"?', { name: data.name }),
|
|
207
|
+
variant: 'destructive',
|
|
208
|
+
})
|
|
209
|
+
if (!confirmed) return
|
|
210
|
+
try {
|
|
211
|
+
await runMutationWithContext(async () => {
|
|
212
|
+
const call = await apiCall(
|
|
213
|
+
`/api/customer_accounts/admin/roles/${encodeURIComponent(id)}`,
|
|
214
|
+
{ method: 'DELETE' },
|
|
215
|
+
)
|
|
216
|
+
if (!call.ok) {
|
|
217
|
+
flash(t('customer_accounts.admin.roles.error.delete', 'Failed to delete role'), 'error')
|
|
218
|
+
return
|
|
219
|
+
}
|
|
220
|
+
flash(t('customer_accounts.admin.roles.flash.deleted', 'Role deleted'), 'success')
|
|
221
|
+
router.push('/backend/customer_accounts/roles')
|
|
222
|
+
}, { id })
|
|
223
|
+
} catch (err) {
|
|
224
|
+
const message = err instanceof Error ? err.message : t('customer_accounts.admin.roles.error.delete', 'Failed to delete role')
|
|
225
|
+
flash(message, 'error')
|
|
226
|
+
}
|
|
227
|
+
}, [confirm, data, id, router, runMutationWithContext, t])
|
|
228
|
+
|
|
229
|
+
if (isLoading) {
|
|
230
|
+
return (
|
|
231
|
+
<Page>
|
|
232
|
+
<PageBody>
|
|
233
|
+
<div className="flex h-[50vh] flex-col items-center justify-center gap-2 text-muted-foreground">
|
|
234
|
+
<Spinner className="h-6 w-6" />
|
|
235
|
+
<span>{t('customer_accounts.admin.roleDetail.loading', 'Loading role...')}</span>
|
|
236
|
+
</div>
|
|
237
|
+
</PageBody>
|
|
238
|
+
</Page>
|
|
239
|
+
)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (error || !data) {
|
|
243
|
+
return (
|
|
244
|
+
<Page>
|
|
245
|
+
<PageBody>
|
|
246
|
+
<div className="flex h-[50vh] flex-col items-center justify-center gap-2 text-muted-foreground">
|
|
247
|
+
<p>{error || t('customer_accounts.admin.roleDetail.error.notFound', 'Role not found')}</p>
|
|
248
|
+
<Button asChild variant="outline">
|
|
249
|
+
<Link href="/backend/customer_accounts/roles">
|
|
250
|
+
{t('customer_accounts.admin.roleDetail.actions.backToList', 'Back to roles')}
|
|
251
|
+
</Link>
|
|
252
|
+
</Button>
|
|
253
|
+
</div>
|
|
254
|
+
</PageBody>
|
|
255
|
+
</Page>
|
|
256
|
+
)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return (
|
|
260
|
+
<Page>
|
|
261
|
+
<PageBody className="space-y-6">
|
|
262
|
+
<FormHeader
|
|
263
|
+
mode="detail"
|
|
264
|
+
backHref="/backend/customer_accounts/roles"
|
|
265
|
+
backLabel={t('customer_accounts.admin.roleDetail.actions.backToList', 'Back to roles')}
|
|
266
|
+
title={data.name}
|
|
267
|
+
subtitle={data.slug}
|
|
268
|
+
statusBadge={data.isSystem ? (
|
|
269
|
+
<span className="inline-flex items-center rounded-full bg-blue-100 px-2 py-0.5 text-xs font-medium text-blue-800 dark:bg-blue-900 dark:text-blue-200">
|
|
270
|
+
{t('customer_accounts.admin.roles.system', 'System')}
|
|
271
|
+
</span>
|
|
272
|
+
) : undefined}
|
|
273
|
+
onDelete={!data.isSystem ? (() => { void handleDelete() }) : undefined}
|
|
274
|
+
deleteLabel={t('customer_accounts.admin.roleDetail.actions.delete', 'Delete')}
|
|
275
|
+
/>
|
|
276
|
+
|
|
277
|
+
<div className="rounded-lg border p-4 space-y-4">
|
|
278
|
+
<h2 className="text-sm font-semibold">{t('customer_accounts.admin.roleDetail.sections.details', 'Role Details')}</h2>
|
|
279
|
+
<div className="space-y-3">
|
|
280
|
+
<div>
|
|
281
|
+
<label className="text-sm font-medium" htmlFor="role-name">
|
|
282
|
+
{t('customer_accounts.admin.roleDetail.fields.name', 'Name')}
|
|
283
|
+
</label>
|
|
284
|
+
<input
|
|
285
|
+
id="role-name"
|
|
286
|
+
type="text"
|
|
287
|
+
value={editName}
|
|
288
|
+
onChange={(event) => setEditName(event.target.value)}
|
|
289
|
+
disabled={data.isSystem}
|
|
290
|
+
className="mt-1 block w-full rounded border border-border bg-background px-3 py-2 text-sm disabled:opacity-50"
|
|
291
|
+
/>
|
|
292
|
+
</div>
|
|
293
|
+
<div>
|
|
294
|
+
<label className="text-sm font-medium" htmlFor="role-description">
|
|
295
|
+
{t('customer_accounts.admin.roleDetail.fields.description', 'Description')}
|
|
296
|
+
</label>
|
|
297
|
+
<textarea
|
|
298
|
+
id="role-description"
|
|
299
|
+
value={editDescription}
|
|
300
|
+
onChange={(event) => setEditDescription(event.target.value)}
|
|
301
|
+
rows={3}
|
|
302
|
+
className="mt-1 block w-full rounded border border-border bg-background px-3 py-2 text-sm"
|
|
303
|
+
/>
|
|
304
|
+
</div>
|
|
305
|
+
<div className="flex items-center gap-6">
|
|
306
|
+
<label className="flex items-center gap-2 text-sm">
|
|
307
|
+
<input
|
|
308
|
+
type="checkbox"
|
|
309
|
+
checked={editIsDefault}
|
|
310
|
+
onChange={(event) => setEditIsDefault(event.target.checked)}
|
|
311
|
+
className="rounded border-border"
|
|
312
|
+
/>
|
|
313
|
+
{t('customer_accounts.admin.roleDetail.fields.isDefault', 'Default role (auto-assigned to new users)')}
|
|
314
|
+
</label>
|
|
315
|
+
<label className="flex items-center gap-2 text-sm">
|
|
316
|
+
<input
|
|
317
|
+
type="checkbox"
|
|
318
|
+
checked={editCustomerAssignable}
|
|
319
|
+
onChange={(event) => setEditCustomerAssignable(event.target.checked)}
|
|
320
|
+
className="rounded border-border"
|
|
321
|
+
/>
|
|
322
|
+
{t('customer_accounts.admin.roleDetail.fields.customerAssignable', 'Customers can self-assign')}
|
|
323
|
+
</label>
|
|
324
|
+
</div>
|
|
325
|
+
</div>
|
|
326
|
+
</div>
|
|
327
|
+
|
|
328
|
+
<div className="rounded-lg border p-4 space-y-4">
|
|
329
|
+
<h2 className="text-sm font-semibold">{t('customer_accounts.admin.roleDetail.sections.permissions', 'Portal Permissions')}</h2>
|
|
330
|
+
<div className="space-y-4">
|
|
331
|
+
{FEATURE_GROUPS.map((group) => {
|
|
332
|
+
const groupFeatures = group.features
|
|
333
|
+
const allSelected = groupFeatures.every((featureId) => editFeatures.includes(featureId))
|
|
334
|
+
const someSelected = groupFeatures.some((featureId) => editFeatures.includes(featureId))
|
|
335
|
+
return (
|
|
336
|
+
<div key={group.id} className="space-y-2">
|
|
337
|
+
<label className="flex items-center gap-2 text-sm font-medium">
|
|
338
|
+
<input
|
|
339
|
+
type="checkbox"
|
|
340
|
+
checked={allSelected}
|
|
341
|
+
ref={(el) => { if (el) el.indeterminate = someSelected && !allSelected }}
|
|
342
|
+
onChange={() => handleGroupToggle(groupFeatures)}
|
|
343
|
+
className="rounded border-border"
|
|
344
|
+
/>
|
|
345
|
+
{t(group.labelKey, group.fallback)}
|
|
346
|
+
</label>
|
|
347
|
+
<div className="ml-6 grid gap-1 sm:grid-cols-2">
|
|
348
|
+
{groupFeatures.map((featureId) => {
|
|
349
|
+
const feature = PORTAL_FEATURES.find((portalFeature) => portalFeature.id === featureId)
|
|
350
|
+
return (
|
|
351
|
+
<label key={featureId} className="flex items-center gap-2 text-sm">
|
|
352
|
+
<input
|
|
353
|
+
type="checkbox"
|
|
354
|
+
checked={editFeatures.includes(featureId)}
|
|
355
|
+
onChange={() => handleFeatureToggle(featureId)}
|
|
356
|
+
className="rounded border-border"
|
|
357
|
+
/>
|
|
358
|
+
{feature ? t(feature.labelKey, feature.fallback) : featureId}
|
|
359
|
+
</label>
|
|
360
|
+
)
|
|
361
|
+
})}
|
|
362
|
+
</div>
|
|
363
|
+
</div>
|
|
364
|
+
)
|
|
365
|
+
})}
|
|
366
|
+
</div>
|
|
367
|
+
</div>
|
|
368
|
+
|
|
369
|
+
<div className="flex gap-2">
|
|
370
|
+
<Button onClick={() => { void handleSave() }} disabled={isSaving}>
|
|
371
|
+
{isSaving
|
|
372
|
+
? t('customer_accounts.admin.roleDetail.actions.saving', 'Saving...')
|
|
373
|
+
: t('customer_accounts.admin.roleDetail.actions.save', 'Save Changes')}
|
|
374
|
+
</Button>
|
|
375
|
+
<Button variant="outline" asChild>
|
|
376
|
+
<Link href="/backend/customer_accounts/roles">
|
|
377
|
+
{t('customer_accounts.admin.roleDetail.actions.cancel', 'Cancel')}
|
|
378
|
+
</Link>
|
|
379
|
+
</Button>
|
|
380
|
+
</div>
|
|
381
|
+
</PageBody>
|
|
382
|
+
{ConfirmDialogElement}
|
|
383
|
+
</Page>
|
|
384
|
+
)
|
|
385
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const metadata = {
|
|
2
|
+
requireAuth: true,
|
|
3
|
+
requireFeatures: ['customer_accounts.roles.manage'],
|
|
4
|
+
pageTitle: 'Create Customer Role',
|
|
5
|
+
pageTitleKey: 'customer_accounts.nav.role_create',
|
|
6
|
+
navHidden: true,
|
|
7
|
+
breadcrumb: [
|
|
8
|
+
{ label: 'Customer Accounts', labelKey: 'customer_accounts.nav.users', href: '/backend/customer_accounts' },
|
|
9
|
+
{ label: 'Roles', labelKey: 'customer_accounts.nav.roles', href: '/backend/customer_accounts/roles' },
|
|
10
|
+
{ label: 'Create Role', labelKey: 'customer_accounts.nav.role_create' },
|
|
11
|
+
],
|
|
12
|
+
} as const
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import Link from 'next/link'
|
|
5
|
+
import { useRouter } from 'next/navigation'
|
|
6
|
+
import { Page, PageBody } from '@open-mercato/ui/backend/Page'
|
|
7
|
+
import { Button } from '@open-mercato/ui/primitives/button'
|
|
8
|
+
import { apiCall } from '@open-mercato/ui/backend/utils/apiCall'
|
|
9
|
+
import { flash } from '@open-mercato/ui/backend/FlashMessages'
|
|
10
|
+
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
11
|
+
import { useGuardedMutation } from '@open-mercato/ui/backend/injection/useGuardedMutation'
|
|
12
|
+
|
|
13
|
+
function slugify(value: string): string {
|
|
14
|
+
return value
|
|
15
|
+
.toLowerCase()
|
|
16
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
17
|
+
.replace(/^-+|-+$/g, '')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default function CreateCustomerRolePage() {
|
|
21
|
+
const t = useT()
|
|
22
|
+
const router = useRouter()
|
|
23
|
+
const [isSaving, setIsSaving] = React.useState(false)
|
|
24
|
+
|
|
25
|
+
const [name, setName] = React.useState('')
|
|
26
|
+
const [slug, setSlug] = React.useState('')
|
|
27
|
+
const [slugTouched, setSlugTouched] = React.useState(false)
|
|
28
|
+
const [description, setDescription] = React.useState('')
|
|
29
|
+
const [isDefault, setIsDefault] = React.useState(false)
|
|
30
|
+
const [customerAssignable, setCustomerAssignable] = React.useState(false)
|
|
31
|
+
|
|
32
|
+
const { runMutation, retryLastMutation } = useGuardedMutation<{
|
|
33
|
+
entityType: string
|
|
34
|
+
}>({
|
|
35
|
+
contextId: 'customer_accounts:role:create',
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
const runMutationWithContext = React.useCallback(
|
|
39
|
+
async <T,>(operation: () => Promise<T>, mutationPayload?: Record<string, unknown>): Promise<T> => {
|
|
40
|
+
return runMutation({
|
|
41
|
+
operation,
|
|
42
|
+
mutationPayload,
|
|
43
|
+
context: { entityType: 'customer_accounts:role' },
|
|
44
|
+
})
|
|
45
|
+
},
|
|
46
|
+
[runMutation],
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
const handleNameChange = React.useCallback((value: string) => {
|
|
50
|
+
setName(value)
|
|
51
|
+
if (!slugTouched) {
|
|
52
|
+
setSlug(slugify(value))
|
|
53
|
+
}
|
|
54
|
+
}, [slugTouched])
|
|
55
|
+
|
|
56
|
+
const handleSlugChange = React.useCallback((value: string) => {
|
|
57
|
+
setSlugTouched(true)
|
|
58
|
+
setSlug(value.toLowerCase().replace(/[^a-z0-9_-]/g, ''))
|
|
59
|
+
}, [])
|
|
60
|
+
|
|
61
|
+
const handleSubmit = React.useCallback(async () => {
|
|
62
|
+
if (!name.trim() || !slug.trim()) {
|
|
63
|
+
flash(t('customer_accounts.admin.roleCreate.error.required', 'Name and slug are required'), 'error')
|
|
64
|
+
return
|
|
65
|
+
}
|
|
66
|
+
setIsSaving(true)
|
|
67
|
+
try {
|
|
68
|
+
await runMutationWithContext(async () => {
|
|
69
|
+
const call = await apiCall(
|
|
70
|
+
'/api/customer_accounts/admin/roles',
|
|
71
|
+
{
|
|
72
|
+
method: 'POST',
|
|
73
|
+
headers: { 'content-type': 'application/json' },
|
|
74
|
+
body: JSON.stringify({
|
|
75
|
+
name: name.trim(),
|
|
76
|
+
slug: slug.trim(),
|
|
77
|
+
description: description.trim() || undefined,
|
|
78
|
+
isDefault,
|
|
79
|
+
customerAssignable,
|
|
80
|
+
}),
|
|
81
|
+
},
|
|
82
|
+
)
|
|
83
|
+
if (!call.ok) {
|
|
84
|
+
const data = call.result as Record<string, unknown> | null
|
|
85
|
+
flash((data?.error as string) || t('customer_accounts.admin.roleCreate.error.save', 'Failed to create role'), 'error')
|
|
86
|
+
return
|
|
87
|
+
}
|
|
88
|
+
const data = call.result as Record<string, unknown> | null
|
|
89
|
+
flash(t('customer_accounts.admin.roleCreate.flash.created', 'Role created'), 'success')
|
|
90
|
+
const role = data?.role as Record<string, unknown> | undefined
|
|
91
|
+
if (role?.id) {
|
|
92
|
+
router.push(`/backend/customer_accounts/roles/${role.id}`)
|
|
93
|
+
} else {
|
|
94
|
+
router.push('/backend/customer_accounts/roles')
|
|
95
|
+
}
|
|
96
|
+
}, { name: name.trim(), slug: slug.trim(), isDefault, customerAssignable })
|
|
97
|
+
} catch (err) {
|
|
98
|
+
const message = err instanceof Error ? err.message : t('customer_accounts.admin.roleCreate.error.save', 'Failed to create role')
|
|
99
|
+
flash(message, 'error')
|
|
100
|
+
} finally {
|
|
101
|
+
setIsSaving(false)
|
|
102
|
+
}
|
|
103
|
+
}, [customerAssignable, description, isDefault, name, router, runMutationWithContext, slug, t])
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<Page>
|
|
107
|
+
<PageBody className="space-y-6">
|
|
108
|
+
<div className="flex items-center justify-between">
|
|
109
|
+
<h1 className="text-2xl font-bold">
|
|
110
|
+
{t('customer_accounts.admin.roleCreate.title', 'Create Customer Role')}
|
|
111
|
+
</h1>
|
|
112
|
+
<Button variant="outline" asChild>
|
|
113
|
+
<Link href="/backend/customer_accounts/roles">
|
|
114
|
+
{t('customer_accounts.admin.roleCreate.actions.cancel', 'Cancel')}
|
|
115
|
+
</Link>
|
|
116
|
+
</Button>
|
|
117
|
+
</div>
|
|
118
|
+
|
|
119
|
+
<div className="rounded-lg border p-4 space-y-4">
|
|
120
|
+
<h2 className="text-sm font-semibold">
|
|
121
|
+
{t('customer_accounts.admin.roleCreate.sections.details', 'Role Details')}
|
|
122
|
+
</h2>
|
|
123
|
+
<div className="space-y-3">
|
|
124
|
+
<div>
|
|
125
|
+
<label className="text-sm font-medium" htmlFor="role-name">
|
|
126
|
+
{t('customer_accounts.admin.roleCreate.fields.name', 'Name')}
|
|
127
|
+
</label>
|
|
128
|
+
<input
|
|
129
|
+
id="role-name"
|
|
130
|
+
type="text"
|
|
131
|
+
value={name}
|
|
132
|
+
onChange={(event) => handleNameChange(event.target.value)}
|
|
133
|
+
className="mt-1 block w-full rounded border border-border bg-background px-3 py-2 text-sm"
|
|
134
|
+
placeholder={t('customer_accounts.admin.roleCreate.fields.namePlaceholder', 'e.g. Buyer')}
|
|
135
|
+
/>
|
|
136
|
+
</div>
|
|
137
|
+
<div>
|
|
138
|
+
<label className="text-sm font-medium" htmlFor="role-slug">
|
|
139
|
+
{t('customer_accounts.admin.roleCreate.fields.slug', 'Slug')}
|
|
140
|
+
</label>
|
|
141
|
+
<input
|
|
142
|
+
id="role-slug"
|
|
143
|
+
type="text"
|
|
144
|
+
value={slug}
|
|
145
|
+
onChange={(event) => handleSlugChange(event.target.value)}
|
|
146
|
+
className="mt-1 block w-full rounded border border-border bg-background px-3 py-2 text-sm font-mono"
|
|
147
|
+
placeholder={t('customer_accounts.admin.roleCreate.fields.slugPlaceholder', 'e.g. buyer')}
|
|
148
|
+
/>
|
|
149
|
+
<p className="mt-1 text-xs text-muted-foreground">
|
|
150
|
+
{t('customer_accounts.admin.roleCreate.fields.slugHint', 'Lowercase letters, numbers, hyphens, and underscores only.')}
|
|
151
|
+
</p>
|
|
152
|
+
</div>
|
|
153
|
+
<div>
|
|
154
|
+
<label className="text-sm font-medium" htmlFor="role-description">
|
|
155
|
+
{t('customer_accounts.admin.roleCreate.fields.description', 'Description')}
|
|
156
|
+
</label>
|
|
157
|
+
<textarea
|
|
158
|
+
id="role-description"
|
|
159
|
+
value={description}
|
|
160
|
+
onChange={(event) => setDescription(event.target.value)}
|
|
161
|
+
rows={3}
|
|
162
|
+
className="mt-1 block w-full rounded border border-border bg-background px-3 py-2 text-sm"
|
|
163
|
+
/>
|
|
164
|
+
</div>
|
|
165
|
+
<div className="flex items-center gap-6">
|
|
166
|
+
<label className="flex items-center gap-2 text-sm">
|
|
167
|
+
<input
|
|
168
|
+
type="checkbox"
|
|
169
|
+
checked={isDefault}
|
|
170
|
+
onChange={(event) => setIsDefault(event.target.checked)}
|
|
171
|
+
className="rounded border-border"
|
|
172
|
+
/>
|
|
173
|
+
{t('customer_accounts.admin.roleCreate.fields.isDefault', 'Default role (auto-assigned to new users)')}
|
|
174
|
+
</label>
|
|
175
|
+
<label className="flex items-center gap-2 text-sm">
|
|
176
|
+
<input
|
|
177
|
+
type="checkbox"
|
|
178
|
+
checked={customerAssignable}
|
|
179
|
+
onChange={(event) => setCustomerAssignable(event.target.checked)}
|
|
180
|
+
className="rounded border-border"
|
|
181
|
+
/>
|
|
182
|
+
{t('customer_accounts.admin.roleCreate.fields.customerAssignable', 'Customers can self-assign')}
|
|
183
|
+
</label>
|
|
184
|
+
</div>
|
|
185
|
+
</div>
|
|
186
|
+
</div>
|
|
187
|
+
|
|
188
|
+
<div className="flex gap-2">
|
|
189
|
+
<Button onClick={() => { void handleSubmit() }} disabled={isSaving}>
|
|
190
|
+
{isSaving
|
|
191
|
+
? t('customer_accounts.admin.roleCreate.actions.saving', 'Creating...')
|
|
192
|
+
: t('customer_accounts.admin.roleCreate.actions.create', 'Create Role')}
|
|
193
|
+
</Button>
|
|
194
|
+
<Button variant="outline" asChild>
|
|
195
|
+
<Link href="/backend/customer_accounts/roles">
|
|
196
|
+
{t('customer_accounts.admin.roleCreate.actions.cancel', 'Cancel')}
|
|
197
|
+
</Link>
|
|
198
|
+
</Button>
|
|
199
|
+
</div>
|
|
200
|
+
</PageBody>
|
|
201
|
+
</Page>
|
|
202
|
+
)
|
|
203
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
const shieldIcon = React.createElement(
|
|
4
|
+
'svg',
|
|
5
|
+
{
|
|
6
|
+
width: 16,
|
|
7
|
+
height: 16,
|
|
8
|
+
viewBox: '0 0 24 24',
|
|
9
|
+
fill: 'none',
|
|
10
|
+
stroke: 'currentColor',
|
|
11
|
+
strokeWidth: 2,
|
|
12
|
+
strokeLinecap: 'round',
|
|
13
|
+
strokeLinejoin: 'round',
|
|
14
|
+
},
|
|
15
|
+
React.createElement('path', { d: 'M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z' }),
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
export const metadata = {
|
|
19
|
+
requireAuth: true,
|
|
20
|
+
requireFeatures: ['customer_accounts.view'],
|
|
21
|
+
pageTitle: 'Customer Roles',
|
|
22
|
+
pageTitleKey: 'customer_accounts.nav.roles',
|
|
23
|
+
pageGroup: 'Customers',
|
|
24
|
+
pageGroupKey: 'customer_accounts.nav.group',
|
|
25
|
+
pageOrder: 156,
|
|
26
|
+
icon: shieldIcon,
|
|
27
|
+
breadcrumb: [
|
|
28
|
+
{ label: 'Customer Accounts', labelKey: 'customer_accounts.nav.users', href: '/backend/customer_accounts' },
|
|
29
|
+
{ label: 'Roles', labelKey: 'customer_accounts.nav.roles' },
|
|
30
|
+
],
|
|
31
|
+
} as const
|