@flatfile/api

中文文档
1.23.0发布于 2025/08/29TypeScriptCommonJS近 30 天下载 95.9万

npm shield [fern shield[https://buildingwithfern.com/?utm source=平面过滤器/f

中文使用文档
文档目录8 节
  1. 文档
  2. 安装
  3. 使用量
  4. 处理错误
  5. 处理事件
  6. 字段
  7. 捐款
  8. 许可证

平面文件节点 API 库

npm shield fern shield

Flatfile Node.js库提供从JavaScript/TypeScript获取Flatfile API的方便访问.

文档

API 备有参考文件 这里。 。 。 .

安装

npm install --save @flatfile/api
# or
yarn add @flatfile/api

使用量

Try it out

import { FlatfileClient } from '@flatfile/api';

async function main() {
  const flatfile = new FlatfileClient({
    // This is usually the environment specific "Secret Key" that can be found
    // on the Getting Started page in the Flatfile dashboard.
    token: 'YOUR_API_KEY',
  });

  const workbook = await flatfile.workbooks.create({
    name: 'SDK Example',
    sheets: [
      {
        name: 'Contacts',
        slug: 'contacts',
        fields: [
          {
            key: 'firstName',
            type: 'string',
            label: 'First Name',
          },
          {
            key: 'lastName',
            type: 'string',
            label: 'Last Name',
          },
          {
            key: 'email',
            type: 'string',
            label: 'Email',
          },
        ],
        actions: [
          {
            slug: 'submitAction',
            label: 'Submit',
            type: 'string',
            description: 'Submit data to webhook.site',
            primary: true,
          },
        ],
      },
    ],
  });

  console.log('Created workbook with id:', workbook.data.id);
}

处理错误

当 API 返回一个非成功状态代码( 4xx 或 5xx 响应) 时, 一个子类 : 平面文件错误 将扔出 :

try {
  await client.agents.get("environment-id", "agent-id");
} catch (err) {
  if (err instanceof FlatfileError) {
    console.log(err.statusCode); // 400
    console.log(err.message); // "BadRequestError"
    console.log(err.body); // list of errors
  }
}

错误代码如下:

身份代码错误类型
400个BadRequestError
404 (韩语)NotFoundError

处理事件

平面文件平台发出不同事件(例如. user:added, (中文(简体) ), webhook:removed) (中文(简体) ). SDK使用过 歧视工会 这样就容易处理具体事件.

const event = eventResponse.data;
if (event.type === 'job:ready') {
  console.log(event.payload.operation); // FILE
  console.log(event.payload.type); // PIPELINE
} else if (event.type === 'records:created') {
  console.log(event.payload.count) // 100
}

字段

SDK使用过 歧视工会 这使得它很容易 透视不同的领域.

for (const field of sheet.config.fields) {
    if (field.type === 'boolean') {
      console.log(field.config?.allowIndeterminate); // false
    } else if (field.type === "number") {
      console.log(field.config?.decimalPlaces); // 2
    } else if (field.type === "enum") {
      console.log(field.config.allowCustom); // true
    }
}

捐款

虽然我们重视对SDK的开源贡献,但这个库是程序生成的. 直接添加到这个库的代码必须移到我们的代号上,否则它们会在下一个生成的版本被覆盖. 随便打开公关作为概念的证明 但知道我们无法将公关合并 我们建议 打开一个问题 先和我们讨论!

另一方面,对 " README " 的贡献总是非常受欢迎的!

许可证

这个项目根据麻省理工学院许可证颁发——见 自由主义 详细文件.

版本与发布记录

@flatfile/api 共发布 179 个版本,首次发布于 2022/11/23;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.23.12025/11/061 年前
1.23.1-conditional-submit-routing.02025/08/301.2 年前
1.23.0latest2025/08/291.2 年前
1.22.02025/08/131.3 年前
1.21.02025/08/021.3 年前
1.20.02025/07/231.3 年前

其他发布通道:rc → 1.15.7-rc.1。

关于 @flatfile/api 的常见问题

@flatfile/api 是什么?

[[https://buildingwithfern.com/?utm source=平面过滤器/f

如何安装 @flatfile/api?

在项目目录运行 npm install @flatfile/api,或使用 pnpm add / yarn add / bun add。

@flatfile/api 支持 TypeScript 吗?

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

@flatfile/api 支持 ESM 还是 CommonJS?

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

@flatfile/api 可以商用吗?

@flatfile/api 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@flatfile/api 的下载量有多少?

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

@flatfile/api 还在维护吗?

最新版本 1.23.0 发布于 2025/08/29(1.2 年前);至今共发布 179 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/11/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。