@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.
Files changed (330) hide show
  1. package/agentic/standalone-guide.md +235 -0
  2. package/dist/generated/entities/customer_role/index.js +27 -0
  3. package/dist/generated/entities/customer_role/index.js.map +7 -0
  4. package/dist/generated/entities/customer_role_acl/index.js +19 -0
  5. package/dist/generated/entities/customer_role_acl/index.js.map +7 -0
  6. package/dist/generated/entities/customer_user/index.js +37 -0
  7. package/dist/generated/entities/customer_user/index.js.map +7 -0
  8. package/dist/generated/entities/customer_user_acl/index.js +19 -0
  9. package/dist/generated/entities/customer_user_acl/index.js.map +7 -0
  10. package/dist/generated/entities/customer_user_email_verification/index.js +17 -0
  11. package/dist/generated/entities/customer_user_email_verification/index.js.map +7 -0
  12. package/dist/generated/entities/customer_user_invitation/index.js +33 -0
  13. package/dist/generated/entities/customer_user_invitation/index.js.map +7 -0
  14. package/dist/generated/entities/customer_user_password_reset/index.js +15 -0
  15. package/dist/generated/entities/customer_user_password_reset/index.js.map +7 -0
  16. package/dist/generated/entities/customer_user_role/index.js +13 -0
  17. package/dist/generated/entities/customer_user_role/index.js.map +7 -0
  18. package/dist/generated/entities/customer_user_session/index.js +21 -0
  19. package/dist/generated/entities/customer_user_session/index.js.map +7 -0
  20. package/dist/generated/entities/organization/index.js +2 -0
  21. package/dist/generated/entities/organization/index.js.map +2 -2
  22. package/dist/generated/entities.ids.generated.js +14 -1
  23. package/dist/generated/entities.ids.generated.js.map +2 -2
  24. package/dist/generated/entity-fields-registry.js +18 -0
  25. package/dist/generated/entity-fields-registry.js.map +2 -2
  26. package/dist/modules/auth/services/rbacService.js +3 -9
  27. package/dist/modules/auth/services/rbacService.js.map +2 -2
  28. package/dist/modules/customer_accounts/acl.js +12 -0
  29. package/dist/modules/customer_accounts/acl.js.map +7 -0
  30. package/dist/modules/customer_accounts/api/admin/roles/[id]/acl.js +87 -0
  31. package/dist/modules/customer_accounts/api/admin/roles/[id]/acl.js.map +7 -0
  32. package/dist/modules/customer_accounts/api/admin/roles/[id].js +216 -0
  33. package/dist/modules/customer_accounts/api/admin/roles/[id].js.map +7 -0
  34. package/dist/modules/customer_accounts/api/admin/roles.js +189 -0
  35. package/dist/modules/customer_accounts/api/admin/roles.js.map +7 -0
  36. package/dist/modules/customer_accounts/api/admin/users/[id]/reset-password.js +69 -0
  37. package/dist/modules/customer_accounts/api/admin/users/[id]/reset-password.js.map +7 -0
  38. package/dist/modules/customer_accounts/api/admin/users/[id]/verify-email.js +64 -0
  39. package/dist/modules/customer_accounts/api/admin/users/[id]/verify-email.js.map +7 -0
  40. package/dist/modules/customer_accounts/api/admin/users/[id].js +253 -0
  41. package/dist/modules/customer_accounts/api/admin/users/[id].js.map +7 -0
  42. package/dist/modules/customer_accounts/api/admin/users-invite.js +78 -0
  43. package/dist/modules/customer_accounts/api/admin/users-invite.js.map +7 -0
  44. package/dist/modules/customer_accounts/api/admin/users.js +251 -0
  45. package/dist/modules/customer_accounts/api/admin/users.js.map +7 -0
  46. package/dist/modules/customer_accounts/api/email/verify.js +59 -0
  47. package/dist/modules/customer_accounts/api/email/verify.js.map +7 -0
  48. package/dist/modules/customer_accounts/api/interceptors.js +5 -0
  49. package/dist/modules/customer_accounts/api/interceptors.js.map +7 -0
  50. package/dist/modules/customer_accounts/api/invitations/accept.js +114 -0
  51. package/dist/modules/customer_accounts/api/invitations/accept.js.map +7 -0
  52. package/dist/modules/customer_accounts/api/login.js +143 -0
  53. package/dist/modules/customer_accounts/api/login.js.map +7 -0
  54. package/dist/modules/customer_accounts/api/magic-link/request.js +78 -0
  55. package/dist/modules/customer_accounts/api/magic-link/request.js.map +7 -0
  56. package/dist/modules/customer_accounts/api/magic-link/verify.js +114 -0
  57. package/dist/modules/customer_accounts/api/magic-link/verify.js.map +7 -0
  58. package/dist/modules/customer_accounts/api/password/reset-confirm.js +59 -0
  59. package/dist/modules/customer_accounts/api/password/reset-confirm.js.map +7 -0
  60. package/dist/modules/customer_accounts/api/password/reset-request.js +77 -0
  61. package/dist/modules/customer_accounts/api/password/reset-request.js.map +7 -0
  62. package/dist/modules/customer_accounts/api/portal/events/stream.js +163 -0
  63. package/dist/modules/customer_accounts/api/portal/events/stream.js.map +7 -0
  64. package/dist/modules/customer_accounts/api/portal/feature-check.js +57 -0
  65. package/dist/modules/customer_accounts/api/portal/feature-check.js.map +7 -0
  66. package/dist/modules/customer_accounts/api/portal/logout.js +64 -0
  67. package/dist/modules/customer_accounts/api/portal/logout.js.map +7 -0
  68. package/dist/modules/customer_accounts/api/portal/notifications/[id]/dismiss.js +49 -0
  69. package/dist/modules/customer_accounts/api/portal/notifications/[id]/dismiss.js.map +7 -0
  70. package/dist/modules/customer_accounts/api/portal/notifications/[id]/read.js +49 -0
  71. package/dist/modules/customer_accounts/api/portal/notifications/[id]/read.js.map +7 -0
  72. package/dist/modules/customer_accounts/api/portal/notifications/mark-all-read.js +46 -0
  73. package/dist/modules/customer_accounts/api/portal/notifications/mark-all-read.js.map +7 -0
  74. package/dist/modules/customer_accounts/api/portal/notifications/unread-count.js +42 -0
  75. package/dist/modules/customer_accounts/api/portal/notifications/unread-count.js.map +7 -0
  76. package/dist/modules/customer_accounts/api/portal/notifications.js +105 -0
  77. package/dist/modules/customer_accounts/api/portal/notifications.js.map +7 -0
  78. package/dist/modules/customer_accounts/api/portal/password-change.js +57 -0
  79. package/dist/modules/customer_accounts/api/portal/password-change.js.map +7 -0
  80. package/dist/modules/customer_accounts/api/portal/profile.js +135 -0
  81. package/dist/modules/customer_accounts/api/portal/profile.js.map +7 -0
  82. package/dist/modules/customer_accounts/api/portal/sessions/[id].js +62 -0
  83. package/dist/modules/customer_accounts/api/portal/sessions/[id].js.map +7 -0
  84. package/dist/modules/customer_accounts/api/portal/sessions-refresh.js +75 -0
  85. package/dist/modules/customer_accounts/api/portal/sessions-refresh.js.map +7 -0
  86. package/dist/modules/customer_accounts/api/portal/sessions.js +77 -0
  87. package/dist/modules/customer_accounts/api/portal/sessions.js.map +7 -0
  88. package/dist/modules/customer_accounts/api/portal/users/[id]/roles.js +90 -0
  89. package/dist/modules/customer_accounts/api/portal/users/[id]/roles.js.map +7 -0
  90. package/dist/modules/customer_accounts/api/portal/users/[id].js +71 -0
  91. package/dist/modules/customer_accounts/api/portal/users/[id].js.map +7 -0
  92. package/dist/modules/customer_accounts/api/portal/users-invite.js +92 -0
  93. package/dist/modules/customer_accounts/api/portal/users-invite.js.map +7 -0
  94. package/dist/modules/customer_accounts/api/portal/users.js +79 -0
  95. package/dist/modules/customer_accounts/api/portal/users.js.map +7 -0
  96. package/dist/modules/customer_accounts/api/signup.js +121 -0
  97. package/dist/modules/customer_accounts/api/signup.js.map +7 -0
  98. package/dist/modules/customer_accounts/backend/customer_accounts/[id]/page.js +491 -0
  99. package/dist/modules/customer_accounts/backend/customer_accounts/[id]/page.js.map +7 -0
  100. package/dist/modules/customer_accounts/backend/customer_accounts/[id]/page.meta.js +15 -0
  101. package/dist/modules/customer_accounts/backend/customer_accounts/[id]/page.meta.js.map +7 -0
  102. package/dist/modules/customer_accounts/backend/customer_accounts/roles/[id]/page.js +343 -0
  103. package/dist/modules/customer_accounts/backend/customer_accounts/roles/[id]/page.js.map +7 -0
  104. package/dist/modules/customer_accounts/backend/customer_accounts/roles/[id]/page.meta.js +16 -0
  105. package/dist/modules/customer_accounts/backend/customer_accounts/roles/[id]/page.meta.js.map +7 -0
  106. package/dist/modules/customer_accounts/backend/customer_accounts/roles/create/page.js +180 -0
  107. package/dist/modules/customer_accounts/backend/customer_accounts/roles/create/page.js.map +7 -0
  108. package/dist/modules/customer_accounts/backend/customer_accounts/roles/create/page.meta.js +16 -0
  109. package/dist/modules/customer_accounts/backend/customer_accounts/roles/create/page.meta.js.map +7 -0
  110. package/dist/modules/customer_accounts/backend/customer_accounts/roles/page.js +176 -0
  111. package/dist/modules/customer_accounts/backend/customer_accounts/roles/page.js.map +7 -0
  112. package/dist/modules/customer_accounts/backend/customer_accounts/roles/page.meta.js +33 -0
  113. package/dist/modules/customer_accounts/backend/customer_accounts/roles/page.meta.js.map +7 -0
  114. package/dist/modules/customer_accounts/backend/page.js +466 -0
  115. package/dist/modules/customer_accounts/backend/page.js.map +7 -0
  116. package/dist/modules/customer_accounts/backend/page.meta.js +35 -0
  117. package/dist/modules/customer_accounts/backend/page.meta.js.map +7 -0
  118. package/dist/modules/customer_accounts/ce.js +26 -0
  119. package/dist/modules/customer_accounts/ce.js.map +7 -0
  120. package/dist/modules/customer_accounts/data/enrichers.js +85 -0
  121. package/dist/modules/customer_accounts/data/enrichers.js.map +7 -0
  122. package/dist/modules/customer_accounts/data/entities.js +377 -0
  123. package/dist/modules/customer_accounts/data/entities.js.map +7 -0
  124. package/dist/modules/customer_accounts/data/extensions.js +8 -0
  125. package/dist/modules/customer_accounts/data/extensions.js.map +7 -0
  126. package/dist/modules/customer_accounts/data/validators.js +111 -0
  127. package/dist/modules/customer_accounts/data/validators.js.map +7 -0
  128. package/dist/modules/customer_accounts/di.js +17 -0
  129. package/dist/modules/customer_accounts/di.js.map +7 -0
  130. package/dist/modules/customer_accounts/events.js +28 -0
  131. package/dist/modules/customer_accounts/events.js.map +7 -0
  132. package/dist/modules/customer_accounts/index.js +15 -0
  133. package/dist/modules/customer_accounts/index.js.map +7 -0
  134. package/dist/modules/customer_accounts/lib/customerAuth.js +71 -0
  135. package/dist/modules/customer_accounts/lib/customerAuth.js.map +7 -0
  136. package/dist/modules/customer_accounts/lib/customerAuthServer.js +29 -0
  137. package/dist/modules/customer_accounts/lib/customerAuthServer.js.map +7 -0
  138. package/dist/modules/customer_accounts/lib/rateLimiter.js +63 -0
  139. package/dist/modules/customer_accounts/lib/rateLimiter.js.map +7 -0
  140. package/dist/modules/customer_accounts/lib/tokenGenerator.js +12 -0
  141. package/dist/modules/customer_accounts/lib/tokenGenerator.js.map +7 -0
  142. package/dist/modules/customer_accounts/migrations/Migration20260313222043.js +49 -0
  143. package/dist/modules/customer_accounts/migrations/Migration20260313222043.js.map +7 -0
  144. package/dist/modules/customer_accounts/notifications.client.js +47 -0
  145. package/dist/modules/customer_accounts/notifications.client.js.map +7 -0
  146. package/dist/modules/customer_accounts/notifications.js +46 -0
  147. package/dist/modules/customer_accounts/notifications.js.map +7 -0
  148. package/dist/modules/customer_accounts/search.js +120 -0
  149. package/dist/modules/customer_accounts/search.js.map +7 -0
  150. package/dist/modules/customer_accounts/services/customerInvitationService.js +87 -0
  151. package/dist/modules/customer_accounts/services/customerInvitationService.js.map +7 -0
  152. package/dist/modules/customer_accounts/services/customerRbacService.js +109 -0
  153. package/dist/modules/customer_accounts/services/customerRbacService.js.map +7 -0
  154. package/dist/modules/customer_accounts/services/customerSessionService.js +75 -0
  155. package/dist/modules/customer_accounts/services/customerSessionService.js.map +7 -0
  156. package/dist/modules/customer_accounts/services/customerTokenService.js +91 -0
  157. package/dist/modules/customer_accounts/services/customerTokenService.js.map +7 -0
  158. package/dist/modules/customer_accounts/services/customerUserService.js +92 -0
  159. package/dist/modules/customer_accounts/services/customerUserService.js.map +7 -0
  160. package/dist/modules/customer_accounts/setup.js +179 -0
  161. package/dist/modules/customer_accounts/setup.js.map +7 -0
  162. package/dist/modules/customer_accounts/subscribers/autoLinkCrm.js +54 -0
  163. package/dist/modules/customer_accounts/subscribers/autoLinkCrm.js.map +7 -0
  164. package/dist/modules/customer_accounts/subscribers/autoLinkCrmReverse.js +68 -0
  165. package/dist/modules/customer_accounts/subscribers/autoLinkCrmReverse.js.map +7 -0
  166. package/dist/modules/customer_accounts/subscribers/notifyStaffOnSignup.js +29 -0
  167. package/dist/modules/customer_accounts/subscribers/notifyStaffOnSignup.js.map +7 -0
  168. package/dist/modules/customer_accounts/translations.js +9 -0
  169. package/dist/modules/customer_accounts/translations.js.map +7 -0
  170. package/dist/modules/customer_accounts/widgets/injection/account-status/widget.client.js +63 -0
  171. package/dist/modules/customer_accounts/widgets/injection/account-status/widget.client.js.map +7 -0
  172. package/dist/modules/customer_accounts/widgets/injection/account-status/widget.js +17 -0
  173. package/dist/modules/customer_accounts/widgets/injection/account-status/widget.js.map +7 -0
  174. package/dist/modules/customer_accounts/widgets/injection/company-users/widget.client.js +55 -0
  175. package/dist/modules/customer_accounts/widgets/injection/company-users/widget.client.js.map +7 -0
  176. package/dist/modules/customer_accounts/widgets/injection/company-users/widget.js +17 -0
  177. package/dist/modules/customer_accounts/widgets/injection/company-users/widget.js.map +7 -0
  178. package/dist/modules/customer_accounts/widgets/injection-table.js +26 -0
  179. package/dist/modules/customer_accounts/widgets/injection-table.js.map +7 -0
  180. package/dist/modules/customer_accounts/workers/cleanupExpiredSessions.js +23 -0
  181. package/dist/modules/customer_accounts/workers/cleanupExpiredSessions.js.map +7 -0
  182. package/dist/modules/customer_accounts/workers/cleanupExpiredTokens.js +38 -0
  183. package/dist/modules/customer_accounts/workers/cleanupExpiredTokens.js.map +7 -0
  184. package/dist/modules/directory/api/get/organizations/lookup.js +83 -0
  185. package/dist/modules/directory/api/get/organizations/lookup.js.map +7 -0
  186. package/dist/modules/directory/commands/organizations.js +32 -1
  187. package/dist/modules/directory/commands/organizations.js.map +2 -2
  188. package/dist/modules/directory/data/entities.js +6 -2
  189. package/dist/modules/directory/data/entities.js.map +2 -2
  190. package/dist/modules/directory/data/validators.js +3 -0
  191. package/dist/modules/directory/data/validators.js.map +2 -2
  192. package/dist/modules/directory/migrations/Migration20260314143323.js +15 -0
  193. package/dist/modules/directory/migrations/Migration20260314143323.js.map +7 -0
  194. package/dist/modules/directory/setup.js +36 -0
  195. package/dist/modules/directory/setup.js.map +2 -2
  196. package/dist/modules/payment_gateways/migrations/Migration20260313222043.js +15 -0
  197. package/dist/modules/payment_gateways/migrations/Migration20260313222043.js.map +7 -0
  198. package/dist/modules/portal/frontend/[orgSlug]/portal/dashboard/page.js +131 -0
  199. package/dist/modules/portal/frontend/[orgSlug]/portal/dashboard/page.js.map +7 -0
  200. package/dist/modules/portal/frontend/[orgSlug]/portal/login/page.js +96 -0
  201. package/dist/modules/portal/frontend/[orgSlug]/portal/login/page.js.map +7 -0
  202. package/dist/modules/portal/frontend/[orgSlug]/portal/page.js +94 -0
  203. package/dist/modules/portal/frontend/[orgSlug]/portal/page.js.map +7 -0
  204. package/dist/modules/portal/frontend/[orgSlug]/portal/profile/page.js +89 -0
  205. package/dist/modules/portal/frontend/[orgSlug]/portal/profile/page.js.map +7 -0
  206. package/dist/modules/portal/frontend/[orgSlug]/portal/signup/page.js +104 -0
  207. package/dist/modules/portal/frontend/[orgSlug]/portal/signup/page.js.map +7 -0
  208. package/dist/modules/portal/index.js +11 -0
  209. package/dist/modules/portal/index.js.map +7 -0
  210. package/dist/modules/portal/setup.js +23 -0
  211. package/dist/modules/portal/setup.js.map +7 -0
  212. package/generated/entities/customer_role/index.ts +12 -0
  213. package/generated/entities/customer_role_acl/index.ts +8 -0
  214. package/generated/entities/customer_user/index.ts +17 -0
  215. package/generated/entities/customer_user_acl/index.ts +8 -0
  216. package/generated/entities/customer_user_email_verification/index.ts +7 -0
  217. package/generated/entities/customer_user_invitation/index.ts +15 -0
  218. package/generated/entities/customer_user_password_reset/index.ts +6 -0
  219. package/generated/entities/customer_user_role/index.ts +5 -0
  220. package/generated/entities/customer_user_session/index.ts +9 -0
  221. package/generated/entities/organization/index.ts +1 -0
  222. package/generated/entities.ids.generated.ts +14 -1
  223. package/generated/entity-fields-registry.ts +18 -0
  224. package/package.json +3 -3
  225. package/src/modules/auth/services/rbacService.ts +3 -9
  226. package/src/modules/customer_accounts/AGENTS.md +377 -0
  227. package/src/modules/customer_accounts/acl.ts +8 -0
  228. package/src/modules/customer_accounts/api/admin/roles/[id]/acl.ts +98 -0
  229. package/src/modules/customer_accounts/api/admin/roles/[id].ts +246 -0
  230. package/src/modules/customer_accounts/api/admin/roles.ts +212 -0
  231. package/src/modules/customer_accounts/api/admin/users/[id]/reset-password.ts +78 -0
  232. package/src/modules/customer_accounts/api/admin/users/[id]/verify-email.ts +72 -0
  233. package/src/modules/customer_accounts/api/admin/users/[id].ts +289 -0
  234. package/src/modules/customer_accounts/api/admin/users-invite.ts +86 -0
  235. package/src/modules/customer_accounts/api/admin/users.ts +280 -0
  236. package/src/modules/customer_accounts/api/email/verify.ts +66 -0
  237. package/src/modules/customer_accounts/api/interceptors.ts +3 -0
  238. package/src/modules/customer_accounts/api/invitations/accept.ts +128 -0
  239. package/src/modules/customer_accounts/api/login.ts +163 -0
  240. package/src/modules/customer_accounts/api/magic-link/request.ts +87 -0
  241. package/src/modules/customer_accounts/api/magic-link/verify.ts +132 -0
  242. package/src/modules/customer_accounts/api/password/reset-confirm.ts +69 -0
  243. package/src/modules/customer_accounts/api/password/reset-request.ts +87 -0
  244. package/src/modules/customer_accounts/api/portal/events/stream.ts +209 -0
  245. package/src/modules/customer_accounts/api/portal/feature-check.ts +60 -0
  246. package/src/modules/customer_accounts/api/portal/logout.ts +71 -0
  247. package/src/modules/customer_accounts/api/portal/notifications/[id]/dismiss.ts +54 -0
  248. package/src/modules/customer_accounts/api/portal/notifications/[id]/read.ts +54 -0
  249. package/src/modules/customer_accounts/api/portal/notifications/mark-all-read.ts +49 -0
  250. package/src/modules/customer_accounts/api/portal/notifications/unread-count.ts +45 -0
  251. package/src/modules/customer_accounts/api/portal/notifications.ts +115 -0
  252. package/src/modules/customer_accounts/api/portal/password-change.ts +65 -0
  253. package/src/modules/customer_accounts/api/portal/profile.ts +151 -0
  254. package/src/modules/customer_accounts/api/portal/sessions/[id].ts +70 -0
  255. package/src/modules/customer_accounts/api/portal/sessions-refresh.ts +87 -0
  256. package/src/modules/customer_accounts/api/portal/sessions.ts +84 -0
  257. package/src/modules/customer_accounts/api/portal/users/[id]/roles.ts +106 -0
  258. package/src/modules/customer_accounts/api/portal/users/[id].ts +81 -0
  259. package/src/modules/customer_accounts/api/portal/users-invite.ts +103 -0
  260. package/src/modules/customer_accounts/api/portal/users.ts +86 -0
  261. package/src/modules/customer_accounts/api/signup.ts +136 -0
  262. package/src/modules/customer_accounts/backend/customer_accounts/[id]/page.meta.ts +11 -0
  263. package/src/modules/customer_accounts/backend/customer_accounts/[id]/page.tsx +607 -0
  264. package/src/modules/customer_accounts/backend/customer_accounts/roles/[id]/page.meta.ts +12 -0
  265. package/src/modules/customer_accounts/backend/customer_accounts/roles/[id]/page.tsx +385 -0
  266. package/src/modules/customer_accounts/backend/customer_accounts/roles/create/page.meta.ts +12 -0
  267. package/src/modules/customer_accounts/backend/customer_accounts/roles/create/page.tsx +203 -0
  268. package/src/modules/customer_accounts/backend/customer_accounts/roles/page.meta.ts +31 -0
  269. package/src/modules/customer_accounts/backend/customer_accounts/roles/page.tsx +217 -0
  270. package/src/modules/customer_accounts/backend/page.meta.ts +33 -0
  271. package/src/modules/customer_accounts/backend/page.tsx +535 -0
  272. package/src/modules/customer_accounts/ce.ts +22 -0
  273. package/src/modules/customer_accounts/data/enrichers.ts +117 -0
  274. package/src/modules/customer_accounts/data/entities.ts +302 -0
  275. package/src/modules/customer_accounts/data/extensions.ts +4 -0
  276. package/src/modules/customer_accounts/data/validators.ts +128 -0
  277. package/src/modules/customer_accounts/di.ts +15 -0
  278. package/src/modules/customer_accounts/events.ts +28 -0
  279. package/src/modules/customer_accounts/i18n/de.json +176 -0
  280. package/src/modules/customer_accounts/i18n/en.json +176 -0
  281. package/src/modules/customer_accounts/i18n/es.json +176 -0
  282. package/src/modules/customer_accounts/i18n/pl.json +176 -0
  283. package/src/modules/customer_accounts/index.ts +13 -0
  284. package/src/modules/customer_accounts/lib/customerAuth.ts +85 -0
  285. package/src/modules/customer_accounts/lib/customerAuthServer.ts +54 -0
  286. package/src/modules/customer_accounts/lib/rateLimiter.ts +36 -0
  287. package/src/modules/customer_accounts/lib/tokenGenerator.ts +9 -0
  288. package/src/modules/customer_accounts/migrations/.snapshot-open-mercato.json +1255 -0
  289. package/src/modules/customer_accounts/migrations/Migration20260313222043.ts +62 -0
  290. package/src/modules/customer_accounts/notifications.client.ts +46 -0
  291. package/src/modules/customer_accounts/notifications.ts +44 -0
  292. package/src/modules/customer_accounts/search.ts +134 -0
  293. package/src/modules/customer_accounts/services/customerInvitationService.ts +109 -0
  294. package/src/modules/customer_accounts/services/customerRbacService.ts +144 -0
  295. package/src/modules/customer_accounts/services/customerSessionService.ts +90 -0
  296. package/src/modules/customer_accounts/services/customerTokenService.ts +98 -0
  297. package/src/modules/customer_accounts/services/customerUserService.ts +105 -0
  298. package/src/modules/customer_accounts/setup.ts +212 -0
  299. package/src/modules/customer_accounts/subscribers/autoLinkCrm.ts +65 -0
  300. package/src/modules/customer_accounts/subscribers/autoLinkCrmReverse.ts +78 -0
  301. package/src/modules/customer_accounts/subscribers/notifyStaffOnSignup.ts +32 -0
  302. package/src/modules/customer_accounts/translations.ts +5 -0
  303. package/src/modules/customer_accounts/widgets/injection/account-status/widget.client.tsx +89 -0
  304. package/src/modules/customer_accounts/widgets/injection/account-status/widget.ts +16 -0
  305. package/src/modules/customer_accounts/widgets/injection/company-users/widget.client.tsx +78 -0
  306. package/src/modules/customer_accounts/widgets/injection/company-users/widget.ts +16 -0
  307. package/src/modules/customer_accounts/widgets/injection-table.ts +24 -0
  308. package/src/modules/customer_accounts/workers/cleanupExpiredSessions.ts +33 -0
  309. package/src/modules/customer_accounts/workers/cleanupExpiredTokens.ts +51 -0
  310. package/src/modules/directory/api/get/organizations/lookup.ts +92 -0
  311. package/src/modules/directory/commands/organizations.ts +34 -1
  312. package/src/modules/directory/data/entities.ts +5 -1
  313. package/src/modules/directory/data/validators.ts +4 -0
  314. package/src/modules/directory/migrations/.snapshot-open-mercato.json +20 -1
  315. package/src/modules/directory/migrations/Migration20260314143323.ts +15 -0
  316. package/src/modules/directory/setup.ts +41 -0
  317. package/src/modules/payment_gateways/migrations/.snapshot-open-mercato.json +4 -1
  318. package/src/modules/payment_gateways/migrations/Migration20260313222043.ts +17 -0
  319. package/src/modules/portal/frontend/[orgSlug]/portal/dashboard/page.tsx +158 -0
  320. package/src/modules/portal/frontend/[orgSlug]/portal/login/page.tsx +120 -0
  321. package/src/modules/portal/frontend/[orgSlug]/portal/page.tsx +118 -0
  322. package/src/modules/portal/frontend/[orgSlug]/portal/profile/page.tsx +112 -0
  323. package/src/modules/portal/frontend/[orgSlug]/portal/signup/page.tsx +138 -0
  324. package/src/modules/portal/i18n/de.json +93 -0
  325. package/src/modules/portal/i18n/en.json +93 -0
  326. package/src/modules/portal/i18n/es.json +93 -0
  327. package/src/modules/portal/i18n/pl.json +93 -0
  328. package/src/modules/portal/index.ts +9 -0
  329. package/src/modules/portal/setup.ts +23 -0
  330. 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