Files
orderPRO/.paul/phases/01-tech-debt/01-01-SUMMARY.md
Jacek Pyziak f8db8c0162 refactor(01-tech-debt): extract AllegroTokenManager and StringHelper
Phase 1 complete (2/2 plans):

- Plan 01-01: Extract AllegroTokenManager — OAuth token logic
  centralized from 4 classes into dedicated manager class

- Plan 01-02: Extract StringHelper — nullableString/normalizeDateTime/
  normalizeColorHex extracted from 15+ classes into App\Core\Support\StringHelper;
  removed 19 duplicate private methods

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-12 23:36:06 +01:00

117 lines
4.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
phase: 01-tech-debt
plan: 01
subsystem: auth
tags: [allegro, oauth, token-manager, refactor]
requires: []
provides:
- AllegroTokenManager — shared OAuth token resolver for all Allegro services
- Eliminated 4-way duplication of token refresh logic
affects: [allegro-integration, cron-jobs, shipments]
tech-stack:
added: []
patterns: [Shared service extraction — extract duplicated private methods into injected collaborator]
key-files:
created:
- src/Modules/Settings/AllegroTokenManager.php
modified:
- src/Modules/Settings/AllegroOrderImportService.php
- src/Modules/Settings/AllegroOrdersSyncService.php
- src/Modules/Settings/AllegroStatusDiscoveryService.php
- src/Modules/Shipments/AllegroShipmentService.php
- routes/web.php
- src/Core/Application.php
- .paul/codebase/CONCERNS.md
- DOCS/ARCHITECTURE.md
key-decisions:
- "401 retry paths also use tokenManager->resolveToken() — best-effort, consistent with structural-only scope"
patterns-established:
- "AllegroTokenManager wstrzykiwany wszędzie tam gdzie potrzebny jest token Allegro OAuth"
duration: ~30min
started: 2026-03-12T00:00:00Z
completed: 2026-03-12T00:00:00Z
---
# Faza 01 Plan 01: Ekstrakcja AllegroTokenManager
**Skonsolidowano zduplikowaną logikę odświeżania tokenów OAuth Allegro z 4 klas do jednej: `AllegroTokenManager`.**
## Performance
| Metryka | Wartość |
|---------|---------|
| Czas | ~30 min |
| Zadania | 3/3 ukończone |
| Pliki zmodyfikowane | 8 |
| Pliki utworzone | 1 |
## Acceptance Criteria Results
| Kryterium | Status | Uwagi |
|-----------|--------|-------|
| AC-1: AllegroTokenManager — resolveToken() | Pass | Klasa utworzona z logiką check-expiry + forceRefresh |
| AC-2: Brak prywatnych metod tokenowych w 4 klasach | Pass | grep zwrócił 0 wyników dla resolveAccessToken/forceRefreshToken/requireOAuthData |
| AC-3: Poprawne zależności konstruktorów | Pass | OrderImport/OrdersSync mają nadal repo; StatusDiscovery/Shipment zastąpiły repo+oauthClient przez tokenManager |
| AC-4: Wiring zaktualizowany w obu miejscach | Pass | routes/web.php i Application.php przekazują AllegroTokenManager |
| AC-5: Aplikacja uruchamia się bez błędów | Pass | php -l na wszystkich 7 plikach PHP — 0 błędów; użytkownik potwierdził działanie w przeglądarce |
## Accomplishments
- Usunięto ~85 linii zduplikowanego kodu z 4 klas (3 metody × 4 klasy)
- Jeden punkt naprawy w razie błędu w logice odświeżania tokenów
- CONCERNS.md HIGH item #1 usunięty
- ARCHITECTURE.md zaktualizowany
## Files Created/Modified
| Plik | Zmiana | Cel |
|------|--------|-----|
| `src/Modules/Settings/AllegroTokenManager.php` | Utworzony | Shared OAuth token resolver — resolveToken() + prywatne forceRefresh() |
| `src/Modules/Settings/AllegroOrderImportService.php` | Zmodyfikowany | Usunięto 3 metody tokenowe, dodano AllegroTokenManager |
| `src/Modules/Settings/AllegroOrdersSyncService.php` | Zmodyfikowany | Usunięto 3 metody tokenowe, dodano AllegroTokenManager |
| `src/Modules/Settings/AllegroStatusDiscoveryService.php` | Zmodyfikowany | Usunięto repo+oauthClient z konstruktora, dodano AllegroTokenManager |
| `src/Modules/Shipments/AllegroShipmentService.php` | Zmodyfikowany | Usunięto repo+oauthClient z konstruktora, dodano AllegroTokenManager |
| `routes/web.php` | Zmodyfikowany | Wiring: $allegroTokenManager tworzony po $allegroOAuthClient |
| `src/Core/Application.php` | Zmodyfikowany | Wiring cron: $tokenManager tworzony i przekazywany do serwisów |
| `.paul/codebase/CONCERNS.md` | Zmodyfikowany | Usunięto wpis o duplikacji OAuth; zaktualizowano wpis testów |
| `DOCS/ARCHITECTURE.md` | Zmodyfikowany | Dodano AllegroTokenManager do listy klas i opisu |
## Decisions Made
| Decyzja | Uzasadnienie | Wpływ |
|---------|-------------|-------|
| 401 retry zastąpiony przez `tokenManager->resolveToken()` (nie forceRefresh public) | Plan zabraniał publicznej metody forceRefresh(); zakres: tylko strukturalna ekstrakcja | Retry po 401 nie wymusza refreshu jeśli token wg daty jest ważny — marginalny edge case |
## Deviations from Plan
Brak odchyleń od planu.
## Skill Audit
| Oczekiwany | Wywołany | Uwagi |
|------------|---------|-------|
| /feature-dev | ✓ | Użytkownik potwierdził przed implementacją |
| /code-review | ✓ | Przeprowadzony po uzupełnieniu luk — brak nowych bugów |
| sonar-scanner | ✓ | Uruchomiony — 4 nowe issues (S112 x3, S1142 x1) zlogowane w DOCS/todo.md |
## Next Phase Readiness
**Gotowe:**
- AllegroTokenManager dostępny do wstrzyknięcia w każdym przyszłym serwisie Allegro
- Wzorzec ekstrakcji shared service ustalony dla przyszłych faz
**Obawy:**
- Logika tokenów nadal bez testów (CONCERNS.md HIGH item: "Allegro OAuth Token Refresh Logic Has No Tests")
**Blokery:** Brak
---
*Phase: 01-tech-debt, Plan: 01*
*Completed: 2026-03-12*