@flatfile/v2-shims

中文文档
1.2.0发布于 2024/05/23ISCTypeScriptESM + CJS近 30 天下载 1.7万

A collection of helpers for migrating from v2 to platform

原始使用文档
文档目录3 节
  1. Convert Your Config
  2. Convert Your Data Hooks
  3. Handle Data Egress

@flatfile/v2-shims

This package is designed to help Flatfile Portal 2 customers upgrade quicker to the new Platform version. You can leverage this package to quickly convert your current setup to a Platform setup. To learn more about the new concepts and what's happening behind the scenes, you can go to the Platform documentation.

Convert Your Config

In Portal 2, the configuration was where everything got started. This contained your Flatfile settings and fields. The configToBlueprint method takes in your old configuration and will create a Platform Blueprint for it.

When we talk about your Flatfile config for Portal 2, we are talking about the Object that gets passed in as the 2nd parameter of the FlatfileImporter Class.

const importer = new FlatfileImporter(
  'License_Key',
  {} // This is your config Object
)

Below you can see some simple usage snippets of how this will look when converting:

import FlatfileImporter from '@flatfile/adapter'

const importer = new FlatfileImporter('License_Key', {
  type: 'Contacts',
  fields: [
    {
      key: 'name',
      label: 'Name',
      description: 'Contact name',
      validators: [{ validate: 'required' }],
    },
  ],
})
import { configToBlueprint } from '@flatfile/v2-shims'
import { configureSpace } from '@flatfile/plugin-space-configure'

const v2config = {
  type: 'Contacts',
  fields: [
    {
      key: 'name',
      label: 'Name',
      description: 'Contact name',
      validators: [{ validate: 'required' }],
    },
  ],
}

const blueprint = configToBlueprint(v2config)

export default function (listener) {
  listener.use(configureSpace({ workbooks: [blueprint] }))
}

Convert Your Data Hooks

The validators function implements v2 validator shims on any migrated schema. It is designed to be used as a middleware for Flatfile Platform integration. The function takes a sheetSlug as input and returns a function that can be used as a Listener with Flatfile.

import { validators } from '@flatfile/v2-shims';

// Define the sheetSlug for the schema you want to apply validators to
const sheetSlug = 'your-sheet-slug';

// Create a FlatfileListener instance
const flatfileListener = ...; // Initialize your FlatfileListener

// Use the validators function to attach validator shims to the listener
flatfileListener.use(validators(sheetSlug));

Handle Data Egress

This function is a plugin designed to handle data from Flatfile. It's used with a Flatfile Listener and is intended for processing data after a submission action in your Flatfile integration. It takes a handler function as input, which is responsible for processing the data and returns a Listener that can be used with Flatfile.

import { handleData } from '@flatfile/v2-shims'

// Define your data handling logic in the handler function
const handler = (results) => {
  // Example data handling logic
  console.log('Received Flatfile Results:')
  console.log(results)
}

// Initialize a FlatfileListener (assuming you have the necessary setup)
const flatfileListener = Flatfile.listener({
  // Configure your Flatfile settings here
  apiKey: 'your-api-key',
  // ...
})

// Use the handleData function to attach data handling functionality to the listener
flatfileListener.use(handleData(handler))

// Define event handling logic (e.g., on job:ready event) as needed
flatfileListener.on('job:ready', (event) => {
  // Handle the job:ready event
})

版本与发布记录

@flatfile/v2-shims 共发布 14 个版本,首次发布于 2023/10/07;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.2.0latest2024/05/232 年前
1.1.42024/05/022 年前
1.1.22024/02/082 年前
1.1.12024/02/072 年前
1.1.02024/02/072 年前
1.0.12024/01/272 年前

关于 @flatfile/v2-shims 的常见问题

@flatfile/v2-shims 是什么?

A collection of helpers for migrating from v2 to platform

如何安装 @flatfile/v2-shims?

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

@flatfile/v2-shims 支持 TypeScript 吗?

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

@flatfile/v2-shims 支持 ESM 还是 CommonJS?

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

@flatfile/v2-shims 可以商用吗?

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

@flatfile/v2-shims 的下载量有多少?

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

@flatfile/v2-shims 还在维护吗?

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