import {z} from 'zod' export type SessionID = string; export type DeleteApiV1FeedNodArgs = {sessionID?: SessionID | undefined, api_username?: string | undefined, signature?: string | undefined, timestamp?: string | undefined, app_partner?: string | undefined, app_name?: string | undefined, app_version?: string | undefined}; export type DeleteApiV1FeedNodOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const emptyResponse = z.object({}).nullable(); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * End/cancel a feed session * * DELETE /v1/feed/nod/ * * Also accepts auth: httpBasicAuth, hmacAuth */ export const deleteApiV1FeedNod = async (args: DeleteApiV1FeedNodArgs, options?: DeleteApiV1FeedNodOptions) => { const {baseUrl = "https://api.domaintools.com", fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.sessionID != null) query.append("sessionID", String(args.sessionID)) if (args.api_username != null) query.append("api_username", String(args.api_username)) if (args.signature != null) query.append("signature", String(args.signature)) if (args.timestamp != null) query.append("timestamp", String(args.timestamp)) if (args.app_partner != null) query.append("app_partner", String(args.app_partner)) if (args.app_name != null) query.append("app_name", String(args.app_name)) if (args.app_version != null) query.append("app_version", String(args.app_version)) if (apiKeyAuth !== undefined) headers.set("X-Api-Key", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/feed/nod/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(emptyResponse, await res.json()) };