flatfile-csv-importer
Version:
A simple adapter for elegantly importing CSV files via flatfile.io (Typescript, ES6, Browser)
105 lines (104 loc) • 4.14 kB
TypeScript
import 'promise-polyfill/dist/polyfill';
import { EventEmitter } from 'eventemitter3';
import FlatfileResults from './results';
import CustomerObject from './obj.customer';
import LoadOptionsObject from './obj.load-options';
import { IDataHookRecord } from './obj.validation-response';
export default class FlatfileImporter extends EventEmitter {
static Promise: PromiseConstructor;
private static MOUNT_URL;
/**
* Promise that resolves when the handshake is completed between Flatfile.io and the adapter
*/
$ready: Promise<any>;
private apiKey;
private options;
private customer?;
private uuid;
private handshake;
private $resolver;
private $rejecter;
private $validatorCallback?;
private $recordHook?;
private $fieldHooks;
constructor(apiKey: string, options: object, customer?: CustomerObject);
/**
* This will by default always be `https://www.flatfile.io/importer/:key` unless you are
* an enterprise customer that is self-hosting the application. In which case, this
* will be the URL of your enterprise installd Flatfile importer index page
*/
static setMountUrl(url: string): void;
/**
* This allows you to opt into or out of specific versions of the Flatfile SDK
*/
static setVersion(version: 1 | 2): void;
/**
* Call open() to activate the importer overlay dialog.
*/
open(options?: {}): void;
/**
* Use load() when you want a promise returned. This is necessary if you want to use
* async/await for an es6 implementation
* @deprecated
*/
load(): Promise<Array<Object>>;
/**
* Use requestDataFromUser() when you want a promise returned. This is necessary if you want to use
* async/await for an es6 implementation
*/
requestDataFromUser(options?: LoadOptionsObject): Promise<FlatfileResults>;
/**
* This will display a progress indicator inside the importer if you anticipate that handling
* the output of the importer may take some time.
*/
displayLoader(msg?: string): void;
/**
* This will display a dialog inside of the importer with an error icon and the message you
* pass. The user will be able to acknowledge the error and be returned to the import data
* spreadsheet to ideally fix any issues or attempt submitting again.
* @deprecated
*/
displayError(msg: string): void;
/**
* This will display a dialog inside of the importer with an error icon and the message you
* pass. The user will be able to acknowledge the error and be returned to the import data
* spreadsheet to ideally fix any issues or attempt submitting again.
*/
requestCorrectionsFromUser(msg: any): Promise<FlatfileResults>;
/**
* This will display a dialog inside of the importer with a success icon and the message you
* pass.
*/
displaySuccess(msg: string): void;
/**
* This will fetch the data from the importer
*/
getMeta(): object;
/**
* Set the customer information for this import
*/
setCustomer(customer: CustomerObject): void;
/**
* Set the customer information for this import
*/
registerValidatorCallback(callback: FlatfileImporter['$validatorCallback']): void;
/**
* Set the customer information for this import
*/
registerRecordHook(callback: FlatfileImporter['$recordHook']): void;
/**
* Set the customer information for this import
*/
registerFieldHook(field: string, cb: FieldHookCallback): void;
/**
* Call close() from the parent window in order to hide the importer. You can do this after
* handling the import callback so your users don't have to click the confirmation button
*/
close(): void;
private handleClose;
private initialize;
private $generateUuid;
private responsePromise;
}
export declare type Scalar = string | number | boolean | null | undefined;
export declare type FieldHookCallback = (values: [Scalar, number][], meta: any) => [IDataHookRecord, number][] | Promise<[IDataHookRecord, number][]>;