44 KiB
Refactor Plan — Priority 1 (actions/index.js split)
Last updated: 2026-03-13
Handover note (2026-03-13)
- Import-migration wave from
actionsbarrel to focused modules has been checked in and completed via PR. - Next chunk will be delivered from a new branch and should start at legacy decomposition.
Next branch kickoff scope (Phase 5)
Primary objective: split actions/services/legacyActionsService.js into smaller direct implementations while preserving function signatures.
Recommended first slice:
- Extract reference/search internals from
legacyActionsService.jsinto dedicated modules. - Keep
actions/services/*exports stable and route through new direct implementations. - Add focused parity checks per extracted function group (inputs, headers, hash behavior, return shapes).
Then continue with:
- Portal/document extraction in small batches.
- Remove dead wrappers from
legacyActionsService.jsonce call paths are fully migrated.
Phase 5 slice roadmap (completed)
Status key: [x] done, [ ] pending
[x]Search + reference direct extractionsearchDirectService.js,referenceDataDirectService.jssearchService.js/referenceDataService.jsre-pointed
[x]Document direct extraction- create
documentDirectService.js - re-point
documentService.js - parity checks: blob paths/hash behavior/return shapes
- create
[x]Portal direct extraction- create
portalDirectService.js - re-point
portalService.js - parity checks: watched-case and completion-message flows
- create
[x]Account + case direct extraction- create
accountDirectService.js,caseDirectService.js - re-point grouped services
- create
[x]Notify + integration + admin direct extraction- create
notifyDirectService.js,integrationDirectService.js,adminDirectService.js
- create
[x]Legacy slim-down pass- remove dead wrappers from
legacyActionsService.js - keep only temporary compatibility exports still required
- remove dead wrappers from
[x]Final cleanup + validation pass- grep checks for remaining
./legacyActionsServiceimports - lint/manual smoke checks
- grep checks for remaining
Phase 5 completion snapshot (2026-03-13)
- All grouped service modules now route through focused direct modules under
actions/services/*DirectService.js. actions/services/legacyActionsService.jshas been removed.- Verification completed:
actions/servicesscan returns zero./legacyActionsServiceimports.npm run lintcompletes with warnings only.npm run buildcompletes successfully.
Next phase kickoff recommendation
Focus on post-split hardening and cleanup:
- Add parity-focused tests for extracted direct services and
actions/services/index.jsexport stability. - Consolidate repeated axios/error-handling patterns into shared clients/utilities where safe.
- Reduce verbose debug logging in direct services (especially account/case/document paths) with redaction discipline.
- Run targeted manual smoke matrix for search/case/myportal/document/notify with EN/CY parity checks.
Phase 6 completion snapshot (2026-03-13)
Status key: [x] done, [ ] pending
[x]Add parity-focused tests for extracted services and barrel stabilitytests/phase6/service-parity.test.cjs- validates grouped/direct service export parity
- validates
actions/services/index.jsexport stability
[x]Reduce repeated axios/error-handling patterns safely- added shared helper:
actions/services/httpServiceUtils.js - adopted in selected direct modules without signature/return-shape changes
- added shared helper:
[x]Logging cleanup in sensitive direct-service flows- removed noisy debug logs from search/document/portal/case/admin direct services
[x]Add focused behavioural contract tests in current phasetests/phase6/service-behaviour.test.cjs- success/error contract checks with mocked axios/logger (8/8 passing)
[x]Run targeted validation/smoke checks- parity test: pass
- behavioural test: pass
- manual smoke matrix executed (search/case/myportal/document/notify, EN/CY + negative paths)
Notes:
- Known pre-existing caveat during smoke checks:
/searchresultsand/cy/searchresultsreturn 500 in local dev due SSR serialization issue (initialState.search.searchStringundefined).- treated as existing issue, not introduced by this refactor phase.
Future requirements / next-phase backlog (post-Phase-6)
- Investigate and fix
/searchresultsSSR serialization issue (EN/CY parity). - Expand behavioural service tests to remaining domains:
- document
- portal
- account
- notify
- integration
- Add focused negative-path tests for token/hash/relay-sensitive handlers.
- Continue small-batch hardening with reversible commits and parity checks per batch.
- Prepare PR evidence bundle for each increment:
- lint + test commands
- behavioural/parity test outputs
- manual EN/CY + negative-path smoke matrix
Phase 7 completion snapshot (2026-03-13)
Status key: [x] done, [ ] pending
[x]Create new branch fromorigin/SIPS-Developmentwith required work item prefix- branch:
TASK21988a-phase7-postphase6-hardening
- branch:
[x]Fix pre-existing/searchresultsSSR serialization issue with EN/CY parity- updated
pages/searchresults.js:setSearch(query.q)->setSearch(query?.q || "")
- updated
[x]Expand behavioural tests to remaining service domains- added
tests/phase7/service-behaviour.test.cjs - coverage includes: document, portal, account, notify, integration
- added
[x]Add feasible negative-path tests for token/hash/relay-sensitive flows- validated hashed path composition (e.g.,
hashAPIPathusage) - validated existing function error contracts (undefined/error string/rethrow)
- validated hashed path composition (e.g.,
[x]Execute validation bundlenode tests/phase6/service-parity.test.cjs-> passnode tests/phase6/service-behaviour.test.cjs-> pass (8/8)node tests/phase7/service-behaviour.test.cjs-> pass (10/10)npm run lint-> warnings only (no new errors)
[x]Execute targeted manual smoke matrix (EN/CY + negative paths)- local server on
localhost:3001(3000 occupied) /searchresults,/cy/searchresults-> 200/case,/cy/case-> 200/myportal,/cy/myportal-> 307 ->/auth/signin/api/file/getbloblistproxy?container=test&casefolderID=test-> 400POST /api/email/notifywith{}-> 400
- local server on
Phase 7 rollback notes
- Revert
pages/searchresults.jsfallback change if search behaviour regresses unexpectedly. - Remove
tests/phase7/service-behaviour.test.cjsif test scope needs to be rolled back. - Reset branch to pre-Phase-7 commit if full rollback required.
Phase 8 completion snapshot (2026-03-13)
Status key: [x] done, [ ] pending
[x]Create new branch fromorigin/SIPS-Developmentwith required work item prefix- branch:
TASK22017-phase8-hardening-slice
- branch:
[x]Re-enable/enforce hash validation in 4 sensitive target handlerspages/api/file/deleteblobcase.jspages/api/file/deleteblobrep.jspages/api/file/createappealcompletemessage_api.jspages/api/endpoint/getportallogin_api.js
[x]Standardize negative-path behavior for invalid/missing hash and required keys- added early 400 guards for missing required query params where applicable
- preserved response-shape contracts/signatures
[x]Improve logging discipline in sensitive flow- removed noisy direct console output in
createappealcompletemessage_api - routed updated error path logging via
consoleLogger
- removed noisy direct console output in
[x]Keep caller behavior compatible after hash re-enforcementactions/services/documentDirectService.jsnow appends hash for:deleteblobcasedeleteblobrep
actions/services/portalDirectService.jsnow appends hash for:createappealcompletemessage_api(existing hash-path contract retained)
[x]Add focused Phase 8 tests- added
tests/phase8/service-behaviour.test.cjs - includes negative-path coverage for all 4 target handlers
- includes one valid-hash happy-path contract check (
getportallogin_api) via mocks
- added
[x]Execute validation bundlenode tests/phase6/service-parity.test.cjs-> passnode tests/phase6/service-behaviour.test.cjs-> pass (8/8)node tests/phase7/service-behaviour.test.cjs-> pass (10/10)node tests/phase8/service-behaviour.test.cjs-> pass (5/5)npm run lint-> warnings only (pre-existing react-hooks dependency warnings)
[x]Execute manual HTTP negative-path matrix + feasible happy-path spot-check- invalid/missing hash across 4 target handlers -> 400
- missing required params where tested -> 400
- valid-hash
getportallogin_apispot-check returned 400 in local env due upstream relay/CRM dependency
Phase 8 rollback notes
- Revert these files to rollback the full hardening slice:
pages/api/file/deleteblobcase.jspages/api/file/deleteblobrep.jspages/api/file/createappealcompletemessage_api.jspages/api/endpoint/getportallogin_api.jsactions/services/documentDirectService.jsactions/services/portalDirectService.jstests/phase8/service-behaviour.test.cjs
- Re-run phase6/phase7 baseline tests and lint after rollback to confirm parity.
Phase 9 completion snapshot (2026-03-13)
Status key: [x] done, [ ] pending
[x]Create new branch fromorigin/SIPS-Developmentwith required work item prefix- branch:
TASK22019-phase-9-hardening
- branch:
[x]Re-enable/enforce hash validation in 4 additional sensitive file handlerspages/api/file/createrepcompletemessage_api.jspages/api/file/upload.jspages/api/file/uploadsinglefile.jspages/api/file/setupcontainer.js
[x]Standardize negative-path behavior for invalid/missing hash and key params- added early 400 handling for missing required query/body values where applicable
[x]Improve logging discipline in sensitive paths- removed noisy direct console logging in touched handlers
[x]Keep caller behavior compatible after hash re-enforcementactions/services/portalDirectService.jssendRepCompleteMessagenow appends hash
actions/services/documentDirectService.js- upload-related calls now append hash
[x]Add focused Phase 9 tests- added
tests/phase9/service-behaviour.test.cjs - negative-path tests for all 4 selected handlers
- added
[x]Execute validation bundlenode tests/phase6/service-parity.test.cjs-> passnode tests/phase6/service-behaviour.test.cjs-> pass (8/8)node tests/phase7/service-behaviour.test.cjs-> pass (10/10)node tests/phase8/service-behaviour.test.cjs-> pass (5/5)node tests/phase9/service-behaviour.test.cjs-> pass (5/5)npm run lint-> warnings only (no new lint errors)
[x]Execute manual HTTP negative-path matrix- missing/invalid hash checks across selected handlers -> 400
- missing key params where tested -> 400
[x]Valid-hash HTTP happy-path spot-checkPOST /api/file/uploadsinglefile?hash=<valid>-> 200 (hash generated from.env.localkey)
Phase 9 rollback notes
- Revert these files to rollback the full hardening slice:
pages/api/file/createrepcompletemessage_api.jspages/api/file/upload.jspages/api/file/uploadsinglefile.jspages/api/file/setupcontainer.jsactions/services/portalDirectService.jsactions/services/documentDirectService.jstests/phase9/service-behaviour.test.cjs
- Re-run phase6/phase7/phase8/phase9 baseline tests and lint after rollback to confirm parity.
Phase 10 completion snapshot (2026-03-13)
Status key: [x] done, [ ] pending
[x]Continue connected hardening slices on same branch- branch:
TASK22019-phase-9-hardening
- branch:
[x]Re-enable/standardize hash + param guard handling in 4 additional file retrieval handlerspages/api/file/getawaitingsubmissionfromblob.jspages/api/file/getprogressobjblob.jspages/api/file/getbloblist.jspages/api/file/getrepsblob.js
[x]Standardize negative-path behavior- added explicit early 400 for missing required query/hash values
- standardized early 400 for hash mismatch
[x]Improve logging discipline in touched handlers- removed old commented debug traces
[x]Add focused Phase 10 tests- added
tests/phase10/service-behaviour.test.cjs - includes negative-path tests for all 4 handlers
- added
[x]Execute validation bundlenode tests/phase6/service-parity.test.cjs-> passnode tests/phase6/service-behaviour.test.cjs-> pass (8/8)node tests/phase7/service-behaviour.test.cjs-> pass (10/10)node tests/phase8/service-behaviour.test.cjs-> pass (5/5)node tests/phase9/service-behaviour.test.cjs-> pass (5/5)node tests/phase10/service-behaviour.test.cjs-> pass (5/5)npm run lint-> warnings only (no new lint errors)
[x]Execute manual HTTP negative-path matrix + valid-hash spot-check- missing hash across selected handlers -> 400
- valid hash
getbloblistspot-check -> 500 (downstream/local dependency)
Phase 10 rollback notes
- Revert these files to rollback the full hardening slice:
pages/api/file/getawaitingsubmissionfromblob.jspages/api/file/getprogressobjblob.jspages/api/file/getbloblist.jspages/api/file/getrepsblob.jstests/phase10/service-behaviour.test.cjs
- Re-run phase6/phase7/phase8/phase9/phase10 baseline tests and lint after rollback to confirm parity.
Phase 11 completion snapshot (2026-03-13)
Status key: [x] done, [ ] pending
[x]Continue connected hardening slices on same branch- branch:
TASK22019-phase-9-hardening
- branch:
[x]Re-enable/standardize hash + param guard handling in additional sensitive handlerspages/api/file/getbloblist.jspages/api/file/deleteblob.jspages/api/file/deleteawaitingsubmissionfromblob.js
[x]Standardize negative-path behavior- added explicit early 400 for missing required query/hash values
- standardized early 400 for hash mismatch
[x]Improve logging discipline in touched handlers- removed old commented debug traces
[x]Add focused Phase 11 tests- added
tests/phase11/service-behaviour.test.cjs - includes negative-path tests for selected handlers
- added
[x]Execute validation bundlenode tests/phase6/service-parity.test.cjs-> passnode tests/phase6/service-behaviour.test.cjs-> pass (8/8)node tests/phase7/service-behaviour.test.cjs-> pass (10/10)node tests/phase8/service-behaviour.test.cjs-> pass (5/5)node tests/phase9/service-behaviour.test.cjs-> pass (5/5)node tests/phase10/service-behaviour.test.cjs-> pass (5/5)node tests/phase11/service-behaviour.test.cjs-> pass (4/4)npm run lint-> warnings only (no new lint errors)
[x]Execute manual HTTP negative-path matrix + valid-hash spot-check- missing/invalid hash across selected handlers -> 400
- valid hash
getbloblistspot-check -> 500 (downstream/local dependency)
Phase 11 rollback notes
- Revert these files to rollback the full hardening slice:
pages/api/file/getbloblist.jspages/api/file/deleteblob.jspages/api/file/deleteawaitingsubmissionfromblob.jstests/phase11/service-behaviour.test.cjs
- Re-run phase6/phase7/phase8/phase9/phase10/phase11 baseline tests and lint after rollback to confirm parity.
Phase 12 completion snapshot (2026-03-13)
Status key: [x] done, [ ] pending
[x]Continue connected hardening slices on same branch- branch:
TASK22019-phase-9-hardening
- branch:
[x]Re-enable/standardize hash + param guard handling in additional sensitive handlerspages/api/file/downloadblob.jspages/api/file/getbloblistproxy.jspages/api/file/getrepsblobproxy.jspages/api/file/getawaitingsubmissionfromblobproxy.js
[x]Standardize negative-path behavior- added explicit early 400 for missing required query/hash values
- standardized early 400 for hash mismatch in
downloadblob
[x]Add focused Phase 12 tests- added
tests/phase12/service-behaviour.test.cjs - includes negative-path tests for selected handlers
- added
[x]Execute validation bundlenode tests/phase6/service-parity.test.cjs-> passnode tests/phase6/service-behaviour.test.cjs-> pass (8/8)node tests/phase7/service-behaviour.test.cjs-> pass (10/10)node tests/phase8/service-behaviour.test.cjs-> pass (5/5)node tests/phase9/service-behaviour.test.cjs-> pass (5/5)node tests/phase10/service-behaviour.test.cjs-> pass (5/5)node tests/phase11/service-behaviour.test.cjs-> pass (4/4)node tests/phase12/service-behaviour.test.cjs-> pass (4/4)npm run lint-> warnings only (no new lint errors)
[x]Execute manual HTTP negative-path matrix + valid-hash spot-check- missing/invalid inputs across selected handlers -> 400
- valid hash
downloadblobspot-check -> 500 (downstream/local dependency)
Phase 12 rollback notes
- Revert these files to rollback the full hardening slice:
pages/api/file/downloadblob.jspages/api/file/getbloblistproxy.jspages/api/file/getrepsblobproxy.jspages/api/file/getawaitingsubmissionfromblobproxy.jstests/phase12/service-behaviour.test.cjs
- Re-run phase6/phase7/phase8/phase9/phase10/phase11/phase12 baseline tests and lint after rollback to confirm parity.
Phase 13 completion snapshot (2026-03-13)
Status key: [x] done, [ ] pending
[x]Continue connected hardening slices on same branch- branch:
TASK22019-phase-9-hardening
- branch:
[x]Re-enable/standardize hash + param guard handling in additional sensitive handlerspages/api/file/deleteblobcase.jspages/api/file/deleteblobrep.jspages/api/file/createcaseinvolvement_api.jspages/api/file/createrepinvolvement_api.js
[x]Standardize negative-path behavior- added explicit early 400 for missing required query/hash/body values
- standardized early 400 for hash mismatch in delete handlers
[x]Improve logging discipline in touched handlers- removed noisy body/query logging in involvement handlers
[x]Add focused Phase 13 tests- added
tests/phase13/service-behaviour.test.cjs - includes negative-path tests and valid-input mocked happy paths
- added
[x]Execute validation bundlenode tests/phase6/service-parity.test.cjs-> passnode tests/phase6/service-behaviour.test.cjs-> pass (8/8)node tests/phase7/service-behaviour.test.cjs-> pass (10/10)node tests/phase8/service-behaviour.test.cjs-> pass (5/5)node tests/phase9/service-behaviour.test.cjs-> pass (5/5)node tests/phase10/service-behaviour.test.cjs-> pass (5/5)node tests/phase11/service-behaviour.test.cjs-> pass (4/4)node tests/phase12/service-behaviour.test.cjs-> pass (4/4)node tests/phase13/service-behaviour.test.cjs-> pass (7/7)npm run lint-> warnings only (no new lint errors)
[x]Execute manual HTTP negative-path matrix + valid-hash spot-check- missing/invalid inputs across selected handlers -> 400
- valid hash
deleteblobcasespot-check -> 500 (downstream/local dependency)
Phase 13 rollback notes
- Revert these files to rollback the full hardening slice:
pages/api/file/deleteblobcase.jspages/api/file/deleteblobrep.jspages/api/file/createcaseinvolvement_api.jspages/api/file/createrepinvolvement_api.jstests/phase13/service-behaviour.test.cjs
- Re-run phase6/phase7/phase8/phase9/phase10/phase11/phase12/phase13 baseline tests and lint after rollback to confirm parity.
Phase 14 completion snapshot (2026-03-13)
Status key: [x] done, [ ] pending
[x]Diagnose authenticated browser journey runtime error- traced to client-side
hashAPIPathusage reading server-onlyHASHKEY
- traced to client-side
[x]Implement minimal reversible signing bridge- added
pages/api/endpoint/gethash_api.js - session-gated with allow-listed API path prefixes
- added
[x]Keep client/service contracts stable- updated
documentDirectServiceandportalDirectServiceto request hash from signer endpoint - kept server-side fallback hashing only when env key exists
- updated
[x]Add focused phase-14 tests- added
tests/phase14/service-behaviour.test.cjs - covers 400/401 negative paths and authenticated happy path
- added
[x]Execute validation bundle- phase6–phase14 test set all pass
- lint warnings only (pre-existing)
Phase 14 rollback notes
- Revert these files to rollback the fix slice:
pages/api/endpoint/gethash_api.jsactions/services/documentDirectService.jsactions/services/portalDirectService.jstests/phase14/service-behaviour.test.cjs
- Re-run phase6–phase14 tests + lint after rollback.
Phase 14 closeout follow-up snapshot (2026-03-13)
Status key: [x] done, [ ] pending
[x]Expand signer usage to remaining browser-sensitive hashed call in account domainactions/services/accountDirectService.jsgetPortalLoginnow requests hash from authenticated signer endpoint
[x]Extend signer allow-list minimally for required routepages/api/endpoint/gethash_api.js- added
/api/endpoint/getportallogin_apionly
[x]Preserve and verify behavioural contract coveragetests/phase7/service-behaviour.test.cjsupdated for signer flowtests/phase14/service-behaviour.test.cjsextended with allow-list path test
[x]Apply runtime-discovered contract alignment fixes (minimal/reversible)pages/api/file/getrepsblob.js- removed unnecessary
casefolderIDrequirement to match endpoint contract
- removed unnecessary
components/elements/index.js- restored missing
updateLinksimport for Quill path
- restored missing
[x]Re-run required validation- phase6 parity + behaviour -> pass
- phase7/8/9/10/11/12/13/14 behaviour -> pass
- lint -> warnings only (pre-existing)
[x]Push branch for review continuityTASK22019-phase-9-hardeningpushed to origin
Phase 14 closeout follow-up rollback notes
- Revert
6094874to remove portal-login signer migration and tests. - Revert
b8fa514to remove getrepsblob contract-alignment + Quill import fix. - Re-run phase6–phase14 tests and lint after rollback.
Phase 15 completion snapshot (2026-03-13)
Status key: [x] done, [ ] pending
[x]Create new branch fromorigin/SIPS-Developmentwith required work item prefix- branch:
TASK22028-phase15-hardening-slice
- branch:
[x]Apply minimal consistency-only hardening in 4 additional sensitive handlerspages/api/file/upload.jspages/api/file/uploadsinglefile.jspages/api/file/createappealcompletemessage_api.jspages/api/file/setupcontainer.js
[x]Standardize negative-path behavior- explicit early 400 for missing/invalid hash in selected handlers
- explicit missing required-input checks where route contract requires them
- preserved response-shape contracts and function signatures
[x]Add focused Phase 15 tests- added
tests/phase15/service-behaviour.test.cjs - includes negative-path tests for missing/invalid hash + required-input checks
- includes one valid-hash mocked happy-path response-shape check
- added
[x]Execute required validation bundle- phase6 parity + phase6–phase14 behaviour tests -> pass
- phase15 behaviour tests -> pass
- lint -> warnings only (pre-existing)
[x]Execute targeted manual checks- missing/invalid hash across selected handlers -> 400
- missing required params where applicable -> 400
- valid-hash
setupcontainerspot-check -> 200
Phase 15 rollback notes
- Revert these files to rollback the full hardening slice:
pages/api/file/upload.jspages/api/file/uploadsinglefile.jspages/api/file/createappealcompletemessage_api.jspages/api/file/setupcontainer.jstests/phase15/service-behaviour.test.cjs
- Re-run phase6–phase15 baseline tests and lint after rollback to confirm parity.
Phase 16 completion snapshot (2026-03-13)
Status key: [x] done, [ ] pending
[x]Continue on current branch with separate commit for additional small slice- branch:
TASK22028-phase15-hardening-slice
- branch:
[x]Apply minimal consistency hardening in 3 file proxy handlerspages/api/file/getbloblistproxy.jspages/api/file/getrepsblobproxy.jspages/api/file/getawaitingsubmissionfromblobproxy.js
[x]Standardize required-input guard pattern- added local
hasValuechecks for required params - removed unused/dead imports/constants in touched files
- added local
[x]Add focused Phase 16 tests- added
tests/phase16/service-behaviour.test.cjs - missing-input negative-path checks + one valid-input contract check
- added
[x]Execute validation bundle- phase6 parity + phase6–phase16 behaviour tests pass
- lint warnings only (pre-existing)
[x]Execute manual checks- missing required-input proxy calls -> 400
Phase 16 rollback notes
- Revert commit
c196edb(or files):pages/api/file/getbloblistproxy.jspages/api/file/getrepsblobproxy.jspages/api/file/getawaitingsubmissionfromblobproxy.jstests/phase16/service-behaviour.test.cjs
- Re-run phase6–phase16 baseline tests and lint.
Follow-up completion snapshot (2026-03-13)
[x]Address browser signer failure for delete-awaiting-submission path- added signer allow-list entry:
/api/file/deleteblobcase
- added signer allow-list entry:
[x]Add focused behavioural test coverage- extended
tests/phase14/service-behaviour.test.cjs
- extended
[x]Validate- phase14 behaviour tests pass (6/6)
- phase7 behaviour tests pass (10/10)
- lint warnings only (pre-existing)
Follow-up rollback notes
- Revert commit
49dd990to undo allow-list/test follow-up.
Follow-up completion snapshot (2026-03-13 — additional delete flows)
[x]Expand signer allow-list for required browser delete paths[x]Move remaining delete service calls to signer-based hash retrieval[x]Extend focused service/signer tests[x]Validate- phase7 behaviour tests pass (12/12)
- phase14 behaviour tests pass (9/9)
- lint warnings only (pre-existing)
Follow-up rollback notes (additional delete flows)
- Revert the follow-up commit for this slice to restore prior hashing behavior.
Follow-up completion snapshot (2026-03-13 — myportal + i18n alignment)
[x]Align myportal delete-representation calls to usecaseRef[x]Add missing i18n namespace mapping for/newappeal/[appealtypes][x]Validate- phase7 behaviour tests pass (12/12)
- lint warnings only (pre-existing)
Follow-up rollback notes (myportal + i18n alignment)
- Revert commit
d32d7d0to restore prior myportal/i18n state.
Phase 17 closeout snapshot (2026-03-13)
Status key: [x] done, [ ] pending
[x]Create new branch fromorigin/SIPS-Developmentwith required work item prefix- branch:
TASK22057-phase17-hardening-closeout
- branch:
[x]Complete remaining consistency-only hardening targets inpages/api/file/**pages/api/file/generatepdf.jspages/api/file/generateappealpdf.jspages/api/file/createappealcompletemessageproxy_api.js
[x]Standardize negative-path behavior and logging discipline- explicit early 400 guards for missing/invalid hash where applicable
- explicit early 400 guards for missing required params where applicable
- noisy direct logs removed from touched handlers
- response-shape/signature contracts preserved
[x]Add focused Phase 17 tests- added
tests/phase17/service-behaviour.test.cjs - includes missing/invalid hash negative-path checks
- includes missing required-param checks
- includes valid-input happy-path check for proxy contract
- added
[x]Execute required validation bundle- phase6 parity + phase6–phase17 behaviour tests -> pass
- lint -> warnings only (pre-existing)
[x]Consistency scan for remainingpages/api/**- no additional broad hash/400 consistency gaps identified in
pages/api/endpoint/**during this pass
- no additional broad hash/400 consistency gaps identified in
Phase 17 rollback notes
- Revert these files to rollback the full closeout slice:
pages/api/file/generatepdf.jspages/api/file/generateappealpdf.jspages/api/file/createappealcompletemessageproxy_api.jstests/phase17/service-behaviour.test.cjs
- Re-run phase6–phase17 baseline tests and lint after rollback to confirm parity.
Phase 18 additional consolidation slices snapshot (2026-03-14)
Status key: [x] done, [ ] pending
[x]Confirm requested scope expansion to implement all 3 additional slices[x]Apply endpoint logging/input hygiene slicepages/api/endpoint/deletewatchedcases_api.jspages/api/endpoint/getaccounts_api.jspages/api/endpoint/getbasicsearchpaged_api.jspages/api/endpoint/getappealpdfdocuments_api.js
[x]Apply file hash-guard flow consistency slicepages/api/file/deleteblob.jspages/api/file/deleteawaitingsubmissionfromblob.jspages/api/file/getprogressobjblob.jspages/api/file/getbloblist.js
[x]Apply create/update input-guard + logging hygiene slicepages/api/file/createcase_api.jspages/api/file/updatecase_api.jspages/api/file/editRepJson.js
[x]Add focused phase-18 behavioural tests- added
tests/phase18/service-behaviour.test.cjs - negative-path coverage for required inputs/hash
- contract-preserving happy-path checks on selected handlers
- added
[x]Execute validation bundle- phase6 parity + phase6–phase18 behavioural tests all pass
- lint warnings only (pre-existing
react-hooks/exhaustive-depsset)
Phase 18 rollback notes
- Revert files in this slice:
pages/api/endpoint/deletewatchedcases_api.jspages/api/endpoint/getaccounts_api.jspages/api/endpoint/getbasicsearchpaged_api.jspages/api/endpoint/getappealpdfdocuments_api.jspages/api/file/deleteblob.jspages/api/file/deleteawaitingsubmissionfromblob.jspages/api/file/getprogressobjblob.jspages/api/file/getbloblist.jspages/api/file/createcase_api.jspages/api/file/updatecase_api.jspages/api/file/editRepJson.jstests/phase18/service-behaviour.test.cjs
- Re-run phase6–phase18 baseline tests and lint after rollback to confirm parity.
Phase 19 endpoint consistency slice snapshot (2026-03-14)
Status key: [x] done, [ ] pending
[x]Apply small consistency-only endpoint hardening in selected handlerspages/api/endpoint/createwatchedcases_api.jspages/api/endpoint/getappealtypes_api.jspages/api/endpoint/getdnslist_api.js
[x]Standardize negative-path required input handling- early 400 on missing/malformed required
@odata.bindvalues increatewatchedcases_api
- early 400 on missing/malformed required
[x]Remove noisy sensitive-path logging- removed direct query logging in appeal-types and dns-list handlers
[x]Add focused teststests/phase19/service-behaviour.test.cjs(5/5)
[x]Execute validation bundle- phase6 parity + phase6–phase19 behavioural suites pass
- lint warnings only (pre-existing)
Phase 19 rollback notes
- Revert files in this slice:
pages/api/endpoint/createwatchedcases_api.jspages/api/endpoint/getappealtypes_api.jspages/api/endpoint/getdnslist_api.jstests/phase19/service-behaviour.test.cjs
- Re-run phase6–phase19 baseline tests and lint after rollback.
Phase 20 endpoint consistency slice snapshot (2026-03-14)
Status key: [x] done, [ ] pending
[x]Apply small consistency-only endpoint hardening in selected handlerspages/api/endpoint/getbasicdnssearch_api.jspages/api/endpoint/getbasicdnsurlsearch_api.jspages/api/endpoint/getbasicsearchdetailspaged_api.js
[x]Standardize negative-path required input handling- early 400 for missing/empty
searchStringingetbasicdnsurlsearch_api - early 400 for missing required params in
getbasicsearchdetailspaged_api
- early 400 for missing/empty
[x]Remove noisy sensitive-path logging- removed direct query logging in
getbasicdnssearch_api
- removed direct query logging in
[x]Add focused teststests/phase20/service-behaviour.test.cjs(5/5)
[x]Execute validation bundle- phase6 parity + phase6–phase20 behavioural suites pass
- lint warnings only (pre-existing)
Phase 20 rollback notes
- Revert files in this slice:
pages/api/endpoint/getbasicdnssearch_api.jspages/api/endpoint/getbasicdnsurlsearch_api.jspages/api/endpoint/getbasicsearchdetailspaged_api.jstests/phase20/service-behaviour.test.cjs
- Re-run phase6–phase20 baseline tests and lint after rollback.
Safe execution mode for migration chunks (required)
To reduce terminal hangs during bulk migration work, run refactor chunks in safe stepwise mode instead of long chained commands.
Required command pattern:
- Read/inspect target files.
- Apply edits only.
- Verify with targeted grep for remaining broad imports.
- Check
git status. - Stage files.
- Commit.
- Re-run verification and then continue to the next chunk.
Rules:
- Do not combine edit + verify + add + commit + log in one long chained command.
- Keep each terminal call short and single-purpose.
- If a command is interrupted, re-check
git statusand resume from the next incomplete step. - Preserve smallest viable diff and behavior parity.
Implementation status snapshot (2026-03-12)
- Phase 1 completed:
- Extracted core helpers into
actions/core/{env,logger,hash,token,headers}.js. - Moved wrapper functions into
actions/services/legacyActionsService.js. - Reduced
actions/index.jsto compatibility barrel re-exports. - Added
actions/clients/README.mdscaffold for upcoming client extraction.
- Extracted core helpers into
- Validation status:
npm run lintcurrently fails at framework/tooling option level (legacy ESLint options), not due to this refactor logic.- Manual test matrix is required next (search/case/myportal/auth/notify/file).
Implementation status snapshot (Phase 2 update — 2026-03-12)
- Phase 2 completed:
- Added grouped service modules under
actions/services/:searchService.jscaseService.jsaccountService.jsportalService.jsdocumentService.jsreferenceDataService.jsnotifyService.jsadminService.jsintegrationService.js
- Added
actions/services/index.jsbarrel. - Updated
actions/index.jsto export from./servicesand./core/*. - Verified export parity: all
legacyActionsServiceexports are represented by grouped service modules.
- Added grouped service modules under
- Current compatibility model:
- Consumers can continue importing from
../actionswith unchanged function names/signatures. legacyActionsServiceremains an internal compatibility implementation module until Phase 3 consumer migration.
- Consumers can continue importing from
Implementation status snapshot (Phase 3 update — 2026-03-12)
- Phase 3 started with targeted consumer migration to focused imports.
- Updated high-churn consumers:
components/case/summary.jscreateWatchedCases,deleteWatchedCases,getWatchedCasesProxy,setCaseInvolvment->actions/services/portalServicegetLinkedCases->actions/services/searchServicegetPortalModuleDetailsProxy->actions/services/caseService
pages/api/email/notify.jsconsoleLogger->actions/core/loggergetPreferredLanguage->actions/services/accountService
- Updated selected endpoint handlers to core imports:
pages/api/endpoint/getwatchedcases_api.jspages/api/endpoint/getadvancedsearchpaged_api.jspages/api/endpoint/getpreferredlanguage_api.jspages/api/endpoint/createcrmtask_api.js
- Compatibility remains preserved via
actions/index.jsbarrel while migration proceeds incrementally.
Implementation status snapshot (Phase 4 update — 2026-03-12)
- Phase 4 started with targeted hardening helpers and sensitive-path adoption.
- Added
actions/core/guards.jswith:isNonEmptyStringsanitizeStringescapeODataString
- Expanded
actions/core/logger.jswith redaction support:redactSensitive- masking for likely email/token/secret patterns in logged content
- Updated
actions/index.jscompatibility barrel to export./core/guards. - Applied hardening in selected sensitive/high-churn handlers:
pages/api/email/notify.js- email input sanitization + required-field guard
- redacted logging for outbound payload diagnostics
pages/api/endpoint/getpreferredlanguage_api.js- sanitized/validated
emailAddress - OData string escaping for query construction
- redacted query logging
- sanitized/validated
pages/api/endpoint/createcrmtask_api.js- sanitized/validated request inputs for subject/email/body
- centralized structured error logging via
consoleLogger
Implementation status snapshot (Priority 1 execution pass — 2026-03-12)
- Completed another targeted consumer migration pass from broad
actionsbarrel imports to focused service/core imports in these files:components/admin/tabs/documents.jscomponents/admin/tabs/storage.jscomponents/admin/utils/serverside.jscomponents/case/documents.jscomponents/case/representation/representationComplete.jscomponents/case/representation/representationElements.jscomponents/elements/index.jscomponents/myportal/awaitingsubmissionfromblob.jscomponents/myportal/topthree.jscomponents/myportal/topthree_reps.jscomponents/utils/index.jslib/myportal/loadMyPortalAppealPage.jslib/newappeal/loadNewAppealPage.js
- Kept compatibility behavior via existing
actions/index.jsbarrel. - Validation note:
npm run lintremains blocked by repository ESLint/Next option incompatibility (pre-existing tooling configuration).
Goal
Reduce coupling and regression risk by splitting actions/index.js into focused modules while preserving existing behavior and call signatures during migration.
Why this is first
actions/index.js is currently a high-risk hotspot: API wrappers, relay/hash helpers, token acquisition, logging, file helpers, and notification helpers are mixed in one module. This increases blast radius for every change.
Scope (planned)
- In scope:
- Module extraction and internal architecture cleanup.
- Backward-compatible export strategy.
- Migration plan for consumers under
components/**,pages/**, andpages/api/**.
- Out of scope (for this refactor phase):
- Functional changes to business logic.
- Contract changes to API handlers.
- Dependency swaps.
Proposed target structure
actions/
index.js # compatibility barrel (temporary)
core/
env.js # BASE_URL/API_ROOT/relay roots
logger.js # consoleLogger/conLog with redaction helpers
hash.js # hashAPIPath/hashString/dehashString
token.js # getToken + token request config
headers.js # azureHeaders* helpers
clients/
relayClient.js # signed relay calls + shared axios behavior
endpointClient.js # endpoint route wrappers
fileClient.js # file route wrappers
notifyClient.js # email/notify wrappers
services/
caseService.js
searchService.js
portalService.js
accountService.js
documentService.js
Notes:
- Keep
actions/index.jsas a façade initially to avoid breaking imports. - Move internals first, then update call sites incrementally.
Migration strategy (phased)
Phase 1 — Safe extraction with no consumer changes
- Create new modules under
actions/core/**andactions/clients/**. - Move utility functions (
hash,headers,token,logger, env helpers). - Re-export all existing functions from
actions/index.jsunchanged. - Verify parity with lint + smoke checks.
Phase 2 — Service grouping
- Group route wrapper functions into service modules by domain (case/search/portal/account/document).
- Keep identical function names/signatures.
- Add thin unit tests for pure helpers first (
hash,env, route builder helpers).
Phase 3 — Consumer migration
- Replace broad imports from
actions/index.jswith targeted imports from new modules. - Migrate high-churn areas first:
components/breadcrumbs.jscomponents/case/summary.jspages/api/email/notify.js- selected
pages/api/endpoint/**handlers
- Keep index barrel until migration completion.
Phase 4 — Harden + slim
- Introduce typed/validated request helper boundaries (JS doc + runtime guard checks).
- Remove dead exports and duplicate wrappers.
- Finalize redacted logging policy in sensitive flows.
Backward compatibility rules
- Do not change public function names/signatures during Phases 1–2.
- Keep return shapes identical unless explicitly planned and validated.
- Preserve existing hash and relay behavior contract.
- Preserve EN/CY behavior where helper functions influence locale-sensitive flows.
Validation plan
npm run lint- Manual smoke paths:
- search -> results -> case summary -> back nav
- myportal viewall -> case summary -> breadcrumb return path
- auth email sign-in flow
- notify new case reference language selection path
- file/document fetch paths touched by moved wrappers
- Negative-path checks:
- invalid hash or malformed query for sensitive handlers
- token acquisition failures and relay timeout handling
Regression tests and coverage plan (to add during implementation)
Test tooling recommendation
Current repo has no active automated test runner configured in package.json. For this refactor, introduce a minimal unit test setup (recommended: Jest) focused on pure logic first.
Suggested scripts:
test: run all unit teststest:watch: local watch modetest:coverage: coverage output for CI and PR evidence
Minimum tests for Priority 1
actions/core/hash.js- deterministic hash for known input
- query string handling (
?hash=vs&hash=) - malformed/edge inputs
actions/core/headers.js- expected OData/auth headers produced for each helper
actions/core/token.js- token request config generation
- success and error mapping behavior (mock axios)
actions/core/env.js- server vs browser base URL resolution
- compatibility barrel (
actions/index.js)- exports parity test to ensure existing function names remain available during migration
Integration-style safeguards (mocked external calls)
- Relay client request assembly test:
- signed URL includes hash
- token is attached
- timeout/error behavior is consistent
- Notify client wrapper test:
- language/template routing remains unchanged for PEDW-NEW-CASEREF path
Coverage targets for this refactor
actions/core/**: >= 90% lines/functionsactions/clients/**: >= 80% lines/functions- Global coverage gate for this phase: >= 70% (new tests only; avoid blocking unrelated legacy code)
Regression gate in PR
Required evidence for each phase:
npm run lintnpm run testnpm run test:coverage(attach summary)- Manual smoke matrix from this plan (search/case/myportal/auth/notify/file)
Risks and mitigations
- Risk: import breakage due to broad existing usage.
- Mitigation: keep compatibility barrel and migrate in small batches.
- Risk: hidden behavior differences from refactor-only moves.
- Mitigation: freeze signatures + add helper tests + run route smoke matrix each phase.
- Risk: sensitive logging leakage while touching shared helpers.
- Mitigation: centralize logger early and enforce redaction helper.
Definition of done (for this priority)
actions/index.jsreduced to compatibility exports only (minimal logic).- Core helper modules and service modules exist and are used by migrated consumers.
- Lint and manual validation matrix pass.
- Memory docs updated (
activeContext,progress,change-log).