import {z} from 'zod' export type AmigoLibPydanticBaseModelStrippedNonemptyString1 = string; export type MetricValueType = 'boolean' | 'numerical' | 'categorical'; export type GetApiV1OrganizationMetricSearchArgs = {organization: string, query: AmigoLibPydanticBaseModelStrippedNonemptyString1, applied_to_service?: Array | undefined, type?: Array | undefined, creator?: Array | undefined, tag?: Array | undefined, 'x-mongo-cluster-name'?: (string | null) | undefined, 'Sec-WebSocket-Protocol'?: Array | undefined}; export type GetApiV1OrganizationMetricSearchOptions = {baseUrl?: string | undefined, BearerAuthorization?: string | undefined, BearerAuthorizationOrganization?: string | undefined, Basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const tag = z.object({key: z.string(), value: z.string().nullable()}); export const amigoLibMongoCollectionsMetricMetricUserInfo = z.object({org_id: z.string(), user_id: z.string()}); export const metricValueType = z.enum(["boolean", "numerical", "categorical"]); export const metric = z.object({_id: z.string(), org_id: z.string(), created_at: z.string().optional(), updated_at: z.string().optional(), name: z.string(), applied_to_services: z.array(z.string()), additional_notes: z.string().nullable(), tags: z.array(tag), creator: amigoLibMongoCollectionsMetricMetricUserInfo, updated_by: amigoLibMongoCollectionsMetricMetricUserInfo, metric_value_type: metricValueType, is_deleted: z.boolean()}); export const srcAppEndpointsMetricSearchMetricsResponse = z.object({metrics: z.array(metric)}); 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 }; /** * Search metrics * * GET /v1/{organization}/metric/search/ */ export const getApiV1OrganizationMetricSearch = async (args: GetApiV1OrganizationMetricSearchArgs, options?: GetApiV1OrganizationMetricSearchOptions) => { const {baseUrl = "https://api.amigo.ai", fetch: fetchFn = fetch, BearerAuthorization, BearerAuthorizationOrganization, Basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.query != null) query.append("query", String(args.query)) for (const item of args.applied_to_service ?? []) query.append("applied_to_service", String(item)) for (const item of args.type ?? []) query.append("type", String(item)) for (const item of args.creator ?? []) query.append("creator", String(item)) for (const item of args.tag ?? []) query.append("tag", String(item)) if (args['x-mongo-cluster-name'] != null) headers.set("x-mongo-cluster-name", String(args['x-mongo-cluster-name'])) if (args['Sec-WebSocket-Protocol'] != null) headers.set("Sec-WebSocket-Protocol", args['Sec-WebSocket-Protocol'].join(',')) if (BearerAuthorization !== undefined) headers.set('authorization', `Bearer ${BearerAuthorization}`) if (BearerAuthorizationOrganization !== undefined) headers.set("X-ORG-ID", BearerAuthorizationOrganization) if (Basic !== undefined) headers.set('authorization', `Basic ${btoa(`${Basic.username}:${Basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/${encodeURIComponent(String(args.organization))}/metric/search/${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(srcAppEndpointsMetricSearchMetricsResponse, await res.json()) };