Commit Graph

18 Commits

Author SHA1 Message Date
Paul Huliganga c5b7b9f5b8 fix: resolve latent bugs found in code review
- Fix ValueError crash in migrate_template.py and migrate_paul_template.py:
  compose_template() returns a 3-tuple since Phase 23 but both CLI scripts
  were still unpacking 2 values
- Fix ImportError in bulk-send/bulk_send.py: replace non-existent auth_helper
  import with docusign_auth.get_access_token via sys.path
- Activate log sanitizer at web app startup so tokens never appear in logs
- Log a warning at startup when SESSION_SECRET_KEY is the default dev value
- Add reportlab to requirements.txt (used by generate_pdfs.py, was missing)
- Move asyncio import from bottom of templates.py to top where it belongs
- Correct stale coordinate comment in generate_pdfs.py (both platforms use
  top-left origin; the comment incorrectly described bottom-left inversion)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-23 09:51:20 -04:00
Paul Huliganga 210f273c05 Show field mapping caveats in template issues 2026-04-23 09:15:49 -04:00
Paul Huliganga eb9ce84001 Add multi-user web auth sessions 2026-04-21 21:05:15 -04:00
Paul Huliganga 3be3903986 Switch DocuSign auth to authorization code flow 2026-04-21 16:25:56 -04:00
Paul Huliganga b2bbcac842 feat(issues): structured field-issue reporting throughout migration pipeline
Replaces flat warning strings with machine-readable FieldIssue objects
(code, field_name, message, severity) emitted during compose and surfaced
in all migration result paths via a new field_issues[] key.

Codes: CROSS_RECIPIENT_CONDITIONAL, UNSUPPORTED_OPERATOR, HIDE_ACTION,
MULTI_PREDICATE, INVALID_PARENT_TAB, FIELD_TYPE_SKIPPED, PARTIAL_FIELD_TYPE

Cross-recipient conditional detection: compose now builds a field→assignee
map and flags conditions where the trigger field belongs to a different
recipient — the main cause of the CONDITIONALTAB_HAS_INVALID_PARENT 400.

UI changes:
- Success rows with field_issues show ⚠️ icon + amber "partial" badge
- Results, History & Audit, and Template Detail history tab all show
  field issues grouped by code in collapsible sections within expanded rows

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-21 15:25:23 -04:00
Paul Huliganga 53eb206d89 fix(compose): strip invalid conditionalParentLabel refs before upload
DocuSign returns CONDITIONALTAB_HAS_INVALID_PARENT when a conditional tab
references a parent that doesn't exist or is a forbidden type (signature,
initial, auto-filled). Added _strip_invalid_conditionals() post-processing
pass that validates all conditionalParentLabel values against the actual
built tabs and removes any that won't pass DocuSign validation, logging a
warning for each. Also updated verify tests for the template role-fetch step.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-21 15:09:11 -04:00
Paul Huliganga 342e8c3471 feat(phases-8-13): blueprint alignment — normalized schema, validation, migration options, retry, security, batch
Phase 8: Normalized intermediate schema (src/models/normalized_template.py, src/services/mapping_service.py)
  - Platform-agnostic NormalizedTemplate as pipeline bridge
  - PDF SHA-256 checksums computed during normalization
  - 13 tests passing

Phase 9: Validation service + report builder (src/services/validation_service.py, src/reports/report_builder.py)
  - Blockers (no recipients, no documents) halt migration
  - Warnings (no fields, unassigned roles, unsupported features) logged
  - Structured MigrationReport with per-template status
  - 20 tests passing

Phase 10: Migration options API (web/routers/migrate.py)
  - source_template_ids, dry_run, overwrite_if_exists, include_documents options
  - Backward compatible with legacy adobe_template_ids field
  - 7 tests passing

Phase 11: Retry with exponential backoff (src/utils/retry.py)
  - retry_with_backoff and async_retry_with_backoff decorators
  - 429/5xx detection via check_response_retryable
  - 14 tests passing

Phase 12: Security hardening (src/utils/log_sanitizer.py)
  - SanitizingFilter redacts tokens, JWTs, base64 PDF content from logs
  - 15 tests passing

Phase 13: Batch migration API
  - POST /api/migrate/batch — async background job with job_id
  - GET /api/migrate/batch/{job_id} — poll progress and results
  - 6 tests passing

Full suite: 108/108 tests passing

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-21 02:19:38 -04:00
Paul Huliganga 39982008d3 Add latest migration files and validation outputs 2026-04-20 01:12:46 -04:00
Paul Huliganga 51f532f452 feat: idempotent upload + FastAPI web UI with full test coverage
Phase 1 — Idempotent upload:
- upload_docusign_template.py now upserts: PUT if template with same name
  exists (most recently modified), POST otherwise
- --force-create flag to bypass upsert

Phase 2-6 — FastAPI web UI:
- web/app.py: FastAPI app with /health, static file serving
- web/routers/auth.py: Adobe Sign + DocuSign OAuth start/callback/disconnect
- web/routers/templates.py: template listing + migration status badges
  (not_migrated / migrated / needs_update)
- web/routers/migrate.py: POST /api/migrate pipeline + GET /api/migrate/history
- web/static/: vanilla HTML/CSS/JS side-by-side template browser UI

Phase 7 — Tests (29/29 passing):
- test_upload_upsert.py: 4 upsert unit tests
- test_api_health/auth/templates/migrate.py: full API coverage
- test_e2e.py: 7-step full pipeline end-to-end test
- test_regression.py: compose output vs snapshots for 3 real templates
- conftest.py: --update-snapshots CLI option

Docs: IMPLEMENTATION-PLAN.md, updated EXECUTION-BOARD.md + architecture.md

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-17 14:47:27 -04:00
Paul Huliganga 785107e8de feat: map Adobe Sign conditional logic to DocuSign conditionalParentLabel/Value
Adobe Sign conditionalAction (SHOW/EQUALS) is now translated to
DocuSign's conditionalParentLabel + conditionalParentValue on the
dependent tab, making conditional fields work in the migrated template.

For radio groups, conditionalParentLabel matches the radio group name.

Unsupported cases emit warnings rather than silently dropping conditions:
- HIDE action (no DocuSign equivalent — field left always visible)
- Non-EQUALS operators (skipped)
- Multi-predicate ANY/ALL (first EQUALS predicate used, rest ignored)

Also updates field-mapping.md: adds Conditional Logic Mapping table
and moves this item out of Known Gaps into documented behaviour.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-16 12:18:48 -04:00
Paul Huliganga e2e47f2662 feat: map Adobe STAMP field to DocuSign stampTabs
Adobe STAMP (hanko/seal) has a direct DocuSign equivalent via
stampTabs. Previously marked as skipped with no equivalent.

- compose_docusign_template.py: emit stampTabs for STAMP input type;
  PARTICIPATION_STAMP remains skipped (still no equivalent)
- field-mapping.md: update STAMP row, add stampTabs to multi-location
  non-merging list, add account feature prerequisite to Known Gaps

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-16 10:10:22 -04:00
Paul Huliganga 9c6c01d619 fix: correct Adobe Sign token refresh endpoint and add auth error handling
Adobe Sign uses a non-standard separate endpoint for refresh:
/oauth/v2/refresh (not /oauth/v2/token). Using the wrong endpoint
returned a misleading "Invalid grant_type refresh_token" error.

Also:
- Remove redirect_uri from refresh requests (not required)
- Add clear RuntimeError message directing user to re-authenticate
- Validate access_token is non-empty before saving in adobe_auth.py
- Log token lengths and exchange response keys on successful auth

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-16 10:10:12 -04:00
Paul Huliganga 766986a795 refactor: rename auth_adobe.py to adobe_auth.py for naming consistency
Matches the naming convention of docusign_auth.py. Update all
references in README.md and the error message in adobe_api.py.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-16 10:10:05 -04:00
Paul Huliganga 9c0910f30f feat: end-to-end migration runner and test template utilities
migrate_template.py — generic end-to-end CLI replacing the earlier
migrate_paul_template.py:
  --list                   list available Adobe Sign templates
  --template "Name"        download → convert → upload a named template
  --template "Name" --skip-upload  convert only, write JSON to migration-output/
  Picks most recently modified when multiple templates share a name.

create_adobe_template.py — utility for creating a test template in Adobe Sign
that exercises all 15+ field types. Uses the David Tag Demo Form PDF as the
base document and positions extra fields (Number, Email, Company, Title) in
the gaps of the original layout.

generate_pdfs.py — generates realistic sample PDFs with labelled form areas
matching the *-formfields.json fixtures in sample-templates/, for use in
offline testing without a live Adobe Sign account.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-15 19:45:31 -04:00
Paul Huliganga 93b6ad248a feat: DocuSign JWT auth and pure-Python template upload client
docusign_auth.py — authentication helper supporting two flows:
- JWT Grant: service-to-service token generation using an RSA private key;
  caches token + expiry in .env to avoid redundant round-trips
- Auth Code Grant (--consent): one-time browser flow to grant the app the
  'impersonation' scope required for JWT; must be run once per user/app before
  JWT will work

upload_docusign_template.py — posts a docusign-template.json to the DocuSign
Templates REST API (v2.1). No Node.js dependency. Retries once on 401.

requirements.txt — adds PyJWT>=2.0 and cryptography for RSA key handling.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-15 19:45:23 -04:00
Paul Huliganga 76568672d7 feat: core migration — Adobe Sign to DocuSign field mapping and composition
compose_docusign_template.py — converts a downloaded template folder into a
DocuSign envelopeTemplate JSON ready for the Templates API. Key behaviours:

- Full field type mapping: TEXT_FIELD, SIGNATURE, CHECKBOX, RADIO, DROP_DOWN,
  BLOCK, FILE_CHOOSER (with warning), INLINE_IMAGE (skipped with warning)
- contentType dispatch: SIGNER_NAME → fullNameTabs, SIGNER_EMAIL →
  emailAddressTabs, SIGNATURE_DATE → dateSignedTabs, COMPANY/SIGNER_COMPANY →
  companyTabs, TITLE/SIGNER_TITLE → titleTabs, DATA+NUMBER → numberTabs,
  DATA+DATE → dateTabs, SIGNER_INITIALS → initialHereTabs
- Multi-location (cloned) fields: emits one tab per location with the same
  tabLabel so DocuSign tab merging replicates Adobe Sign's sync behaviour
- Width/height passed through from Adobe Sign locations; MIN_TEXT_WIDTH=120pt
  ensures text fields render as visible boxes rather than vertical lines
- Coordinate system: both platforms use top-left origin — no inversion needed

test_mapping.py — unit test harness validating tab grouping and field mapping.

field-mapping.md — full Adobe Sign → DocuSign tab type reference table with
edge cases, known gaps, and decision log.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-15 19:45:13 -04:00
Paul Huliganga e655d8b4f5 feat: Adobe Sign template download pipeline
download_templates.py — subcommand CLI for listing and downloading library
templates from Adobe Sign.

  list                   — print all templates with name, modified date, ID
  download               — download all templates (default)
  download --all         — explicit download all
  download "Name"        — download a single named template; picks the most
                           recently modified if duplicates exist

Each template is saved to downloads/<name>__<id8>/ containing metadata.json,
form_fields.json, documents.json, and the source PDF.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-15 19:44:52 -04:00
Paul Huliganga 343955241d feat: Adobe Sign OAuth client and API wrapper
auth_adobe.py — one-time browser Auth Code Grant flow; saves access and
refresh tokens to .env. Targets the EU2 shard.

adobe_api.py — thin API client with auto token refresh on 401. Supports
GET, POST (JSON and multipart), PUT, and binary download.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-15 19:44:43 -04:00