@humanity-org/connect-sdk is the official TypeScript helper for Humanity’s Public API. It wraps the generated REST client with ergonomic helpers for OAuth, preset verification, feeds, and error handling so partner teams can ship integrations quickly.
Installation
Initialization & configuration
| Option | Required | Description |
|---|---|---|
clientId | ✅ | Issued when your app is approved. |
redirectUri | ✅ | Must match one of the URIs registered with Humanity. |
environment | ➖ | sandbox or production. Sets the Humanity base URL automatically (defaults to sandbox). |
baseUrl | ➖ | Advanced override for regional/private deployments (takes precedence over environment). |
clientSecret | ➖ | Only required for confidential clients or service-to-service flows. Never ship it to the browser. |
clockToleranceMs | ➖ | Adjusts token expiry validation for skewed environments. |
defaultHeaders | ➖ | Custom headers to include with every request (e.g., for tracing). |
fetch | ➖ | Custom fetch implementation for environments without native fetch or for request interception. |
OAuth helpers
/oauth/authorize, /oauth/token, /oauth/revoke) and enforces the PKCE + grant-type requirements documented in the API reference.
buildAuthUrl options
| Option | Required | Description |
|---|---|---|
scopes | ✅ | Array of OAuth scopes to request (e.g., ['identity:read', 'kyc:read']). |
state | ➖ | CSRF protection token. Generate with HumanitySDK.generateState() and verify on callback. |
nonce | ➖ | Replay protection for ID tokens. Generate with HumanitySDK.generateNonce(). |
codeVerifier | ➖ | Provide your own PKCE code verifier, or let the SDK generate one. |
codeVerifierLength | ➖ | Length of auto-generated code verifier (default: 43). |
additionalQueryParams | ➖ | Extra query parameters like { prompt: 'consent' } or { login_hint: 'user@example.com' }. |
{ url: string, codeVerifier: string } — the state is NOT returned; you must pass it in and store it yourself.
TokenResult
TheexchangeCodeForToken helper returns a fully typed TokenResult:
| Property | Type | Description |
|---|---|---|
accessToken | string | Bearer token for API requests. |
tokenType | string | Always "Bearer". |
expiresIn | number | Seconds until the access token expires. |
scope | string | Space-separated list of granted scopes. |
grantedScopes | string[] | Array of granted scopes. |
presetKeys | string[] | Preset keys available for verification. |
authorizationId | string | Unique ID for this authorization grant. |
appScopedUserId | string | User ID scoped to your app—use this for user identification. |
issuedAt | string? | ISO timestamp when the token was issued. |
refreshToken | string? | Refresh token (confidential clients only). |
refreshTokenExpiresIn | number? | Seconds until the refresh token expires. |
refreshIssuedAt | string? | ISO timestamp when the refresh token was issued. |
idToken | string? | OIDC ID token (when openid scope is requested). |
raw | object | Raw API response for advanced use cases. |
rateLimit | object? | Rate limit info from response headers. |
Static security helpers
The SDK provides static methods for OAuth security parameters:Preset verification
verifyPreset,verifyPresets, andgetPresetexpose the/presets/*endpoints with fully typed responses (including evidence payloads).- Use
listPresets()to discover all available presets with their metadata. - Maximum of 10 presets per batch request; the helper enforces this before hitting the API.
PresetBatchResult
TheverifyPresets helper returns a PresetBatchResult with two arrays:
Query Engine
For declarative queries against user credentials, use the Query Engine:Dropping down to the raw client
The generatedsdk.client exposes every controller method exactly as declared in the OpenAPI. Use it whenever you need lower-level access or when rolling your own abstractions.
src/contracts), you can rely on TypeScript to catch breaking changes long before runtime.
Error handling
The SDK exports typed error classes for precise error handling:| Error Class | Description |
|---|---|
HumanitySDKError | Base error for all SDK operations. Includes message, code, status, and details. |
HttpError | Network-level errors (timeouts, connection failures). |
- Rate limits follow the guidance in Environments & tooling. Honor
Retry-Afterheaders and reuseidempotency_keyvalues when retrying POSTs. - If you lose track of the SDK abstraction, call
sdk.clientdirectly—both layers share the same authentication headers and transport pipeline.