Feature ID: PF-65Documentation Index
Fetch the complete documentation index at: https://docs.encoreos.io/llms.txt
Use this file to discover all available pages before exploring further.
Status: π Planned
Created: 2026-02-05
Version: v1.0.0
Spec Reference:
specs/pf/specs/PF-65-gusto-embedded-payroll-integration.md (v1.0)
Overview
PF-65 provides a Platform Integration Layer for the Gusto Embedded React SDK (@gusto/embedded-react-sdk). It enables HR (and other cores) to embed Gusto payroll and onboarding workflows inside Encore Health OS without implementing auth or proxy logic. All SDK traffic goes through a backend proxy (Supabase Edge Function) that adds OAuth2 tokens and x-gusto-client-ip.
Integration Patterns
| Type | Pattern | Location | Status |
|---|---|---|---|
| Platform Layer | Pattern 1 | @/platform/gusto (or equivalent) | π Planned |
| Backend Proxy | API (internal) | Supabase Edge Function gusto-proxy | π Planned |
| PF-35 | Credential storage | pf_integrations (integration_type gusto_embedded) | π Planned |
| HR consumer | Platform Layer consumer | HR routes under /hr/payroll/gusto, /hr/me/onboarding | π Planned |
Platform Integration Layer
Location:/src/platform/gusto/ (to be created)
Public API (from spec):
hr.gusto.view (embed components), hr.gusto.configure (configure connection and company mapping).
API Contract: Gusto Proxy
Endpoint: Supabase Edge Function, e.g.POST /functions/v1/gusto-proxy
Behavior:
- Receives request from SDK (path + body match Gusto Embedded API 1:1).
- Resolves authenticated userβs
organization_id; loads that orgβs Gusto OAuth access token from PF-35 (pf_integrations+ credentials). - Adds
Authorization: Bearer <token>andx-gusto-client-ip(fromX-Forwarded-FororX-Real-IP). - Forwards to
https://api.gusto.com(exact path per Gusto Embedded API docs). - On 401: attempts token refresh (using stored refresh token). If the authorization server returns a new refresh token in the refresh response, the proxy must persist and replace the old refresh token in the credential store (PF-35 /
pf_integrations) so future refreshes use the new value. The retry MUST use the newly issued access token in theAuthorization: Bearer <token>header. On refresh or persist failure, return a sanitized error (e.g. 502 βReconnect to Gustoβ) without exposing tokens.
API_CONTRACTS.md (e.g. 401 Unauthorized, 502 Bad Gateway, 503 Service Unavailable).
Security
- OAuth tokens and refresh tokens only server-side (PF-35 / Vault); never in frontend.
x-gusto-client-ip(trusted client IP): The Edge Function (or middleware) must derive a trusted client IP as follows:- Prefer X-Forwarded-For: use the rightmost entry added by your trusted edge proxy (i.e., the last IP in the chain), since the leftmost is typically the original client and the rightmost is the one added by the proxy closest to this service.
- Fall back to X-Real-IP only if the request is known to have passed through a trusted proxy that sets it.
- Otherwise use the connection remote address.
- The Edge Function must validate/sanitize the chosen IP: parse and canonicalize it, reject private/reserved ranges unless explicitly expected (e.g., internal networks), and verify the request passed through a known proxy list when using forwarded headers. If no trusted IP can be determined, set the header value to βunknownβ and log a warning.
- Proxy and company resolution scoped by
organization_id; no cross-tenant data.
SDK Event Types
The Gusto Embedded SDK emits events viaonEvent callback. Encore Health OS handles:
| Event Name | Description | Encore Health OS Action |
|---|---|---|
employee/created | New employee added to Gusto | Toast notification, analytics |
onboarding/complete | Employee finished onboarding | Toast notification, analytics |
References
- Spec:
specs/pf/specs/PF-65-gusto-embedded-payroll-integration.md - PF-35: Integration Hub β
specs/pf/specs/PF-35-integration-hub.md - API Contracts:
docs/architecture/integrations/API_CONTRACTS.md(proxy to be added) - Platform Integration Layers:
docs/architecture/integrations/PLATFORM_INTEGRATION_LAYERS.md - Gusto Embedded API: https://docs.gusto.com/embedded-payroll/docs/