import { EventEmitter } from 'eventemitter3'; /** * Type for hex colors */ type Hex = `#${string}`; /** * Corresponds to the Branding Customizations. * * https://[ORG_SUBDOMAIN].oneschema.co/customizations */ interface OneSchemaBrandingCustomizations { primaryColor?: Hex; backgroundPrimaryColor?: Hex; backgroundSecondaryColor?: Hex; headerColor?: Hex; footerColor?: Hex; borderColor?: Hex; successColor?: Hex; warningColor?: Hex; errorColor?: Hex; modalFullscreen?: boolean; hideCloseButton?: boolean; modalMaskColor?: Hex; modalBorderRadius?: string; buttonBorderRadius?: string; buttonPrimaryFillColor?: Hex; buttonPrimaryStrokeColor?: Hex; buttonPrimaryTextColor?: Hex; buttonSecondaryFillColor?: Hex; buttonSecondaryStrokeColor?: Hex; buttonSecondaryTextColor?: Hex; buttonTertiaryFillColor?: Hex; buttonTertiaryStrokeColor?: Hex; buttonTertiaryTextColor?: Hex; buttonAlertFillColor?: Hex; buttonAlertStrokeColor?: Hex; buttonAlertTextColor?: Hex; fontUrl?: string; fontFamily?: string; fontColorPrimary?: Hex; fontColorSecondary?: Hex; fontColorPlaceholder?: Hex; hideLogo?: boolean; } /** * Type with options for mapping strategy customization */ type MappingStrategy = "exact" | "fuzzy" | "historical_user" | "historical_org" | "historical"; /** * Type with options for skipping the header row step */ type SkipHeaderRowStrategy = "always" | "detect" | "never"; /** * Type with options for allowing row deletion */ type RowDeletionStrategy = "selection" | "errors"; /** * Type with options for AI suggested mappings customization */ type AiSuggestedMappings = "column" | "picklist"; /** * Type with options for import experience customization */ type ImportExperience = "blockIfErrors" | "promptIfErrors" | "ignoreErrors"; /** * Type with options for sidebar details customization */ type SidebarDetails = "required" | "all"; /** * Available customization settings for OneSchema * For more information on a particular setting see https://docs.oneschema.co/docs/customizations */ interface ImporterCustomization extends OneSchemaBrandingCustomizations { fileSizeLimit?: number; illustrationUrl?: string; uploaderShowSidebar?: boolean; uploaderSidebarDetails?: SidebarDetails; uploaderShowSidebarBanner?: boolean; uploaderSidebarBannerText?: string; includeExcelTemplate?: boolean; skipHeaderRow?: SkipHeaderRowStrategy; includeUnmappedColumns?: boolean; mappingStrategy?: MappingStrategy[]; skipMapping?: MappingStrategy[]; aiSuggestedMappings?: AiSuggestedMappings[]; oneClickMode?: boolean; mappingShowSidebar?: boolean; mappingSidebarDetails?: SidebarDetails; mappingShowSidebarBanner?: boolean; mappingSidebarBannerText?: string | null; autofixAfterMapping?: boolean; acceptCodeHookSuggestions?: boolean; preventRowDeletion?: RowDeletionStrategy[]; importErrorUX?: ImportExperience; skipCleaning?: boolean; allowEmptyImports?: boolean; importMaxRowLimit?: number | null; importRowLimitHeader?: string | null; importRowLimitDescription?: string | null; showUploadEducationWidget?: boolean; uploadEducationWidgetMessage?: string; uploadEducationWidgetAutoOpen?: boolean; showSetHeaderEducationWidget?: boolean; setHeaderEducationWidgetMessage?: string; setHeaderEducationWidgetAutoOpen?: boolean; showMappingEducationWidget?: boolean; mappingEducationWidgetMessage?: string; mappingEducationWidgetAutoOpen?: boolean; showCleaningEducationWidget?: boolean; cleaningEducationWidgetMessage?: string; cleaningEducationWidgetAutoOpen?: boolean; /** * Text overrides */ backButtonText?: string; nextButtonText?: string; uploadPaneHeaderText?: string; uploaderHeaderText?: string; uploaderSubheaderText?: string; setHeaderPaneHeaderText?: string; mappingPaneHeaderText?: string; mappingUploadedColumnText?: string; mappingTemplateColumnText?: string; cleaningPaneHeaderText?: string; cleaningConfirmButtonText?: string; picklistMappingHeaderText?: string; picklistMappingSubheaderText?: string; picklistMappingUploadedColumnText?: string; picklistMappingTemplateColumnText?: string; } /** * @deprecated: Use `ImporterCustomization` instead. */ type OneSchemaCustomization = ImporterCustomization; /** * Configuration for importing data through a webhook. */ interface WebhookImportConfig { type: "webhook"; key: string; } /** * Configuration for importing local data. */ interface LocalImportConfig { type: "local"; metadataOnly?: boolean; } /** * Configuration for importing data through file upload. */ interface BaseFileUploadImportConfig { type: "file-upload"; url: string; headers?: { [headerName: string]: string; }; } interface CsvFileUploadImportConfig extends BaseFileUploadImportConfig { format: "csv"; formatOptions?: { headerStyle?: "names" | "keys"; }; } interface JsonFileUploadImportConfig extends BaseFileUploadImportConfig { format: "json"; } type FileUploadImportConfig = CsvFileUploadImportConfig | JsonFileUploadImportConfig; /** * Configuration for importing data, supporting various destination types. */ type ImportConfig = WebhookImportConfig | LocalImportConfig | FileUploadImportConfig; /** * Interface for column validation options for data type BOOLEAN */ interface BooleanValidationOptions { true_label: string; false_label: string; } /** * Interface for column validation options for data type NUMBER */ interface NumberValidationOptions { format?: "eu" | "us"; max_num?: number | null; min_num?: number | null; only_int?: boolean; allow_thousand_separators?: boolean; num_decimals?: number | null; } /** * Interfaces for column validation options for data type PICKLIST */ interface PicklistOption { value: string; values?: string[]; color?: string | null; alternative_names?: string[]; } interface PicklistValidationOptions { picklist_options: PicklistOption[]; } /** * Interface for column validation options for data type ENUM_COUNTRY */ interface EnumCountryValidationOptions { format: "name" | "code2" | "code3"; variant_set_mods?: string[]; } /** * Interface for column validation options for data type CURRENCY_CODE */ interface CurrencyCodeValidationOptions { format?: "code"; variant_set_mods?: string[]; } /** * Interface for column validation options for data type CUSTOM_REGEX */ interface CustomRegexValidationOptions { regex: string; error_message: string; } /** * Interface for column validation options for DATE data types ("Advanced ambiguous date detection") */ interface AdvancedAmbiguousDateDetectionValidationOptions { input_date_order: "dmy" | "mdy" | "ymd"; } /** * Interface for column validation options for data type MONEY */ interface MoneyValidationOptions { currency_symbol: "dollar" | "euro" | "pound" | "yen"; } /** * Interface for column validation options for data type ALPHABETICAL */ interface AlphabeticalValidationOptions { allow_spaces?: boolean; allow_special?: boolean; } /** * Interface for column validation options for data type FILE_NAME */ interface FileNameValidationOptions { extensions: string[]; } /** * Interface for column validation options for data type "ENUM_US_STATE_TERRITORY" */ interface EnumUsStateTerritoryValidationOptions { format: "name" | "code"; variant_set_mods?: ["include_dc"] | ["include_territories"] | ["include_dc", "include_territories"]; } /** * Base interface for template columns */ type OneSchemaTemplateColumn = { key: string; label: string; description: string; is_custom: boolean; is_required: boolean; is_unique: boolean; is_locked: boolean; is_hidden: boolean; is_unmappable: boolean; letter_case: string; min_char_limit: number; max_char_limit: number; delimiter: string; must_exist: boolean; default_value: string; mapping_hints: string[]; } & ({ data_type: "DOMAIN" | "EAN" | "EMAIL" | "IANA_TIMEZONE" | "IMEI" | "JSON" | "LOCATION_POSTALCODE" | "PERCENTAGE" | "PHONE_NUMBER" | "SSN_MASKED" | "SSN_UNMASKED" | "TEXT" | "TIME_HHMM" | "UNIT_OF_MEASURE" | "UPC_A" | "URL" | "US_PHONE_NUMBER_EXT" | "UUID"; } | { data_type: "ALPHABETICAL"; validation_options?: AlphabeticalValidationOptions; } | { data_type: "BOOLEAN"; validation_options: BooleanValidationOptions; } | { data_type: "CURRENCY_CODE"; validation_options?: CurrencyCodeValidationOptions; } | { data_type: "CUSTOM_REGEX"; validation_options: CustomRegexValidationOptions; } | { data_type: "DATE_ISO" | "DATE_MDY" | "DATE_DMY" | "DATE_YMD" | "DATE_DMMMY" | "DATETIME_ISO" | "DATETIME_MDYHM" | "DATETIME_DMYHM" | "UNIX_TIMESTAMP"; validation_options?: AdvancedAmbiguousDateDetectionValidationOptions; } | { data_type: "ENUM_COUNTRY"; validation_options?: EnumCountryValidationOptions; } | { data_type: "ENUM_US_STATE_TERRITORY"; validation_options?: EnumUsStateTerritoryValidationOptions; } | { data_type: "FILE_NAME"; validation_options?: FileNameValidationOptions; } | { data_type: "MONEY"; validation_options?: MoneyValidationOptions; } | { data_type: "NUMBER"; validation_options?: NumberValidationOptions; } | { data_type: "PICKLIST"; validation_options: PicklistValidationOptions; }); /** * @deprecated Use `OneSchemaTemplateColumn["data_type"]` instead. */ type TemplateColumnDataType = OneSchemaTemplateColumn["data_type"]; /** * Params for adding a column to a template */ type OneSchemaTemplateColumnToAdd = Pick & Partial; /** * Params for updating a column in a template */ type OneSchemaTemplateColumnToUpdate = Pick & Partial; /** * Params for removing a column from a template */ type OneSchemaTemplateColumnToRemove = Pick; /** * Type of validation hook: either "row" or "column". * For row hooks, each request sends a batch of rows. * For column hooks, each request will be sent with all rows. * For more information on a particular setting see https://docs.oneschema.co/docs/validation-webhook#validation-webhook */ type ValidationHookType = "row" | "column"; /** * Type of authorization used in the header of a validation hook: either "basic" or "bearer_user_jwt". * For "basic", the secret key is used to authenticate the request. * For "bearer_user_jwt", the user JWT is used to authenticate the request. * For more information on a particular setting see https://docs.oneschema.co/docs/validation-webhook#securing-your-validation-hook */ type ValidationHookAuthorizationType = "basic" | "bearer_user_jwt"; /** * Params for adding a validation hook to a template */ interface OneSchemaValidationHookToAdd { name: string; url: string; column_keys?: string[]; custom_column_keys?: string[]; hook_type?: ValidationHookType; authorization_type?: ValidationHookAuthorizationType; secret_key?: string; batch_size?: number; } type OneSchemaMappingValidationToAdd = { type: "required-column-group"; columns: string[]; }; /** * Overrides for a template * For more information on a particular setting see https://docs.oneschema.co/docs/per-customer-overrides-v2 */ interface OneSchemaTemplateOverrides { columns_to_add?: OneSchemaTemplateColumnToAdd[]; columns_to_update?: OneSchemaTemplateColumnToUpdate[]; columns_to_remove?: OneSchemaTemplateColumnToRemove[]; validation_hooks_to_add?: OneSchemaValidationHookToAdd[]; mapping_validations_to_add?: OneSchemaMappingValidationToAdd[]; } /** * Parameters that can be set when the OneSchema importer launches */ interface OneSchemaLaunchParams { /** * The JSON web token for the user importing data */ userJwt: string; /** * The key for the template that data will be imported for. * Setup inside OneSchema before using */ templateKey: string; /** * Template overrides to modify the behavior of the base template */ templateOverrides?: OneSchemaTemplateOverrides; /** * The configuration for how data should be imported from OneSchema */ importConfig?: ImportConfig; /** * Key for a customization setup in OneSchema */ customizationKey?: string; /** * Customization options for how OneSchema will behave */ customizationOverrides?: ImporterCustomization; /** * Event webhooks that should be used during an import session */ eventWebhookKeys?: string[]; } /** * Parameters that can be set when the OneSchema importer launches with a sessionToken */ interface OneSchemaLaunchSessionParams { /** * A token for a session created through the API for initializing OneSchema */ sessionToken: string; } /** * Possible errors when launching OneSchema */ declare enum OneSchemaLaunchError { MissingTemplate = 0, MissingJwt = 1, MissingSessionToken = 2, LaunchError = 3 } interface OneSchemaLaunchStatus { /** * Whether or not launch was successful */ success: boolean; /** * If success is true, include a session token */ sessionToken?: string; /** * If success is true, include the embed ID */ embedId?: string; /** * If success is false, this will be why it failed */ error?: OneSchemaLaunchError; } /** * Parameters for the OneSchema importer set at initialization */ interface OneSchemaInitParams { /** * The client id from your OneSchema developer dashboard */ clientId: string; /** * Whether to launch the importer in dev mode. * By default checks `process.env.NODE_ENV` for "production" */ devMode?: boolean; /** * CSS class for the iframe */ className?: string; /** * CSS Styles to be applied directly to the iframe */ styles?: Partial; /** * Optional language code (like 'en' or 'zh') to force importer language * By default, will use user's set language. * Requires enterprise licensing */ languageCode?: string; /** * The id of the DOM element the iframe should be appended to * By default appends to document.body */ parentId?: string; /** * Whether to save session information to local storage and enable resuming * Defaults to false */ saveSession?: boolean; /** * Whether to close the importer when complete. * Defaults to true */ autoClose?: boolean; /** * Whether the class should create and append iframe to DOM. * Default to true */ manageDOM?: boolean; /** * The base URL for the iframe. * By default uses OneSchema's production instance */ baseUrl?: string; } /** * Combined options for params used when launching OneSchema */ type OneSchemaLaunchParamOptions = OneSchemaLaunchParams | OneSchemaLaunchSessionParams; /** * Parameters for the OneSchema importer, includes all settings */ type OneSchemaParams = OneSchemaInitParams & Partial; /** * Message params shared for all messageTypes */ interface OneSchemaSharedInitParams { manualClose: boolean; version: string; client: string; } /** * Message params for init a standard OneSchemaImporter */ interface OneSchemaInitSimpleMessage extends OneSchemaSharedInitParams { messageType: "init"; userJwt: string; templateKey: string; importConfig: ImportConfig; customizationKey: string; customizationOverrides: ImporterCustomization; templateOverrides: OneSchemaTemplateOverrides; eventWebhookKeys: string[]; resumeToken?: string; } /** * Message params for init a OneSchemaImporter with a sessionToken */ interface OneSchemaInitSessionMessage extends OneSchemaSharedInitParams { messageType: "init-session"; sessionToken: string; } /** * Message passed to OneSchema for init */ type OneSchemaInitMessage = OneSchemaInitSimpleMessage | OneSchemaInitSessionMessage; /** * The default values for the OneSchema importer */ declare const DEFAULT_PARAMS: Partial; declare enum OneSchemaErrorSeverity { Error = "error", Fatal = "fatal" } interface OneSchemaError { message: string; severity: OneSchemaErrorSeverity; } /** * OneSchemaImporter class manages the iframe used for importing data in your * application and emits events based on what happens. */ declare class OneSchemaImporterClass extends EventEmitter { #private; iframe?: HTMLIFrameElement; _hasAttemptedLaunch: boolean; constructor(params: OneSchemaParams); /** * Set the name and version of the client, used for logging/debugging * @param client * @param version */ setClient(client: string, version: string): void; /** * Set the iframe to be used by the OneSchema importer * Should only be used in conjunction with the param of manageDOM false * @param iframe */ setIframe(iframe: HTMLIFrameElement): void; /** * Will change the CSS class of the iframe. * * @param className the new CSS class */ setClassName(className: string): void; /** * Will change the styles of the iframe. * * @param styles the styles to apply */ setStyles(styles: Partial): void; /** * Will change the parent container of the iframe * NOTE: will reload the URL * @param parent DOM element to append to */ setParent(parent: HTMLElement): void; /** * Launch will show the OneSchema window and initialize the importer session * @param launchParams optionally pass in parameter overrides or values not passed into constructor */ launch(launchParams?: Partial & Partial): OneSchemaLaunchStatus; /** * DEPRECATED: use `launch` instead. * Launch session will show the OneSchema window and initialize the importer session with the given session token * @param launchParams optionally pass in parameter overrides or values not passed into constructor */ launchSession(launchParams?: Partial): OneSchemaLaunchStatus; _launch(): void; _initWithRetry(count?: number): void; _resetSession(launchParams?: Partial & Partial): void; /** * Close will stop the importing session and hide the OneSchema window * @param clean will remove the iframe and event listeners if true */ close(clean?: boolean): void; emitErrorEvent(error: OneSchemaError): void; } /** * @param params the settings for the importing session * @returns an instance of the OneSchemaImporter */ declare function oneSchemaImporter(params: OneSchemaParams): OneSchemaImporterClass; export { AdvancedAmbiguousDateDetectionValidationOptions, AiSuggestedMappings, AlphabeticalValidationOptions, BaseFileUploadImportConfig, BooleanValidationOptions, CsvFileUploadImportConfig, CurrencyCodeValidationOptions, CustomRegexValidationOptions, DEFAULT_PARAMS, EnumCountryValidationOptions, EnumUsStateTerritoryValidationOptions, FileNameValidationOptions, FileUploadImportConfig, ImportConfig, ImportExperience, ImporterCustomization, JsonFileUploadImportConfig, LocalImportConfig, MappingStrategy, MoneyValidationOptions, NumberValidationOptions, OneSchemaCustomization, OneSchemaError, OneSchemaErrorSeverity, OneSchemaImporterClass, OneSchemaInitMessage, OneSchemaInitParams, OneSchemaInitSessionMessage, OneSchemaInitSimpleMessage, OneSchemaLaunchError, OneSchemaLaunchParamOptions, OneSchemaLaunchParams, OneSchemaLaunchSessionParams, OneSchemaLaunchStatus, OneSchemaMappingValidationToAdd, OneSchemaParams, OneSchemaSharedInitParams, OneSchemaTemplateColumn, OneSchemaTemplateColumnToAdd, OneSchemaTemplateColumnToRemove, OneSchemaTemplateColumnToUpdate, OneSchemaTemplateOverrides, OneSchemaValidationHookToAdd, PicklistValidationOptions, RowDeletionStrategy, SidebarDetails, SkipHeaderRowStrategy, TemplateColumnDataType, ValidationHookAuthorizationType, ValidationHookType, WebhookImportConfig, oneSchemaImporter as default };