5. eIDAS Electronic Agreement Signing Portal
Repository:
Microservices (planovi-microservices)β’ Rule Prefix:BR-SIGβ’ Documented Rules: 7 β’ Open[TEAM_WHY_NEEDED]Questions: 2
1. Business Purpose & Actors
- Problem Solved: Provides a white-labeled web signing portal where agreement signatories review an agreement document (HTML
srcdocor PDF iframe) and execute a Simple Electronic Signature (eIDAS Regulation (EU) 910/2014) backed byplanovi-backendβssigning-apiEdge Function (which records IP, UTC timestamp, and SHA-256 hash). - Actors:
- Agreement Signatory (Client / Counterparty / Cooperative Rep): Receives an email link containing
?signatoryId={id}&token={token}, reviews the document, types their full name, and clicks"Podpisz umowe". planovi-backend(signing-apiEdge Function): Authorizes token, returns agreement content + tenant branding fromcompany_settings, records signature, and emails final signed document once all signatories complete.
- Agreement Signatory (Client / Counterparty / Cooperative Rep): Receives an email link containing
2. All Features & End-to-End Flows (Happy Path + Error Paths)
- Feature A: Load & Verify Signing Session (
GET agreements/sign.php?signatoryId=...&token=...ordealflow/sign.php?...)- Trigger: Signatory opens link from invitation email.
- Validation: On page load,
init()checksSIDandTOKare non-empty; if missing βstateError("Nieprawidlowy link"/"Brak parametrow signatoryId lub token. Sprawdz email i sprobuj ponownie."). - API Call:
POST {SUPABASE_URL}/functions/v1/signing-apiwith{"signatoryId": SID, "token": TOK, "action": "load"}(noapikey/Authorizationheaders sent β relies onverify_jwt = falseonsigning-api). - Response Handling:
data.errorβstateError("Blad weryfikacji", message =data.error).data.alreadySignedβstateAlreadySigned("Juz podpisano").- Valid pending signatory β Populates signatory name/email, signature level badge (
'Poziom: ' + (data.signatureLevel || 'SES')), signing order ('Kolejnosc podpisu: ' + data.signingOrder), applies dynamic tenant branding (companyName,companyTagline,companyLogo), loads document into#docFrame(frame.srcdoc = data.htmlContentpreferred overframe.src = data.pdfUrl, else hides iframe), and transitions tostateMain.
- Feature B: Name Input Soft-Check & Signature Execution
- Validation (
onNameInput()): Button#signBtnstays disabled whiletypedName.length < 2. Once>= 2, normalizes case and whitespace (toLowerCase().replace(/\s+/g,' ').trim()) againstSNAME:- Exact normalized match β green hint
'Imie i nazwisko zgodne' - Mismatch β amber warning
'Nie pasuje dokladnie β mozesz podpisac mimo to'(does NOT block signing).
- Exact normalized match β green hint
- API Call (
doSign()): Disables button, shows spinner, posts{"signatoryId": SID, "token": TOK, "action": "sign", "typedName": typedName}tosigning-api. - Response Handling:
data.error === 'already_signed'βstateAlreadySigned.!data.successβ throws error, re-enables button, shows inline#errBox.data.successβ showsstateSuccesswith different copy fordata.allSigned === true("Wszystkie podpisy zostaly zlozone! Obie strony otrzymaja email z podpisana umowa.") vsfalse("Twoj podpis zostal zarejestrowany. Oczekujemy na podpisy pozostalych sygnatariuszy.").
- Validation (
3. Hard Business Rules, Validations, Calculations & Edge Cases
BR-SIG-01(Exact Duplicate Across Two Microservices):agreements/sign.phpanddealflow/sign.phpare byte-for-byte identical (523lines each,diffexit0).BR-SIG-02(Minimum Signature Length & Non-Blocking Name Match):typedName.trim().length >= 2is required to enable signing (sign.php:394,474). Name mismatch againstdata.signatoryNamedisplays an amber hint but deliberately permits signing (sign.php:401-407).BR-SIG-03(Document Rendering Precedence):data.htmlContentis rendered viaiframe.srcdoc(avoiding Content-Type issues,sign.php:455-458); falls back toiframe.src = data.pdfUrl; if neither exists,#docFrameis hidden. Note:#docFramehas nosandboxattribute.BR-SIG-04(Dynamic Company Branding Injection): Ifdata.companyLogois returned, JS prepends a new<img>inside#brandLogo(sign.php:445-453) WITHOUT hiding the default#brandIconhexagon SVG or#brandNamespan, resulting in both the uploaded logo and default Planovi hexagon icon showing simultaneously.BR-SIG-05(Theme Storage Key Typo):sign.php:366, 369stores dark/light toggle inlocalStorage['planowi_theme'](withw), whereasinquiry.phpusesplanovi_theme(withv).BR-SIG-06(Unstripped Quotes in.envLoader & Unused Env Var):sign_load_env()(sign.php:6-15) does not strip surrounding quotes from.envvalues.$logoUrl = $_ENV['PLANOVI_LOGO_URL'] ?? '';(sign.php:23) is loaded and never referenced.BR-SIG-07(Anti-Cache Headers): Explicitly sendsCache-Control: no-store, no-cache, must-revalidate, max-age=0andPragma: no-cache(sign.php:2-3).
4. State Machines & Data Lifecycle
Signing Portal UI State Machine (showState()):
stateDiagram-v2
[*] --> stateLoading: Page load -> init()
stateLoading --> stateError: Missing SID/TOK OR data.error OR network failure
stateLoading --> stateAlreadySigned: data.alreadySigned == true
stateLoading --> stateMain: Valid pending signatory loaded
stateMain --> stateAlreadySigned: doSign() -> data.error == 'already_signed'
stateMain --> stateSuccess: doSign() -> data.success == true (allSigned true/false)
stateMain --> stateMain: doSign() error -> inline errBox + retry
stateError --> [*]
stateAlreadySigned --> [*]
stateSuccess --> [*]
5. Technical Contract (Inputs β Processing β Side Effects)
- Endpoints Exposed:
GET /agreements/sign.php?signatoryId={id}&token={token}GET /dealflow/sign.php?signatoryId={id}&token={token}
- External API Called:
POST {SUPABASE_URL}/functions/v1/signing-api- Action
load: Request{signatoryId, token, action: "load"}β Response{signatoryName, signatoryEmail, title, signatureLevel, signingOrder, companyName, companyTagline, companyLogo, htmlContent?, pdfUrl?, alreadySigned?, error?}. - Action
sign: Request{signatoryId, token, action: "sign", typedName}β Response{success, allSigned?, error?}.
- Action
6. Cross-Repository Dependencies
| Caller | Callee | Protocol & Auth | Exact Endpoint / Contract |
|---|---|---|---|
Signing invitation email (planovi-backend) | planovi-microservices (agreements / dealflow) | Browser GET with URL signatoryId + token | /sign.php?signatoryId=...&token=... |
agreements/sign.php & dealflow/sign.php (browser JS) | planovi-backend (Supabase Edge Function) | HTTPS POST JSON (signatory token in body, no JWT header) | POST /functions/v1/signing-api |
7. Why It Works This Way (Decisions, Trade-offs & Workarounds)
iframe.srcdocfor Agreement HTML (sign.php:455-458): Comment explicitly statesEmbed agreement HTML via srcdoc β no Content-Type issues(avoids Supabase Storage serving HTML astext/plainor triggering downloads).- Soft Name Matching (
sign.php:401-407): Allows signing even on minor spelling/diacritic differences while signaling visual confirmation on exact match. [TEAM_WHY_NEEDED: Why do identical copies exist at both agreements/sign.php and dealflow/sign.php? Which subdomain/path is canonical in production emails, and can one be removed or redirected?][TEAM_WHY_NEEDED: Does agreements/sign.php intentionally omit iframe sandbox="allow-same-origin" (or empty sandbox) on #docFrame when rendering arbitrary htmlContent via srcdoc?]
8. Debugging, Logs & Common Failure Modes
| Symptom / Error Message | Root Cause in Code | How to Verify / Exact Log or Query | Fix |
|---|---|---|---|
"Blad polaczenia" on every link | SUPABASE_URL missing or wrapped in quotes in .env (sign_load_env keeps literal quotes, corrupting API URL at sign.php:18-19), or CORS/network block on signing-api. | Inspect var API = ... in page source and check browser Console/Network tab. | Strip quotes in sign_load_env() and verify SUPABASE_URL in root .env. |
| Both tenant logo and default Planovi hexagon icon appear in header | sign.php:445-453 inserts logoImg before #brandIcon without setting #brandIcon.style.display = 'none'. | Inspect #brandLogo children in DOM when data.companyLogo is returned. | Hide #brandIcon (or populate existing #brandImg element at line 241 which is currently unused). |
Broken footer links (planowi.app) | Typos in sign.php:345, 348, 350 (https://planowi.app and https://dev-main.planowi.app/assets/for_preview/index). | Click footer links. | Replace planowi.app with planovi.app and production legal URLs. |