import {z} from 'zod' export type GetApiV3TelemetryDestinationsDestinationIdArgs = {destination_id: string}; export type GetApiV3TelemetryDestinationsDestinationIdOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const telemetryContentMode = z.enum(["TELEMETRY_CONTENT_MODE_METADATA_ONLY", "TELEMETRY_CONTENT_MODE_FULL_CONTENT"]); export const telemetryProjectScope = z.enum(["TELEMETRY_PROJECT_SCOPE_ALL", "TELEMETRY_PROJECT_SCOPE_SELECTED", "TELEMETRY_PROJECT_SCOPE_ALL_EXCEPT"]); export const telemetryDestination = z.object({id: z.string().optional(), workspace_id: z.string().optional(), display_name: z.string().optional(), provider: z.string().optional(), endpoint_url: z.string().optional(), request_headers: z.record(z.string(), z.string()).optional(), settings: z.record(z.string(), z.string()).optional(), content_mode: telemetryContentMode.optional(), project_scope: telemetryProjectScope.optional(), project_ids: z.array(z.string()).optional(), enabled: z.boolean().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), failure_count: z.number().int().optional(), last_error: z.string().optional(), last_status_code: z.number().int().optional(), last_attempt_at: z.string().optional(), disabled_reason: z.string().optional()}); export const telemetryDestinationResponse = z.object({destination: telemetryDestination.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 }; /** * Retrieve an OpenTelemetry destination * * GET /v3/telemetry-destinations/{destination_id} */ export const getApiV3TelemetryDestinationsDestinationId = async (args: GetApiV3TelemetryDestinationsDestinationIdArgs, options?: GetApiV3TelemetryDestinationsDestinationIdOptions) => { const {baseUrl = "https://my.orq.ai", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3/telemetry-destinations/${encodeURIComponent(String(args.destination_id))}${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(telemetryDestinationResponse, await res.json()) };