@@ -314,10 +314,8 @@ export const byPersonQualifier = (data: unknown): PersonQualifier => {
314
314
throw new InvalidArgumentError ( `Missing required fields in the parent hierarchy [${ JSON . stringify ( qualifier ) } ].` ) ;
315
315
}
316
316
317
- if ( qualifier . type === 'contact' && ! hasField ( qualifier , { name : 'contact_type' , type : 'string' } ) ) {
318
- throw new InvalidArgumentError ( `Missing or empty required fields [${ JSON . stringify ( qualifier ) } ].` ) ;
319
- } else if ( ! ( qualifier . type === 'person' ) ) {
320
- throw new InvalidArgumentError ( 'Expected `type` to be `person`.' ) ;
317
+ if ( ! hasValidContactType ( qualifier ) && ! hasValidLegacyContactType ( qualifier , 'person' ) ) {
318
+ throw new InvalidArgumentError ( 'Invalid type for contacts.' ) ;
321
319
}
322
320
323
321
if ( hasBloatedLineage ( qualifier ) ) {
@@ -341,9 +339,7 @@ export const isPersonQualifier = (data: unknown): data is PersonQualifier => {
341
339
return false ;
342
340
}
343
341
344
- if ( data . type === 'contact' && ! hasField ( data , { name : 'contact_type' , type : 'string' } ) ) {
345
- return false ;
346
- } else if ( ! ( data . type === 'person' ) ) {
342
+ if ( ! hasValidContactType ( data ) && ! hasValidLegacyContactType ( data , 'person' ) ) {
347
343
return false ;
348
344
}
349
345
@@ -364,3 +360,16 @@ const hasBloatedLineage = ( data: Record<string, unknown> ): boolean => {
364
360
}
365
361
return true ;
366
362
} ;
363
+
364
+ /** @internal */
365
+ const hasValidContactType = ( data : Record < string , unknown > ) : boolean => {
366
+ if ( data . type === 'contact' && hasField ( data , { name : 'contact_type' , type : 'string' } ) ) {
367
+ return true ;
368
+ }
369
+ return false ;
370
+ } ;
371
+
372
+ /** @internal */
373
+ const hasValidLegacyContactType = ( data : Record < string , unknown > , type :string ) : boolean => {
374
+ return data . type === type ;
375
+ } ;
0 commit comments