# @flowcore/sdk-transformer-core 中文文档

规范地址：https://npmcn.com/package/%40flowcore/sdk-transformer-core/

版本：2\.5\.1
npm 元数据更新时间：2026-03-02T10:38:18.700Z
中文译文更新时间：2026-11-15T00:14:43.827Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40flowcore/sdk-transformer-core
原文对照：https://npmcn.com/package/%40flowcore/sdk-transformer-core/?lang=original
源码仓库：https://github.com/flowcore-io/library-sdk-transformer-core-ts

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：145 kB，47 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：2 个
- 首次发布：2024-05-29T15:21:07.806Z
- 最新版本发布：2025-06-03T12:43:33.453Z
- 近 30 天下载量：28247（2026-10-15 至 2026-11-13，npm 官方下载统计）
- 已发布版本数：43（近 12 个月 0 个）

## 中文简介

一个核心库,用于促进使用流芯范式的变压器和企业逻辑服务

## 安装

```sh
npm install @flowcore/sdk-transformer-core
```

也可以使用：`pnpm add @flowcore/sdk-transformer-core`、`yarn add @flowcore/sdk-transformer-core`、`bun add @flowcore/sdk-transformer-core`

## README

# sdk- 转换后核心

一个核心库,用于促进使用流芯范式的变压器和企业逻辑服务

## 安装

安装 npm :

```bash
npm install @flowcore/refine-data-provider
```

线条 :

```bash
yarn add @flowcore/refine-data-provider
```

## 使用量

## 发展

```bash
yarn install
```

或带 npm :

```bash
npm install
```

### 变形器构建器

#### 用法考试

```ts
new TransformerBuilder("flow-type.0")
    .withSecret("SUPER_SECRET_STRING")
    // Execute after succsessfully handling and responding to an event
    .withSuccessHandler(async (event: FlowcoreEvent) => {
        // Handle success
    })
    .onEventType(
        "event-type.0",
        EventTypePayloadSchema,
        async (event: FlowcoreEvent, payload: Static<typeof EventTypePayloadSchema>) => {
            // Handle event
        }
    )
    // ... (add more onEventType)
    // Get a generic handler method
    .getHandler()
    // Returns
    // (event: unknown, secret?: string) => Promise<{status: "ok" | "error", statusCode: number, message?: string, errors?: Record<string, string>}>

// You can extend the builder to build for specific routers

// Elysia example
export class ElysiaTransformerBuilder extends TransformerBuilder {
  public getRouter() {
    return new Elysia().post(
      `/${this.flowType}`,
      async ({ body, headers, set }) => {
        const response = await this.handleEvent(body, headers["x-secret"])
        set.status = response.statusCode
        return response
      },
      {
        body: FlowcoreEventSchema,
        headers: TransformerHeadersSchema,
        response: TransformerResponseSchema,
      },
    )
  }
}

```

### Webhook 构建器

#### 用法实例

```ts
const webhookFactory = new WebhookBuilder({
  // Base URL of webhook ingestion (default: "https://webhook.api.flowcore.io")
  baseUrl: "https://webhook.api.flowcore.io",
  // Required: flowcore tenant name
  tenant: "tenant",
  // Required: data core name or uuid
  dataCore: "data-core",
  // Required: flowcore api key
  apiKey: "00000000-0000-0000-0000-000000000000",
})
    // Will attempt X times to send webhook if it fails with a retryable status code
    // Retryable status codes are: 408, 429, 500, 502, 503, 504
    .withRetry({
        // Maximum number of attempts (default: 1)
        maxAttempts: 1,
        // Delay between attempts (default: 250)
        attemptDelayMs: 250,
        // Can also be a backoff method
        // attemptDelayMs: (attempt: number) => number
    })
    // Will do a predicate check after event is sent
    .withPredicate({
        // Predicate method: (eventId: string) => Promise<boolean> | boolean
        predicate: (eventId: string) => checkEventId(eventId)
        // Predicate options
        options: {
            // Maximum number of predicate attempts
            maxAttempts: 8,
            // Delay betweeen predicate attempts
            attemptDelayMs: 250,
            // Can also be a backoff method
            // attemptDelayMs: (attempt: number) => number
        }
    })
    // Build webhook method
    .buildWebhook<EventPayload extends Record<string, unknown>, MetaData extends Record<string, unknown>>("flow-type.0", "event-type.0")
    // Returns
    //{
    //    send: (payload: EventPayload, metadata?: MetaData, options?: WebhookSendOptions) => Promise<string>,
    //    sendBatch: (payload: EventPayload[], metadata?: MetaData, options?: WebhookSendBatchOptions) => Promise<string>,
    //}
    .buildFileWebhook<MetaData extends Record<string, unknown>>("flow-type.0", "event-type.0")
    // Returns
    //{
    //    send: (payload: FilePayload, metadata?: MetaData, options?: WebhookSendOptions) => Promise<string>,
    //}
    // Can also be used as a factory
    .factory()
    // Returns a method that returns a new instance of WebhookBuilder with current options
    // () => WebhookBuilder
```

### 回返和例外处理

`webhook.send` 返回单个事件Id(`string`(中文(简体) ) `webhook.sendBatch` 财务报告和审定财务报表 `fileWebhook.send` 返回事件编号数组( R)`string[]`(中文(简体) )

当发送方法失败时, 您可以得到这些例外 `WebhookSendError {message: string, response?: unknown, exception?: Error}`

-   `response` 从 webhook 端点返回( 在webhook 端点上发送失败)
-   `exception` 是本地丢弃的例外( 本地发送失败, 但有一个例外)

`WebhookPredicateError` {消息: 字符串, 事件编号: 字符串\[\], 例外? : 错误 {}

-   `eventIds` 从 webhook 端点返回的事件 id
-   `exception` 是本地丢弃的例外( 预设失败, 例外)

`Error`

-   呜呼... 难得例外

### 元数据厂

```ts
const webhookWithMetadata = metadataWebhook({
  userId: "123",
})

// Will inject metadata into the sent event
const eventId: string = await webhookWithMetadata(webhook.send, {foo: "bar"})
// Will inject metadata into the sent events
const eventIds: string[] = await webhookWithMetadata(webhook.sendBatch, {foo: "bar"})
// Will inject metadata into the sent event
const eventIds: string[] = await webhookWithMetadata(fileWebhook.send, {foo: "bar"})
```

## 常见问题

### @flowcore/sdk-transformer-core 是什么？

一个核心库,用于促进使用流芯范式的变压器和企业逻辑服务

### 如何安装 @flowcore/sdk-transformer-core？

在项目目录运行 npm install @flowcore/sdk-transformer-core，或使用 pnpm add / yarn add / bun add。

### @flowcore/sdk-transformer-core 支持 TypeScript 吗？

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

### @flowcore/sdk-transformer-core 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @flowcore/sdk-transformer-core 可以商用吗？

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

### @flowcore/sdk-transformer-core 的下载量有多少？

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

### @flowcore/sdk-transformer-core 还在维护吗？

最新版本 2\.5\.1 发布于 2025/06/03（1\.5 年前）；至今共发布 43 个版本，其中过去 12 个月发布了 0 个；首次发布于 2024/05/29。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

