export type UpdateApiIpLabelsArgs = {ip: number, labels: Array}; export type UpdateApiIpLabelsOptions = {baseUrl?: string | undefined, APIKeyInHeader?: string | undefined, fetch?: typeof fetch | undefined}; /** * Assign labels to an IP * * PUT /ip/labels */ export const updateApiIpLabels = async (args: UpdateApiIpLabelsArgs, options?: UpdateApiIpLabelsOptions) => { const {baseUrl = "https://cyber-risk.upguard.com/api/public", fetch: fetchFn = fetch, APIKeyInHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.ip != null) query.append("ip", String(args.ip)) for (const item of args.labels ?? []) query.append("labels", String(item)) if (APIKeyInHeader !== undefined) headers.set("Authorization", APIKeyInHeader) const url = `${baseUrl.replace(/\/+$/, '')}/ip/labels${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };