export type GetApiPromocodesArgs = {name?: string | undefined, 'pagination[limit]'?: number | undefined, 'pagination[page]'?: number | undefined}; export type GetApiPromocodesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * List promocodes * * GET /promocodes */ export const getApiPromocodes = async (args: GetApiPromocodesArgs, options?: GetApiPromocodesOptions) => { const {baseUrl = "http://api.gostarmartbus.com/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.name != null) query.append("name", String(args.name)) if (args['pagination[limit]'] != null) query.append("pagination[limit]", String(args['pagination[limit]'])) if (args['pagination[page]'] != null) query.append("pagination[page]", String(args['pagination[page]'])) const url = `${baseUrl.replace(/\/+$/, '')}/promocodes${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 };