feat: ConnectWise PSA Integration — Slice 1 (Foundation) #106

Merged
chihlasm merged 29 commits from feat/connectwise-psa-integration into main 2026-03-15 05:45:36 +00:00

29 Commits

Author SHA1 Message Date
Michael Chihlas
ecb9dd77dc docs: update CLAUDE.md for PSA integration phase and add ConnectWise reference docs
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 01:44:57 -04:00
Michael Chihlas
7f3f054583 fix(psa): move CW clientId to server config, remove from user input
ClientId is a product-level GUID registered at developer.connectwise.com,
not per-MSP. Moved to settings.CW_CLIENT_ID env var. MSPs now only
provide site URL, company ID, public key, and private key.

Also added newline handling note to post_note() — CW Developer Guide
states \n is unsupported in JSON bodies. Needs sandbox testing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 00:15:04 -04:00
Michael Chihlas
db305f54e7 feat(psa): add Member Mapping tab with auto-match and manual assignment
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 23:53:02 -04:00
Michael Chihlas
f6ce135b22 feat(psa): attribute posted notes to mapped CW member
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 23:46:35 -04:00
Michael Chihlas
1771577732 feat(psa): add member mapping CRUD and auto-match endpoints
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 23:46:21 -04:00
Michael Chihlas
540208a923 feat(psa): implement list_members in ConnectWise provider with cache
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 23:45:14 -04:00
Michael Chihlas
eeee94f74b feat(psa): add PsaMemberMapping model and migration
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 23:45:00 -04:00
Michael Chihlas
0e2aaff571 feat(psa): add Post History tab placeholder to Integrations page
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 23:39:54 -04:00
Michael Chihlas
74875d74e1 feat(psa): add Update Ticket modal with note posting and status update
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 23:39:49 -04:00
Michael Chihlas
5ade3be44e feat(psa): add PSA post preview, post-to-ticket, and post history endpoints
Three new session-scoped endpoints for posting session documentation
to linked PSA tickets:

- GET /sessions/{id}/psa-post/preview — generates PSA-formatted content,
  fetches ticket details and available statuses, counts previous posts
- POST /sessions/{id}/psa-post — posts note to CW ticket with optional
  status update, logs all actions in psa_post_log audit trail
- GET /sessions/{id}/psa-posts — returns post history for the session

New schemas: PsaPostRequest, PsaPostResponse, PsaPreviewResponse,
PsaPostLogResponse.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 23:31:11 -04:00
Michael Chihlas
74ee5009c2 feat(psa): implement post_note and update_ticket_status in CW provider
Replaces NotImplementedError stubs with working implementations:
- post_note maps note_type to CW flag fields (internalAnalysisFlag,
  resolutionFlag, detailDescriptionFlag) with appropriate visibility
  and notification settings
- update_ticket_status uses CW JSON Patch format to update status

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 23:28:46 -04:00
Michael Chihlas
7059969d05 feat(psa): add PsaPostLog model and migration
Audit trail for notes posted to PSA systems. Tracks session ID,
ticket ID, note type, content, status (success/failed), and any
status changes made alongside the note post.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 23:28:21 -04:00
Michael Chihlas
dcf8bce2bf feat(psa): upgrade ticket picker with search and fix lookup/link separation
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 23:14:56 -04:00
Michael Chihlas
88495b10f0 feat(psa): add in-memory TTL cache for board statuses
Add PSACache class with get/set/invalidate/clear operations and TTL expiry.
Board statuses are cached for 1 hour in the provider.
Cache is cleared when a PSA connection is re-tested.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 23:07:08 -04:00
Michael Chihlas
c1da853d01 feat(psa): add ticket search and status API endpoints
Add three new endpoints under /integrations/psa:
- GET /tickets/search: search CW tickets with query, board_id, status_id filters
- GET /tickets/{ticket_id}: fetch a single ticket by ID
- GET /tickets/{ticket_id}/statuses: get available statuses for a ticket's board

Add PSATicketSearchResult and PSATicketStatusItem schemas.
All endpoints require engineer_or_admin auth.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 23:07:03 -04:00
Michael Chihlas
5a35c933e0 feat(psa): implement search_tickets, get_ticket_statuses, list_companies in CW provider
Implement all remaining NotImplementedError stubs in ConnectWiseProvider:
- search_tickets: query by summary with board_id, status_id, include_closed filters
- get_ticket_statuses: fetch statuses for a service board
- list_companies: list companies with optional status filter
- get_company: fetch a single company by ID
- get_ticket_configurations: fetch configs attached to a ticket
- Extract shared _map_ticket helper to reduce duplication

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 23:06:57 -04:00
Michael Chihlas
b76864a892 feat(psa): add ticket picker modal and session header ticket link indicator
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 22:56:21 -04:00
Michael Chihlas
7eaab77daa feat(psa): add ticket link/unlink endpoint for sessions
PATCH /sessions/{id}/ticket-link validates ticket exists in ConnectWise
before linking, supports unlinking by sending null, and returns ticket
details on success.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 22:45:10 -04:00
Michael Chihlas
5bcaf6a9d4 feat(psa): add psa_ticket_id and psa_connection_id to sessions
Add columns to link sessions to PSA tickets and connections. Includes
migration 059, model relationship, and response schema fields.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 22:45:04 -04:00
Michael Chihlas
2a53f48d69 feat(psa): implement get_ticket in ConnectWise provider
Replace NotImplementedError stub with real implementation that fetches
a ticket by ID via CW REST API and maps it to PSATicket.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 22:44:58 -04:00
Michael Chihlas
ad9d4271d6 feat(psa): add Integrations page with connection management UI
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 22:14:50 -04:00
Michael Chihlas
08e1b4bf38 feat: add PSA connection API endpoints with RBAC and tests
Five endpoints under /integrations/psa/connections:
- GET (any auth user), POST/PUT/DELETE/test (owner+ only)
- Create tests CW connection before saving; update re-tests on cred change
- Credentials decrypted only for masked hints in responses
- Three CI-safe tests: empty GET, engineer 403, delete 404

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 22:06:48 -04:00
Michael Chihlas
910b3c4aef feat: add Pydantic schemas for PSA connection CRUD
PsaConnectionCreate, PsaConnectionUpdate, PsaConnectionResponse,
and PsaConnectionTestResponse — registered in schemas __init__.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 21:53:57 -04:00
Michael Chihlas
2086ecb5ea feat(psa): add ConnectWiseProvider with test_connection + provider registry
ConnectWiseProvider implements PSAProvider with test_connection() that
calls GET /system/info to verify credentials and connectivity. All other
methods raise NotImplementedError with slice references for future work.

Provider registry (get_provider_for_account) looks up the account's
PsaConnection, decrypts stored credentials, and instantiates the
correct provider. Currently supports connectwise only.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 21:52:23 -04:00
Michael Chihlas
fdaea49d3b feat(psa): add ConnectWise HTTP client with auth, URL resolution, pagination, retry
Implements ConnectWiseClient in services/psa/connectwise/client.py with:
- API key auth (Base64 companyId+publicKey:privateKey) + clientId header
- Accept header pinned to CW API version 2025.16
- Dynamic base URL resolution via /login/companyinfo (cloud vs on-premise)
- SSRF prevention: validates against known CW domains, rejects private IPs
- Retry with exponential backoff for timeouts and 5xx errors
- 429 rate limit handling with Retry-After header respect
- Error mapping: 401/403/404/429/5xx to typed PSA exceptions
- Paginated GET with while-loop pattern (max 1000 per page)
- JSON Patch array format for PATCH requests

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 21:51:49 -04:00
Michael Chihlas
5323768de6 feat(psa): add PsaConnection model and migration 058
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 21:49:19 -04:00
Michael Chihlas
086e4c6d59 feat(psa): add Fernet credential encryption with HKDF key derivation
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 21:48:09 -04:00
Michael Chihlas
d2edb9e3ce feat(psa): add PSA abstraction layer — base types, exceptions, abstract interface
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 21:46:12 -04:00
Michael Chihlas
1e3b6c0784 docs: add ConnectWise PSA integration implementation plan
5-slice plan covering foundation (abstraction layer, encryption,
connection CRUD, frontend), ticket linking, ticket search, update
ticket modal, and member mapping. Slice 1 has full task-level detail;
slices 2-5 are outlined for iterative planning.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 21:21:56 -04:00