@ingestro/importer-react 4.9.0 → 4.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +58 -0
  2. package/index.d.ts +16 -0
  3. package/index.js +391 -391
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -100,6 +100,64 @@ In this example:
100
100
 
101
101
  For a comprehensive guide on setting up and customizing the importer, refer to the [First Steps](https://docs.ingestro.com/sdk/start/) documentation.
102
102
 
103
+ ### Hook-based usage (`useDataImporter`)
104
+
105
+ `useDataImporter` is a hook-based alternative to the `DataImporter` component. It
106
+ accepts the **exact same configuration** as `<DataImporter />` (a superset of
107
+ `IConfigureAPI`, including `stepHandler`, the lifecycle callbacks and the
108
+ `onUploadSuccess` / `onUploadError` convenience callbacks) and mounts the same UI
109
+ into the element you attach the returned `ref` to.
110
+
111
+ ```jsx
112
+ import { useDataImporter } from '@ingestro/importer-react';
113
+
114
+ function ImportButton() {
115
+ const { ref, open, isReady, isUploading, error } = useDataImporter({
116
+ licenseKey: 'Your License Key',
117
+ settings: {
118
+ identifier: 'product_data',
119
+ columns: [
120
+ { label: 'Product ID', key: 'product_id' },
121
+ { label: 'Article Name', key: 'article_name' },
122
+ ],
123
+ },
124
+ onUploadSuccess: () => analytics.track('file-upload-success'),
125
+ onUploadError: ({ type, message }) => analytics.track('file-upload-error', { type, message }),
126
+ onResults: (results, errors, complete) => {
127
+ console.log('Imported Data:', results);
128
+ complete();
129
+ },
130
+ });
131
+
132
+ return (
133
+ <>
134
+ {/* Mounting this element renders the same UI as <DataImporter /> */}
135
+ <div ref={ref} />
136
+
137
+ <button onClick={open} disabled={!isReady || isUploading}>
138
+ Upload file
139
+ </button>
140
+
141
+ {error ? <p>{error.message}</p> : null}
142
+ </>
143
+ );
144
+ }
145
+ ```
146
+
147
+ The hook returns:
148
+
149
+ - **ref**: attach to an element (e.g. `<div ref={ref} />`) to mount the importer.
150
+ - **open()**: opens the importer (file picker / modal), mirroring the launcher button.
151
+ - **reload()**: reloads this instance (proxies `ImporterSession.reload` for its `identifier`).
152
+ - **isReady**: `true` once the instance is authorized/verified (parity with `ImporterSession.verify`).
153
+ - **isUploading**: `true` while a selected file is being parsed / uploaded.
154
+ - **error**: unified `{ type, message }` for verification or upload failures.
155
+
156
+ Because each hook instance owns its own container and `settings.identifier`,
157
+ multiple `useDataImporter` instances can coexist on one page and each remains
158
+ individually targetable by [`ImporterSession`](https://docs.ingestro.com/sdk/dynamic-import/)
159
+ (`parse` / `upload` / `start` / `verify` / `reload`) using its `identifier`.
160
+
103
161
  ## Advanced Configuration
104
162
 
105
163
  ### Settings & Configuration
package/index.d.ts CHANGED
@@ -687,6 +687,7 @@ export type SettingsAPI = {
687
687
  contextualEngine?: `${ContextualEngineType}`;
688
688
  columnMappingConfiguration?: IMappingConfiguration;
689
689
  baseUrl?: string;
690
+ completeImportLogging?: boolean;
690
691
  submitModalConfiguration?: ISubmitModalConfiguration;
691
692
  prompts?: boolean;
692
693
  successModalConfiguration?: ISuccessModalConfiguration;
@@ -2000,6 +2001,21 @@ export type LanguageType =
2000
2001
 
2001
2002
  export declare const DataImporter: (props: ConfigureAPI) => JSX.Element;
2002
2003
 
2004
+ export type UseDataImporterConfig = ConfigureAPI;
2005
+
2006
+ export type UseDataImporterReturn = {
2007
+ ref: (element: HTMLDivElement | null) => void;
2008
+ open: () => void;
2009
+ reload: () => void;
2010
+ isReady: boolean;
2011
+ isUploading: boolean;
2012
+ error: { type: string; message: string } | null;
2013
+ };
2014
+
2015
+ export declare const useDataImporter: (
2016
+ config: UseDataImporterConfig
2017
+ ) => UseDataImporterReturn;
2018
+
2003
2019
  export type DynamicStepValues =
2004
2020
  | 'header'
2005
2021
  | 'mapping'