main
ts 22 lines 803 Bytes
Raw
1 import type { AxiosRequestConfig } from "axios"
2
3 /**
4 * Merge an optional multi-customer filter into an axios request config.
5 *
6 * When `customerCodes` has entries they are appended as repeated query params
7 * (`customer_codes=a&customer_codes=b`) — the shape FastAPI's
8 * `List[str] = Query(...)` expects — via `paramsSerializer: { indexes: null }`.
9 * When empty/undefined the original config is returned untouched, so callers
10 * fall back to "all accessible customers" exactly as before.
11 */
12 export function withCustomerCodes(customerCodes?: string[], config: AxiosRequestConfig = {}): AxiosRequestConfig {
13 if (!customerCodes?.length) {
14 return config
15 }
16
17 return {
18 ...config,
19 params: { ...(config.params ?? {}), customer_codes: customerCodes },
20 paramsSerializer: { indexes: null }
21 }
22 }