@edge-markets/connect
Core types, configuration, and utilities for EDGE Connect SDK.
Installation
npm install @edge-markets/connect
# or
pnpm add @edge-markets/connect
# or
yarn add @edge-markets/connect
Usage
Types
Import types for API responses and requests:
import type {
User,
Balance,
Transfer,
EdgeTokens,
EdgeWebhookEvent,
} from '@edge-markets/connect'
// Types are generated from the OpenAPI spec
const user: User = {
id: '507f1f77bcf86cd799439011',
email: '[email protected]',
firstName: 'John',
lastName: 'Doe',
verified: true,
createdAt: '2024-01-15T10:30:00.000Z',
}
Webhook events
EdgeWebhookEvent is a discriminated union over event.type covering every
event the producer emits. Switching narrows event.data to the matching
variant — no casts:
import type { EdgeWebhookEvent } from '@edge-markets/connect'
function handle(event: EdgeWebhookEvent) {
switch (event.type) {
case 'transfer.completed':
// event.data is { transferId, status: 'completed', type, amount }
console.log(`completed: ${event.data.transferId} for ${event.data.amount}`)
break
case 'transfer.failed':
// event.data.reason is `string | undefined`
console.log(`failed: ${event.data.reason ?? 'unknown'}`)
break
case 'transfer.expired':
console.log(`expired: ${event.data.transferId}`)
break
case 'transfer.processing':
// @experimental — reserved for ledger dual-write hand-off
break
case 'consent.revoked':
console.log(`consent revoked: ${event.data.userId}`)
break
default: {
const _exhaustive: never = event
return _exhaustive
}
}
}
event.data.amountis intentionally typed asstring(e.g.'100.00') to preserve decimal precision. Parse with a decimal-aware library on your side.
For HMAC signature verification on the live HTTP delivery channel, use
verifyWebhookSignature from @edge-markets/connect-node. For
reconciliation polling, use EdgeConnectServer.syncWebhookEvents.
Configuration
Get environment-specific URLs:
import {
getEnvironmentConfig,
getLinkUrl,
EDGE_SCOPES,
formatScopeForEnvironment,
} from '@edge-markets/connect'
const config = getEnvironmentConfig('sandbox')
console.log(config.apiBaseUrl) // https://...
console.log(getLinkUrl('sandbox')) // https://sandbox-oauth.staging-app.edgeboost.io/oauth/link
// Format scopes for your environment
const scopes = formatScopeForEnvironment(EDGE_SCOPES.BALANCE_READ, 'sandbox')
// Returns: 'edge-connect-sandbox/balance.read'
Error Handling
Typed error classes for specific scenarios:
import {
EdgeError,
EdgeConsentRequiredError,
isConsentRequiredError,
} from '@edge-markets/connect'
try {
const client = edge.forUser(accessToken)
const balance = await client.getBalance()
} catch (error) {
if (isConsentRequiredError(error)) {
// User needs to grant consent - redirect to EdgeLink
console.log(`Consent required for client: ${error.clientId}`)
} else if (error instanceof EdgeError) {
// Handle other SDK errors
console.error(`Error [${error.code}]: ${error.message}`)
}
}
Exports
Types
| Type | Description |
|---|---|
User | User profile information |
Balance | Account balance |
Transfer | Transfer response |
TransferListItem | Transfer in list |
EdgeTokens | OAuth tokens |
EdgeLinkSuccess | Successful link result |
EdgeLinkExit | Link exit metadata |
EdgeWebhookEvent | Discriminated union over webhook event types |
TransferCompletedEventData | Payload for transfer.completed |
TransferFailedEventData | Payload for transfer.failed (includes optional reason) |
TransferExpiredEventData | Payload for transfer.expired |
ConsentRevokedEventData | Payload for consent.revoked |
EDGE_WEBHOOK_EVENT_TYPES | Runtime tuple of all known event type strings |
Configuration
| Export | Description |
|---|---|
EDGE_ENVIRONMENTS | All environment configs |
getEnvironmentConfig(env) | Get config for environment |
EDGE_SCOPES | Available OAuth scopes |
ACTIVE_EDGE_SCOPES | Scopes enabled for current partner integrations |
ALL_EDGE_SCOPES | Alias for all currently requestable scopes |
RESERVED_EDGE_SCOPES | Future-only scopes that should not be requested |
formatScopeForEnvironment(scope, env) | Format scope for Cognito |
Errors
| Error | When thrown |
|---|---|
EdgeError | Base error class |
EdgeAuthenticationError | Invalid/expired token |
EdgeConsentRequiredError | User hasn't granted consent |
EdgeApiError | API request failed |
EdgePopupBlockedError | Popup was blocked |
Type Guards
isEdgeError(error) // Any SDK error
isConsentRequiredError(error) // Consent needed
isAuthenticationError(error) // Auth failed
isApiError(error) // API error
Related Packages
@edge-markets/connect-link- Browser SDK for popup authentication@edge-markets/connect-node- Server SDK for token exchange and API calls
License
MIT