@edge-markets/connect

中文文档
3.0.0发布于 2026/10/27MITTypeScriptESM + CJS零依赖近 30 天下载 1.7万

Core types, configuration, and utilities for EDGE Connect SDK

原始使用文档
文档目录13 节
  1. Installation
  2. Usage
  3. Types
  4. Webhook events
  5. Configuration
  6. Error Handling
  7. Exports
  8. Types
  9. Configuration
  10. Errors
  11. Type Guards
  12. Related Packages
  13. License

@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.amount is intentionally typed as string (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

TypeDescription
UserUser profile information
BalanceAccount balance
TransferTransfer response
TransferListItemTransfer in list
EdgeTokensOAuth tokens
EdgeLinkSuccessSuccessful link result
EdgeLinkExitLink exit metadata
EdgeWebhookEventDiscriminated union over webhook event types
TransferCompletedEventDataPayload for transfer.completed
TransferFailedEventDataPayload for transfer.failed (includes optional reason)
TransferExpiredEventDataPayload for transfer.expired
ConsentRevokedEventDataPayload for consent.revoked
EDGE_WEBHOOK_EVENT_TYPESRuntime tuple of all known event type strings

Configuration

ExportDescription
EDGE_ENVIRONMENTSAll environment configs
getEnvironmentConfig(env)Get config for environment
EDGE_SCOPESAvailable OAuth scopes
ACTIVE_EDGE_SCOPESScopes enabled for current partner integrations
ALL_EDGE_SCOPESAlias for all currently requestable scopes
RESERVED_EDGE_SCOPESFuture-only scopes that should not be requested
formatScopeForEnvironment(scope, env)Format scope for Cognito

Errors

ErrorWhen thrown
EdgeErrorBase error class
EdgeAuthenticationErrorInvalid/expired token
EdgeConsentRequiredErrorUser hasn't granted consent
EdgeApiErrorAPI request failed
EdgePopupBlockedErrorPopup was blocked

Type Guards

isEdgeError(error)           // Any SDK error
isConsentRequiredError(error) // Consent needed
isAuthenticationError(error)  // Auth failed
isApiError(error)            // API error
  • @edge-markets/connect-link - Browser SDK for popup authentication
  • @edge-markets/connect-node - Server SDK for token exchange and API calls

License

MIT

版本与发布记录

@edge-markets/connect 共发布 19 个版本,首次发布于 2026/01/21;过去 12 个月发布了 19 个版本。

版本发布日期距今
3.0.0latest2026/10/2717 天前
2.2.02026/09/281 个月前
2.1.02026/08/033 个月前
2.0.02026/07/293 个月前
1.10.12026/07/273 个月前
1.10.02026/07/273 个月前

关于 @edge-markets/connect 的常见问题

@edge-markets/connect 是什么?

Core types, configuration, and utilities for EDGE Connect SDK

如何安装 @edge-markets/connect?

在项目目录运行 npm install @edge-markets/connect,或使用 pnpm add / yarn add / bun add。

@edge-markets/connect 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@edge-markets/connect 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@edge-markets/connect 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.23.4。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@edge-markets/connect 可以商用吗?

@edge-markets/connect 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@edge-markets/connect 的下载量有多少?

根据 npm 官方下载统计,@edge-markets/connect 在 2026/10/13 – 2026/11/11 这 30 天内被下载 16,512 次,日均约 550 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@edge-markets/connect 还在维护吗?

最新版本 3.0.0 发布于 2026/10/27(17 天前);至今共发布 19 个版本,其中过去 12 个月发布了 19 个;首次发布于 2026/01/21。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。