@flowcore/sdk-transformer-core

中文文档
2.5.1发布于 2025/06/03MITTypeScriptCommonJS近 30 天下载 2.8万

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

中文使用文档
文档目录7 节
  1. 安装
  2. 使用量
  3. 发展
  4. 变形器构建器
  5. Webhook 构建器
  6. 回返和例外处理
  7. 元数据厂

sdk- 转换后核心

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

安装

安装 npm :

npm install @flowcore/refine-data-provider

线条 :

yarn add @flowcore/refine-data-provider

使用量

发展

yarn install

或带 npm :

npm install

变形器构建器

用法考试

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 构建器

用法实例

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

  • 呜呼... 难得例外

元数据厂

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 共发布 43 个版本,首次发布于 2024/05/29;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.5.1latest2025/06/031.5 年前
2.5.02025/06/031.5 年前
2.4.02025/05/271.5 年前
2.3.72025/05/271.5 年前
2.3.62025/02/211.7 年前
2.3.52025/02/211.7 年前

关于 @flowcore/sdk-transformer-core 的常见问题

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