Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@flatfile/adapter

flatfilers62.3kMIT2.9.6TypeScript support: included

A lightweight TypeScript/JavaScript adapter for working with Flatfile's Portal

csv, importer, import, convert, json, parse, parser, csv-parse, parse, async, await, ES6, ES7, typescript

readme

Flatfile.com CSV Importer Adapter

Build Status Standard Version dependencies Status devDependencies Status

A simple adapter for elegantly importing data (CSV, XLS & more) via flatfile.com (Typescript, ES6, Browser)

Important note: While the below info is a basic way to get up and running, we recommend reading the developer docs → https://flatfile.com/developers/javascript/getting-started

Another note: If you are using Angular or React, we have specific packages for those. Check out our React package on GitHub and Angular package on GitHub.

License Key

In order to setup, you need to create or sign in to your flatfile.com account and obtain a license key.

Changelog

To view information about the latest releases and any minor/major changes, check out the changelog here.

Note: In version 2.8, previously available "deep-imports" (for Interfaces) have been moved to the root level of @flatfile/adapter.

Using NPM

If you don't like external dependencies, or you have a nice build system like Webpack in place. You can install and use Flatfile as an npm package.

npm i @flatfile/adapter --save

Using CDN

The latest version of the package is available via CDN so you can just drop it into your website and start using it.

https://unpkg.com/@flatfile/adapter/build/dist/index.min.js

Quickstart

Add the following code before the ending </body> tag in your html.

<script src="https://unpkg.com/@flatfile/adapter/build/dist/index.min.js"></script>

<script>
  const LICENSE_KEY = '00000000-0000-0000-0000-000000000000' // replace this with your license key

  const importer = new FlatfileImporter(LICENSE_KEY, {
    type: 'Robot',
    fields: [
      {
        label: 'Name',
        key: 'name',
        validators: [ { validate: 'unique' } ]
      },
      {
        label: 'Phone',
        key: 'phone',
        alternates: ['number', 'tel'],
        validators: [
          {
            validate: 'regex_matches',
            regex: '^\d{10}$'
          }
        ]
      },
      {
        label: 'Country',
        key: 'country',
        type: 'select',
        options: [
          { value: 'US', label: 'United States' },
          { value: 'CA', label: 'Canada' }
        ]
      }
    ]
  })

  // More info: https://flatfile.com/developers/javascript/getting-started/#the-basics
  importer.setCustomer({
    userId: '1'
  })

  importer.requestDataFromUser().then((results) => {
    importer.displayLoader('Please wait while your data is loading')

    // do something with your data
    setTimeout(() => {
      // console.log(results)

      importer.displaySuccess('You are all done!')
    }, 1000)
  })
</script>

ES6 / Babel

const LICENSE_KEY = '00000000-0000-0000-0000-000000000000' // replace this with your license key

const importer = new FlatfileImporter(LICENSE_KEY, {
  type: 'Robot',
  fields: [
    {
      label: 'Name',
      key: 'name'
    }
  ]
})

// More info: https://flatfile.com/developers/javascript/getting-started/#the-basics
importer.setCustomer({
  userId: '1'
})

document.querySelector('button').addEventListener('click', async () => {
  try{
    const results = await importer.requestDataFromUser()

    importer.displayLoader('Please wait while your data is loading')

    // do something with your data
    setTimeout(() => {
      // console.log(results)

      importer.displaySuccess('You are all done!')
    }, 1000)
  }catch(e){
    // handle a failed upload
  }
})

Data hooks

Flatfile's Data Hooks are a useful data healing element to re-format, validate and/or correct data automatically during the import without the user having to correct manually.

More information: Getting started with Data Hooks

const importer = new FlatfileImporter(LICENSE_KEY, {
  type: 'Robot',
  fields: [
    {
      label: 'Name',
      key: 'name'
    }
  ]
})

importer.setCustomer({
  userId: '1'
})

// adding a data hook that will add 'Jr.' to the name in each row
importer.registerRecordHook((row) => {
  // Example row: {name: 'John'}
  const result = {};

  if (row.name) {
    result.name = {
      value: `${row.name} Jr.`
    };
  }

  return result;
});

Themes

Theming gives you independent control over the look and feel of Flatfile Portal. With this, you can adjust both a global styles and individual components within the importer, as well as control the CSS pseudo-class :hover & :focus on buttons.

More information: Custom Themes for Flatfile Portal

const importer = new FlatfileImporter(LICENSE_KEY, {
  type: 'Robot',
  fields: [
    {
      label: 'Name',
      key: 'name'
    }
  ],
  theme: {
    global: {
      backgroundColor: '#212327',
      textColor: '#c2c3c3',
      primaryTextColor: '#c2c3c3',
      secondaryTextColor: '#c2c3c3',
      successColor: '#c2c3c3',
      warningColor: '#c2c3c3'
    },
    // other keys below
  }
})

Promise Overrides

Flatfile includes a basic native compatible Promise shim for IE support. You can override this with your preferred library by using the following global setting:

FlatfileImporter.Promise = Bluebird.Promise

changelog

Change Log

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

2.8.0 (2020-04-20)

Breaking Changes

  • All default exports have been removed, all publicly available interfaces or classes are now available from @flatfile/adapter (no deep-imports), with the exception being FlatfileImporter itself being exported from the default.

An example of these new imports and usage:

import FlatfileImporter, { // <-- still found at the default export level
  FieldHookCallback, // <-- everything else public is now available via destructuring from @flatfile/adapter
  ISettings,
  CustomerObject,
  LoadOptionsObject,
  IVirtualFieldOptions,
  IInteractionEvent,
  IBeforeFetchRequest,
  IBeforeFetchResponse,
  StepHookCallback,
  RecordObject,
  IDataHookResponse,
  ScalarDictionary,
  Nullable,
  IPrimitive,
  IValidationResponse,
  IDictionary,
  FlatfileResults
} from '@flatfile/adapter';
  • FlatfileResult is now found from the root of import { FlatfileResult } from '@flatfile/adapter';
    • Previously it was grabbed via default import from a deep-import import FlatfileResults from '@flatfile/adapter/build/main/results';

2.1.4 (2020-11-03)

2.1.3 (2020-11-03)

Bug Fixes

  • adapter: only polyfill document if exists (06b4ab7)

0.2.11 (2020-06-17)

Bug Fixes

  • imports: release 0.2.10 (a601586)

0.2.9 (2020-02-04)

0.2.8 (2020-02-04)

0.2.7 (2020-01-29)

0.2.6 (2020-01-20)

0.2.5 (2020-01-17)

0.2.4 (2020-01-07)

0.2.2 (2019-10-24)

0.2.0 (2019-10-24)

Features

  • add custom validator callbacks (6ee8ef9)

0.1.16 (2019-06-09)

0.1.15 (2019-06-09)

0.1.14 (2019-05-19)

0.1.13 (2019-05-19)

0.1.12 (2018-07-11)

0.1.11 (2018-07-11)

0.1.10 (2018-07-11)

0.1.9 (2018-04-24)

0.1.8 (2018-04-24)

0.1.7 (2018-04-24)

0.1.6 (2018-04-24)

0.1.5 (2018-04-24)

0.1.4 (2018-04-24)

0.1.3 (2018-04-24)

0.1.2 (2018-04-24)

0.1.1 (2018-04-24)

0.1.0 (2018-04-24)

0.0.7 (2018-03-27)

0.0.6 (2018-01-03)

0.0.5 (2018-01-03)

0.0.4 (2018-01-03)

0.0.3 (2018-01-03)

0.0.2 (2018-01-03)

1.4.1 (2017-06-27)

1.4.0 (2017-03-02)

Features

  • gh-pages: add package script for publishing docs to gh-pages (1dfe830), closes #14
  • publish: add one-step publish process (7b9b857), closes #15

1.3.0 (2017-03-01)

Bug Fixes

  • hash.js: correctly pre-build hash.js for the browser (1fe0b10)
  • watch: exclude build/*/.spec.js from ava to avoid double execution (e365656)

Features

  • browser: add browser build, tests, and sample sha256 library method (01f67d1)
  • watch: use concurrently for the watch task (7fa64b8), closes #11

1.2.2 (2017-02-17)

Bug Fixes

  • tsconfig: set rootDir option when outDir option is used (3577caa), closes #9

1.2.1 (2017-02-14)

1.2.0 (2017-02-14)

Features

  • github: add sample GitHub issue template, PR template, and contributing guidelines (9c95249)
  • watch: add unified watch task with multiview (973966e)

1.1.1 (2017-02-13)

1.1.0 (2017-02-13)

Features

  • examples: improve browser usage example (c8199e7)
  • starter: add changelogs and examples (5f18048)