@@ -10,6 +10,7 @@ import Meta from './obj.meta'
10
10
import RecordObject from './obj.record'
11
11
import CustomerObject from './obj.customer'
12
12
import LoadOptionsObject from './obj.load-options'
13
+ import IValidationResponse from './obj.validation-response'
13
14
14
15
export default class FlatfileImporter extends EventEmitter {
15
16
@@ -30,6 +31,7 @@ export default class FlatfileImporter extends EventEmitter {
30
31
31
32
private $resolver : ( data : any ) => any
32
33
private $rejecter : ( err : any ) => any
34
+ private $validatorCallback ?: ( row : { [ key : string ] : string | number } ) => Array < IValidationResponse > | Promise < Array < IValidationResponse > >
33
35
34
36
constructor ( apiKey : string , options : object , customer ?: CustomerObject ) {
35
37
super ( )
@@ -175,6 +177,16 @@ export default class FlatfileImporter extends EventEmitter {
175
177
} )
176
178
}
177
179
180
+ /**
181
+ * Set the customer information for this import
182
+ */
183
+ registerValidatorCallback ( callback : FlatfileImporter [ '$validatorCallback' ] ) : void {
184
+ this . $validatorCallback = callback
185
+ this . $ready . then ( ( child ) => {
186
+ child . parentHasValidator ( )
187
+ } )
188
+ }
189
+
178
190
/**
179
191
* Call close() from the parent window in order to hide the importer. You can do this after
180
192
* handling the import callback so your users don't have to click the confirmation button
@@ -230,9 +242,15 @@ export default class FlatfileImporter extends EventEmitter {
230
242
this . emit ( 'close' )
231
243
this . handleClose ( )
232
244
} ,
245
+ validatorCallback : ( row ) => {
246
+ return this . $validatorCallback ? this . $validatorCallback ( row ) : undefined
247
+ } ,
233
248
ready : ( ) => {
234
249
this . handshake . promise . then ( ( child ) => {
235
250
this . $resolver ( child )
251
+ if ( this . customer ) {
252
+ child . setUser ( this . customer )
253
+ }
236
254
} ) . catch ( ( err ) => {
237
255
console . error ( err )
238
256
} )
0 commit comments