export type GetApiLegalEntitiesArgs = {after_cursor?: string | undefined, per_page?: number | undefined, legal_entity_type?: string | undefined, metadata?: string | undefined, status?: string | undefined}; export type GetApiLegalEntitiesOptions = {baseUrl?: string | undefined, sec0?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * List Legal Entities * * GET /legal_entities */ export const getApiLegalEntities = async (args: GetApiLegalEntitiesArgs, options?: GetApiLegalEntitiesOptions) => { const {baseUrl = "https://app.moderntreasury.com/api", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.after_cursor != null) query.append("after_cursor", String(args.after_cursor)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.legal_entity_type != null) query.append("legal_entity_type", String(args.legal_entity_type)) if (args.metadata != null) query.append("metadata", String(args.metadata)) if (args.status != null) query.append("status", String(args.status)) if (sec0 !== undefined) headers.set('authorization', `Basic ${btoa(`${sec0.username}:${sec0.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/legal_entities${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };