- Added Cache-Control headers to various endpoints in CatalogController and SubscriptionsController to improve caching behavior and reduce server load. - Updated response structures to ensure consistent caching strategies across different API endpoints. - Improved overall performance by implementing throttling and caching mechanisms for better request management.
4.1 KiB
4.1 KiB
Proposal: Remove Unnecessary Normalizers
Problem
We have unnecessary abstraction layers that convert between identical data structures multiple times:
Frontend State → build*Selections() → OrderSelections → toSearchParams()
→ URLSearchParams → paramsToRecord() → normalizeSelections() → OrderSelections → BFF
Unnecessary Functions to Remove
1. packages/domain/orders/checkout.ts
Remove these:
buildInternetCheckoutSelections()- Lines 103-129deriveInternetCheckoutState()- Lines 134-156buildSimCheckoutSelections()- Lines 161-216deriveSimCheckoutState()- Lines 221-282coalescePlanSku()- Lines 81-97 (now obsolete after plan/planSku cleanup)normalizeString()- Lines 56-60normalizeSkuList()- Lines 62-71parseAddonList()- Lines 73-79- All Draft/Patch interfaces - Lines 10-54
Keep:
- Nothing from this file is needed in domain layer
2. apps/portal/src/features/catalog/services/catalog.store.ts
Simplify:
buildInternetCheckoutParams()- Lines 202-217buildSimCheckoutParams()- Lines 219-238selectionsToSearchParams()- Lines 124-136paramsToSelectionRecord()- Lines 114-122
Replace with: Direct URL param construction from state
What Frontend Should Do Instead
For Internet Checkout:
// BEFORE (current mess):
const selections = buildInternetCheckoutSelections({
planSku: internet.planSku,
accessMode: internet.accessMode,
installationSku: internet.installationSku,
addonSkus: internet.addonSkus,
});
return selectionsToSearchParams(selections, "internet");
// AFTER (clean):
const params = new URLSearchParams({
type: "internet",
planSku: internet.planSku,
accessMode: internet.accessMode,
installationSku: internet.installationSku,
addons: internet.addonSkus.join(","), // Only transform is array → CSV
});
return params;
For SIM Checkout:
// BEFORE:
const selections = buildSimCheckoutSelections({...});
return selectionsToSearchParams(selections, "sim");
// AFTER:
const params = new URLSearchParams();
params.set("type", "sim");
params.set("planSku", sim.planSku);
if (sim.simType) params.set("simType", sim.simType);
// ... only add non-empty values
return params;
For Restoring from Params:
// BEFORE:
const selections = normalizeOrderSelections(paramsToSelectionRecord(params));
const derived = deriveInternetCheckoutState(selections);
set({ internet: { ...state.internet, ...derived } });
// AFTER:
set({
internet: {
planSku: params.get("planSku") ?? undefined,
accessMode: params.get("accessMode") ?? undefined,
installationSku: params.get("installationSku") ?? undefined,
addonSkus: params.get("addons")?.split(",") ?? [],
}
});
Benefits
- Fewer lines of code - Remove ~300+ lines
- Clearer data flow - No mysterious transformations
- Better type safety - Direct property access, not dynamic string manipulation
- Easier debugging - Fewer layers to trace through
- Frontend owns frontend data - Domain layer isn't polluted with UI concerns
What Domain Layer SHOULD Have
Only these helpers:
normalizeOrderSelections(value: unknown): OrderSelections- Zod validation from API/paramsbuildOrderConfigurations(selections: OrderSelections): OrderConfigurations- Extract config from selections
That's it! Frontend handles its own URL param serialization.
Migration Plan
- Update catalog store to directly build URL params
- Update checkout param service to directly parse params
- Remove all build/derive functions from domain
- Remove Draft/Patch interfaces
- Test all checkout flows (Internet, SIM, VPN)
Files to Change
Remove entirely:
- Most of
packages/domain/orders/checkout.ts(keep only types if needed)
Simplify:
apps/portal/src/features/catalog/services/catalog.store.tsapps/portal/src/features/checkout/services/checkout-params.service.ts
Update imports in:
apps/portal/src/features/catalog/hooks/useInternetConfigure.tsapps/portal/src/features/catalog/hooks/useSimConfigure.ts- Any component using these functions