export type CreateApiAccessesArgs = {body: {name: string, description?: string | undefined, permission_ids: Array, counter_ids: Array, station_ids: Array}}; export type CreateApiAccessesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create * * POST /accesses */ export const createApiAccesses = async (args: CreateApiAccessesArgs, options?: CreateApiAccessesOptions) => { const {baseUrl = "http://api.gostarmartbus.com/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/x-www-form-urlencoded") const url = `${baseUrl.replace(/\/+$/, '')}/accesses${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: new URLSearchParams(Object.entries(args.body).flatMap(([key, value]) => (value == null ? [] : [[key, String(value)]])))}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };