@edge-markets/connect

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

EDGE 连接 SDK 的核心类型、配置和公用事业

中文使用文档
文档目录13 节
  1. 安装
  2. 使用量
  3. 类型
  4. Webhook活动
  5. 配置
  6. 处理错误
  7. 出口
  8. 类型
  9. 配置
  10. 错误
  11. 类型警卫
  12. 相关软件包
  13. 许可证

@ edge- markets/ 连接

EDGE Connect SDK的核心类型,配置,和公用事业.

安装

npm install @edge-markets/connect
# or
pnpm add @edge-markets/connect
# or
yarn add @edge-markets/connect

使用量

类型

API 回复和请求的导入类型 :

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活动

EdgeWebhookEvent 歧视的结合 event.type 覆盖每个 事件。 切换窄口 event.data 选择 变式——无铸造:

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 故意输入为: string (例如:. '100.00'改为: 保持小数精确。 以小数感知库在你的一边分析.

HMAC 实时 HTTP 传输通道上的 HMAC 签名验证, 使用 verifyWebhookSignature 从 @edge-markets/connect-node用于 核对投票、使用 EdgeConnectServer.syncWebhookEvents。 。 。 .

配置

获取特定环境的 URL :

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'

处理错误

特定情景的打出错误类别 :

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}`)
  }
}

出口

类型

类型说明
User用户配置信息
Balance账户余额
Transfer转移响应
TransferListItem清单上的转让
EdgeTokens证书
EdgeLinkSuccess成功链接结果
EdgeLinkExit链接退出元数据
EdgeWebhookEvent在网络活动类型上的歧视结合
TransferCompletedEventData有效载荷 transfer.completed
TransferFailedEventData有效载荷 transfer.failed (包括可选) reason(中文(简体) )
TransferExpiredEventData有效载荷 transfer.expired
ConsentRevokedEventData有效载荷 consent.revoked
EDGE_WEBHOOK_EVENT_TYPES所有已知事件类型字符串的运行时间拖转

配置

导出说明
EDGE_ENVIRONMENTS所有环境配置
getEnvironmentConfig(env)获取环境配置
EDGE_SCOPES可用的 OAuth 范围
ACTIVE_EDGE_SCOPES允许当前伙伴一体化的范围
ALL_EDGE_SCOPES目前所有可请求范围均不使用
RESERVED_EDGE_SCOPES不应请求的仅未来范围
formatScopeForEnvironment(scope, env)认知格式范围

错误

错误扔的时候
EdgeError基础错误类
EdgeAuthenticationError无效/ 过期的令牌
EdgeConsentRequiredError用户没有同意
EdgeApiErrorAPI 请求失败
EdgePopupBlockedError弹出被封锁

类型警卫

isEdgeError(error)           // Any SDK error
isConsentRequiredError(error) // Consent needed
isAuthenticationError(error)  // Auth failed
isApiError(error)            // API error
  • @edge-markets/connect-link - 用于弹出认证的浏览器 SDK
  • @edge-markets/connect-node - 用于交换和API的服务器SDK

许可证

麻省理工学院

版本与发布记录

@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 是什么?

EDGE 连接 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 和提交记录判断。