@edge-markets/connect
v1.3.0
Published
Core types, configuration, and utilities for EDGE Connect SDK
Readme
@edgeboost/edge-connect-sdk
Core types, configuration, and utilities for EDGE Connect SDK.
Installation
npm install @edgeboost/edge-connect-sdk
# or
pnpm add @edgeboost/edge-connect-sdk
# or
yarn add @edgeboost/edge-connect-sdkUsage
Types
Import types for API responses and requests:
import type {
User,
Balance,
Transfer,
EdgeTokens,
} from '@edgeboost/edge-connect-sdk'
// Types are generated from the OpenAPI spec
const user: User = {
id: '507f1f77bcf86cd799439011',
email: '[email protected]',
firstName: 'John',
lastName: 'Doe',
createdAt: '2024-01-15T10:30:00.000Z',
}Configuration
Get environment-specific URLs:
import {
getEnvironmentConfig,
EDGE_SCOPES,
formatScopeForEnvironment,
} from '@edgeboost/edge-connect-sdk'
const config = getEnvironmentConfig('staging')
console.log(config.apiBaseUrl) // https://...
// Format scopes for your environment
const scopes = formatScopeForEnvironment(EDGE_SCOPES.BALANCE_READ, 'staging')
// Returns: 'edge-connect-staging/balance.read'Error Handling
Typed error classes for specific scenarios:
import {
EdgeError,
EdgeConsentRequiredError,
isConsentRequiredError,
} from '@edgeboost/edge-connect-sdk'
try {
const balance = await edge.getBalance(accessToken)
} 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 |
Configuration
| Export | Description |
|--------|-------------|
| EDGE_ENVIRONMENTS | All environment configs |
| getEnvironmentConfig(env) | Get config for environment |
| EDGE_SCOPES | Available OAuth scopes |
| ALL_EDGE_SCOPES | All scopes as array |
| 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 errorRelated Packages
@edgeboost/edge-connect-link- Browser SDK for popup authentication@edgeboost/edge-connect-server- Server SDK for token exchange and API calls
License
MIT
