import {z} from 'zod' export type GetApiApplicationsApplicationIdInstancesIdJsonArgs = {application_id: number, id: number}; export type GetApiApplicationsApplicationIdInstancesIdJsonOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const appSummaryDataResponse = z.object({apdex_score: z.number().optional(), error_rate: z.number().optional(), instance_count: z.number().int().optional(), response_time: z.number().optional(), throughput: z.number().optional()}); export const endUserSummaryDataResponse = z.object({apdex_score: z.number().optional(), response_time: z.number().optional(), throughput: z.number().optional()}); export const applicationInstanceLinksResponse = z.object({application: z.number().int().optional(), application_host: z.number().int().optional(), server: z.number().int().optional()}); export const applicationInstanceResponseType = z.object({host: z.string().optional(), application_name: z.string().optional(), application_summary: appSummaryDataResponse.optional(), end_user_summary: endUserSummaryDataResponse.optional(), health_status: z.string().optional(), id: z.number().int().optional(), language: z.number().int().optional(), links: applicationInstanceLinksResponse.optional(), port: z.number().int().optional()}); export const applicationInstanceResponse = z.object({application_instance: applicationInstanceResponseType.optional()}); 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 }; /** * Show * * GET /applications/{application_id}/instances/{id}.json */ export const getApiApplicationsApplicationIdInstancesIdJson = async (args: GetApiApplicationsApplicationIdInstancesIdJsonArgs, options?: GetApiApplicationsApplicationIdInstancesIdJsonOptions) => { const {baseUrl = "https://api.newrelic.com/v2", fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (APIKeyHeader !== undefined) headers.set("Api-Key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/applications/${encodeURIComponent(String(args.application_id))}/instances/${encodeURIComponent(String(args.id))}.json${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 validateResponse(applicationInstanceResponse, await res.json()) };