Files
co-lite/solvway-admin-portal/app/lib/routeModules.ts
T
ngqileandClaude Opus 5.5 5ee51d1913 chore: copy kept Tastefully modules and portals into Co-Lite
Backend modules from tastefully 8bd93d15: core-libs, core-session,
api-gateway, mobile-api, services-auth, services-system,
services-counter, services-member, services-log, services-email.
solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal
from tastefully 8bd93d15. Copied as tracked files only.

Literal secrets replaced with environment placeholders:
- services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY,
  MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default)
- services-system: JUMIO_TOKEN, JUMIO_SECRET (optional)
- services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed
- core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default
  removed, ipgeolocation key read from IPGEOLOCATION_API_KEY
- services-system EkycAppConfig: commented Jumio credentials removed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
2026-11-26 15:55:45 +08:00

298 lines
19 KiB
TypeScript

import { INVENTORY_MODULE_NAMES, INVENTORY_MODULES } from "@/app/lib/inventoryModules";
// Route -> required module name. Values are the seeded aclMenu `name`
// column (BO_MEMBERS, ...), NOT the `desc` display label: the route gate
// RequireModule -> useAdminAuth().hasModule(x) matches a flattened aclMenu
// node by `name` or `url` only, so a desc label here never matches and a
// granted user would wrongly see the not-authorised state.
//
// "/members"/"/reports"/"/network" are enrolled here but enforcement is
// deferred (Ruling R5, add-admin-portal-auth spec "admin-portal-auth"): those
// pages are not wrapped in RequireModule, so they stay reachable (mock data)
// regardless of this map. "/messages" IS enforced (Ruling M1,
// add-message-catalog spec "admin-portal-i18n", requirement "Management
// Access Is Gated By Module And JWT"): its page IS wrapped in RequireModule,
// so a signed-in user without the "Messages" module gets the not-authorised
// state on direct navigation. "/users" is enforced the same way (Task 7,
// admin-portal-m1-identity-access-part2): its page is wrapped in
// RequireModule against the BO_USERS module. "/roles" is enforced the same
// way (Task 9, admin-portal-m1-identity-access-part2): its page is wrapped in
// RequireModule against the BO_ROLES module. "/bulletins" is
// enforced the same way (M2, add-admin-portal-bulletins spec
// "admin-bulletin-management"): the module row is seeded by the change's
// reviewed migration SQL (sql/seed-bo-module-bulletins.sql, id 41000000).
// That SQL's modules_roles grant (which would surface the module for a
// non-super role) is left commented out for the operator to target a
// specific role and apply; no grant is needed for ROLE_SUPER_ADMIN, which
// bypasses module-role gating in code. Its ROUTE_MODULES value is the seeded
// module `name` column ("Bulletins"), not a desc label — hasModule matches
// name/url.
//
// M3 (openspec/changes/add-admin-locations-warehouses): the seeded Area-'BO'
// module row uses name 'Locations & Warehouses' — the gate must use that name
// value (matching AdminModule.name), not a desc label, so hasModule() resolves.
//
// M4 (openspec/changes/add-admin-i18n-currency): the seeded module row was
// renamed to 'BO_Currency' (id 40600000, sql/seed-bo-module-currency.sql)
// because the plain name 'Currency' collides with a legacy Area-A module.
// The gate must use the actual seeded name — pointing this at 'Currency'
// left /currency showing NotAuthorised for everyone, including super-admin
// (RequireModule has no super-admin bypass on this client-side check), and
// was caught in live verification (fix-currency-gate-and-type-labels).
//
// M5 (openspec/changes/add-admin-email-templates): the seeded Area-'BO'
// module row is named 'BO_EMAIL_TEMPLATES' (id 41200000, seed
// sql/seed-bo-module-email-templates.sql) — the gate must use that `name`
// column value, never a desc label, so hasModule() resolves for a granted
// role.
//
// M6 (openspec/changes/add-admin-internal-notifications): the seeded module row
// is 'BO_NOTIFICATIONS' (id 41300000, sql/seed-bo-module-notifications.sql,
// url /notifications, icon 'Bell' under the System group 40460000). The gate
// must use that seeded `name` value, never the 'Notifications' desc label —
// hasModule matches name/url only. The /notifications page is wrapped in
// RequireModule, so a user without the grant gets the not-authorised state.
//
// M7 (openspec/changes/add-membership-wallet-foundation, increment I1): the
// seeded module row is 'BO_WALLET' (id 41400000, sql/seed-bo-module-wallet.sql,
// url /wallet, icon 'Wallet' under the BO root 40000000). The gate uses that
// seeded `name` value, never the 'Wallet' desc label — hasModule matches
// name/url only. The /wallet/{memberCode} view is wrapped in RequireModule, so
// a user without the grant gets the not-authorised state and no wallet data
// renders.
//
// M8 (openspec/changes/add-admin-login-security): the seeded module row is
// 'BO_LOGIN_SECURITY' (id 41500000, sql/seed-bo-module-login-security.sql,
// url /login-security, icon 'ShieldCheck' under the System group 40000000).
// Id 41500000 (not 41400000) because BO_WALLET took 41400000 on main. The gate
// must use that seeded `name` value, never the 'Login Security' desc label —
// hasModule matches name/url only. The /login-security page is wrapped in
// RequireModule; super-admin bypasses module-role gating consistently with the
// other BO modules.
//
// M9 (openspec/changes/add-membership-wallet-topup, increment I2): the top-up
// approval queue lives under the wallet module, so /wallet/topups is gated by
// the same seeded BO_WALLET module (id 41400000) as /wallet.
//
// M10 (openspec/changes/add-admin-locale-management): the seeded module row is
// 'BO_LOCALES' (id 41600000, sql/seed-bo-module-locales.sql, url /locales,
// icon 'Languages' under the System group 40460000). The gate must use that
// seeded `name` value, never the 'Locales (UI languages)' desc label —
// hasModule matches name/url only. The /locales page is wrapped in
// RequireModule; super-admin bypasses module-role gating consistently with the
// other BO modules.
//
// M11 (openspec/changes/add-admin-module-node-crud): the seeded module row is
// 'BO_MODULES' (id 41700000, sql/seed-bo-module-modules.sql, url /modules,
// icon 'Settings' under the System group 40460000). The gate must use that
// seeded `name` value, never the 'Module tree management' desc label. The
// /modules page is wrapped in RequireModule, so a user without the grant gets
// the not-authorised state. BO_MODULES is also in the protected-names denylist
// (admin-portal app/lib/protectedModules.ts, mobile-api AdminModuleService):
// it is itself a route-gate name with hardcoded dependencies.
//
// M12 (openspec/changes/add-admin-reference-data): the seeded module row is
// 'BO_REFERENCE_DATA' (id 41800000, sql/seed-bo-module-reference.sql, url
// /reference, icon 'FileText' under the System group 40460000). The gate must
// use that seeded `name` value, never the 'Reference Data' desc label —
// hasModule matches name/url only. The /reference page is wrapped in
// RequireModule; super-admin bypasses module-role gating consistently with the
// other BO modules. Adding this name to ROUTE_MODULES makes BO_REFERENCE_DATA a
// route-gated (and therefore protected) module name: the mobile-api
// AdminModuleService.PROTECTED_NAMES list and its drift-guard fixture MUST be
// updated in the same change (deleting/reparenting it would break the
// /reference gate).
//
// Task D (openspec/changes/add-admin-catalog-setup): the seeded module row is
// 'BO_CATALOG_SETUP' (id 41900000, url /catalog-setup) under the BO_CATALOG
// nav group. The gate must use that seeded `name` value, never a desc label
// -- hasModule matches name/url only. The /catalog-setup page is wrapped in
// RequireModule; super-admin bypasses module-role gating consistently with
// the other BO modules. Same as BO_REFERENCE_DATA, this addition makes
// BO_CATALOG_SETUP a route-gated (and therefore protected) module name via
// protectedModules.ts, which derives PROTECTED_MODULE_NAMES from this map.
//
// Task E (openspec/changes/add-admin-product-setup, Phase 1b): the seeded
// module row is 'BO_PRODUCTS' (id 42000000, url /products) under the same
// BO_CATALOG nav group as BO_CATALOG_SETUP. The gate must use that seeded
// `name` value, never a desc label. The /products page is wrapped in
// RequireModule; super-admin bypasses module-role gating consistently with
// the other BO modules.
//
// Task 9 (openspec/changes/add-membership-withdrawal, increment I5): the
// withdrawal approval queue lives under the wallet module, so
// /wallet/withdrawals is gated by the same seeded BO_WALLET module (id
// 41400000) as /wallet and /wallet/topups.
//
// Task 4 (BABYBOO-13, change withdrawal-config-and-cycle): the withdrawal settings page
// (min/max/increment/fee + weekly payout cycle cut-off) is another Wallet-tab sub-function, so
// /wallet/withdrawal-settings is gated by the same seeded BO_WALLET module as its siblings.
//
// Task 9 (openspec/changes/add-warehouse-setup, BABYBOO-18 increment I1): the
// seeded module row is 'BO_WAREHOUSE_SETUP' (id 42100000, url /warehouses,
// icon 'Warehouse') under the System nav group (40460000), mirroring the
// /locations (M3) module-row shape and parent — only the code/name/path/url
// differ. The gate must use that seeded `name` value, never a desc label —
// hasModule matches name/url only. The /warehouses page is wrapped in
// RequireModule; super-admin bypasses module-role gating consistently with
// the other BO modules.
//
// (openspec/changes/add-admin-company-account-crud, Part C; simplified by
// openspec/changes/simplify-company-account-nav-gating): Company/HQ account management is a
// second surface WITHIN the Network section, reached from the NetworkTabs sub-nav on /network
// — not a separate sidebar node. It is gated by the SAME BO_NETWORK permission as /network, so
// it does NOT carry its own module row. The earlier dedicated BO_COMPANY_ACCOUNT module
// (id 42200000) is un-seeded (sql/unseed-bo-module-company-account.sql), which removes the
// redundant Network sidebar child and the raw-code label it rendered with.
export const ROUTE_MODULES: Record<string, string> = {
"/members": "BO_MEMBERS",
"/reports": "BO_REPORTS",
"/network": "BO_NETWORK",
"/messages": "BO_MESSAGES",
"/users": "BO_USERS",
"/roles": "BO_ROLES",
"/locations": "Locations & Warehouses",
"/bulletins": "Bulletins",
"/currency": "BO_Currency",
"/email-templates": "BO_EMAIL_TEMPLATES",
// Payment Methods (add-payment-method-config, 2a): the seeded Area-'BO' module row is named
// 'BO_PAYMENT_METHODS' (sql/02-seed-bo-module-payment-methods.sql, url /payment-methods). The
// gate uses that seeded `name` value, never a desc label — hasModule matches name/url only.
"/payment-methods": "BO_PAYMENT_METHODS",
"/notifications": "BO_NOTIFICATIONS",
"/wallet": "BO_WALLET",
"/wallet/topups": "BO_WALLET",
"/wallet/withdrawals": "BO_WALLET",
"/wallet/withdrawal-settings": "BO_WALLET",
"/login-security": "BO_LOGIN_SECURITY",
"/locales": "BO_LOCALES",
"/modules": "BO_MODULES",
"/reference": "BO_REFERENCE_DATA",
"/catalog-setup": "BO_CATALOG_SETUP",
"/products": "BO_PRODUCTS",
// add-storefront-collections: seeded module 44900000 (url /collections) under BO_CATALOG.
"/collections": "BO_COLLECTIONS",
// add-cms-pages: seeded module 45100000 (url /pages), shown in the Online store sidebar group.
"/pages": "BO_PAGES",
// add-cms-forms: seeded module 45200000 (url /forms), in the Online store sidebar group.
"/forms": "BO_FORMS",
// add-storefront-menus: seeded module 45300000 (url /menus), in the Online store sidebar group.
"/menus": "BO_MENUS",
// add-shipping-rates: seeded module BO_SHIPPING (url /shipping), in the Online store sidebar group.
"/shipping": "BO_SHIPPING",
// Task 8 (add-portal-audit-log): the seeded module row is 'BO_AUDIT_LOG' (id 42000000, url
// /audit-log, icon 'ScrollText' under the System group 40000000). The gate must use that seeded
// `name` value, never a desc label — hasModule matches name/url only. The /audit-log page is
// wrapped in RequireModule; super-admin bypasses module-role gating consistently with the
// other BO modules.
"/audit-log": "BO_AUDIT_LOG",
// add-online-users: seeded module BO_ONLINE_USERS (url /online-users) in the Activity group (BO_NAV_ACTIVITY),
// beside Audit log.
"/online-users": "BO_ONLINE_USERS",
"/warehouses": "BO_WAREHOUSE_SETUP",
"/network/company-accounts": "BO_NETWORK",
// The five inventory modules gate /inventory together: see ROUTE_ANY_MODULES.
// E1 (openspec/changes/add-event-module-pickup-e1): the seeded module row is
// 'BO_EVENTS' (url /events) under the inventory nav group (40470000). The gate
// must use that seeded `name` value, never a desc label — hasModule matches
// name/url only. The /events page is wrapped in RequireModule; super-admin
// bypasses module-role gating consistently with the other BO modules.
"/events": "BO_EVENTS",
// BABYBOO-31 (add-event-summary): the seeded module row is 'BO_EVENT_SUMMARY' (url /events/summary)
// under the same nav group as BO_EVENTS. The gate must use that seeded `name` value, never a desc
// label — hasModule matches name/url only. The /events/summary page is wrapped in RequireModule;
// super-admin bypasses module-role gating consistently with the other BO modules.
"/events/summary": "BO_EVENT_SUMMARY",
// Task 12 (openspec/changes/add-homepage-banners): the seeded module row's
// `name` column is 'Banners' (mirroring /bulletins' "Bulletins" convention),
// not a desc label — hasModule matches name/url only. The /banners page is
// wrapped in RequireModule; super-admin bypasses module-role gating in code.
"/banners": "Banners",
// Task 10 (openspec/changes/add-event-pos-counter-sales): the seeded module row is
// 'BO_POS' (url /pos) for the event POS counter-sales page. The gate must use that
// seeded `name` value, never a desc label — hasModule matches name/url only. The /pos
// page is wrapped in RequireModule; super-admin bypasses module-role gating consistently
// with the other BO modules.
"/pos": "BO_POS",
// BABYBOO-18 Phase F (openspec/changes/add-admin-do-monitoring): the seeded module row is
// 'BO_DELIVERY_ORDERS' (url /inventory/delivery-orders) under the BO_CATALOG nav group
// (40470000), alongside the other inventory modules. The gate must use that seeded `name`
// value, never a desc label — hasModule matches name/url only. The /inventory/delivery-orders
// page is wrapped in RequireModule; super-admin bypasses module-role gating consistently with
// the other BO modules. This addition makes BO_DELIVERY_ORDERS a route-gated (and therefore
// protected) module name — the mobile-api AdminModuleService.PROTECTED_NAMES list and its
// drift-guard fixture must be updated in the same change.
"/inventory/delivery-orders": "BO_DELIVERY_ORDERS",
// (openspec/changes/add-admin-delivery-fulfilment-steps): the seeded module row is
// 'BO_WEB_ORDERS' (url /orders/web) under the BO_CATALOG nav group (40470000). The gate must
// use that seeded `name` value, never a desc label — hasModule matches name/url only. The
// /orders/web page is wrapped in RequireModule; super-admin bypasses module-role gating
// consistently with the other BO modules. This addition makes BO_WEB_ORDERS a route-gated
// (and therefore protected) module name — the mobile-api AdminModuleService.PROTECTED_NAMES
// list and its drift-guard fixture must be updated in the same change.
"/orders/web": "BO_WEB_ORDERS",
// (openspec/changes/add-refund-requests, BABYBOO-26): seeded module row 'BO_REFUND_REQUESTS'
// (id 44300000, url /orders/refunds, icon 'Undo2') under the same nav group (40470000). Also in
// mobile-api AdminModuleService.PROTECTED_NAMES and its drift-guard fixture; mobile-api enforces
// the same module server-side on every /api/admin/refunds call (refunds move money).
"/orders/refunds": "BO_REFUND_REQUESTS",
// babyboo-56-warranty-claims: module id 46000000 (url /orders/warranty-claims), same nav group.
"/orders/warranty-claims": "BO_WARRANTY_CLAIMS",
// (openspec/changes/add-branch-counter-sale): the seeded Area-'BO' module row is named
// 'BO_COUNTER' (url /pos/counter, icon 'Store') for the branch counter (recorded-tender,
// no-event) POS page. The gate must use that seeded `name` value, never a desc label —
// hasModule matches name/url only. The /pos/counter page is wrapped in RequireModule;
// super-admin bypasses module-role gating consistently with the other BO modules. This
// addition makes BO_COUNTER a route-gated (and therefore protected) module name via
// protectedModules.ts (PROTECTED_MODULE_NAMES derives from this map) — the mobile-api
// AdminModuleService.PROTECTED_NAMES list and its drift-guard fixture must be updated in the
// same change.
"/pos/counter": "BO_COUNTER",
// Task 12 (openspec/changes/add-member-kyc): the seeded module row is
// 'BO_KYC' (id 44200000, url /members/knowYourCustomer, icon 'ShieldCheck' under the BO
// root 40000000). The gate must use that seeded `name` value, never a desc label —
// hasModule matches name/url only. The /members/knowYourCustomer page is wrapped in
// RequireModule; super-admin bypasses module-role gating consistently with the other
// BO modules. This addition makes BO_KYC a route-gated (and therefore protected) module
// name — PROTECTED_NAMES in solvway-mobile-api AdminModuleService must be updated in the
// same change.
"/members/knowYourCustomer": "BO_KYC",
// BABYBOO-22 (openspec/changes/add-promotions-campaigns): seeded module 'BO_PROMOTIONS' (url /promotions).
// Route-gated, so it is also in mobile-api AdminModuleService.PROTECTED_NAMES.
"/promotions": "BO_PROMOTIONS",
// add-gift-card-core: seeded module BO_GIFT_CARDS (id 45000000, url /gift-cards).
"/gift-cards": "BO_GIFT_CARDS",
// add-product-reviews: seeded module 'BO_PRODUCT_REVIEWS' (id 44800000, url /product-reviews, icon 'Star'). Route-gated, so also in mobile-api AdminModuleService.PROTECTED_NAMES.
"/product-reviews": "BO_PRODUCT_REVIEWS",
// add-admin-online-payments: seeded module 'BO_ONLINE_PAYMENTS' (url /online-payments).
// Route-gated, so it is also in mobile-api AdminModuleService.PROTECTED_NAMES.
"/online-payments": "BO_ONLINE_PAYMENTS",
// add-member-messaging: seeded module 'BO_MEMBER_MESSAGES' (id 44600000, url /member-messages, icon
// 'MessagesSquare'; BO_MESSAGES /messages is the translation catalog, a different module). Route-gated, so
// it must also be added to mobile-api AdminModuleService.PROTECTED_NAMES in the same change.
"/member-messages": "BO_MEMBER_MESSAGES",
// BABYBOO-43 add-rank-referral-module: seeded module 'BO_RANK_REFERRAL' (id 45800000, url
// /rank-referral, icon 'Wrench'). Route-gated, so it is also in mobile-api
// AdminModuleService.PROTECTED_NAMES.
"/rank-referral": "BO_RANK_REFERRAL",
"/member-messages/broadcast": "BO_MEMBER_MESSAGES",
"/member-messages/broadcasts": "BO_MEMBER_MESSAGES",
};
export function requiredModuleFor(pathname: string): string | undefined {
return ROUTE_MODULES[pathname];
}
// Routes open to a user holding ANY one of several modules (merge-inventory-page). Each module
// then gates its own part of the page with hasModule.
export const ROUTE_ANY_MODULES: Record<string, readonly string[]> = {
"/inventory": INVENTORY_MODULE_NAMES,
// add-stock-count-event-closeout: a stock count detail page needs the count or the approve module.
"/inventory/stock-counts": [INVENTORY_MODULES.count, INVENTORY_MODULES.countApprove],
};
export function requiredModulesFor(pathname: string): readonly string[] | undefined {
const single = ROUTE_MODULES[pathname];
return ROUTE_ANY_MODULES[pathname] ?? (single ? [single] : undefined);
}