11import { BrexIcon } from '@/components/icons'
22import type { BlockConfig , BlockMeta } from '@/blocks/types'
33import { AuthMode , IntegrationType } from '@/blocks/types'
4- import { normalizeFileInput , toOptionalBoolean , toOptionalFiniteNumber } from '@/blocks/utils'
4+ import { normalizeFileInput } from '@/blocks/utils'
55import type { BrexResponse } from '@/tools/brex/types'
66
77/** Coerces a required money-amount field to a finite number, throwing on blank/non-numeric input rather than silently sending 0 or NaN to Brex. */
@@ -16,6 +16,23 @@ function toRequiredAmount(value: unknown, fieldLabel: string): number {
1616 return parsed
1717}
1818
19+ /** Coerces an optional numeric field to a finite number, throwing on non-numeric input instead of silently forwarding NaN. Preserves explicit 0. */
20+ function toOptionalFiniteNumber ( value : unknown , fieldLabel : string ) : number | undefined {
21+ if ( value == null || ( typeof value === 'string' && value . trim ( ) === '' ) ) return undefined
22+ const parsed = Number ( value )
23+ if ( ! Number . isFinite ( parsed ) ) {
24+ throw new Error ( `${ fieldLabel } must be a valid number` )
25+ }
26+ return parsed
27+ }
28+
29+ /** Normalizes a boolean field that may arrive as a string (e.g. from a dynamic <Block.output> reference) instead of an actual boolean. */
30+ function toOptionalBoolean ( value : unknown ) : boolean | undefined {
31+ if ( value == null ) return undefined
32+ if ( typeof value === 'boolean' ) return value
33+ return String ( value ) . toLowerCase ( ) === 'true'
34+ }
35+
1936const PAGINATED_OPERATIONS = new Set ( [
2037 'list_expenses' ,
2138 'list_card_transactions' ,
0 commit comments