import {z} from 'zod' export type GetApiV2OrganizationsOrganizationTelemetrySourcesSourceArgs = {organization: string, source: string}; export type GetApiV2OrganizationsOrganizationTelemetrySourcesSourceOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const v2SourceScopeType = z.enum(["INVALID", "SERVICE", "INGRESS", "RELATION"]); export const serviceScopesServiceScopeScopeType = z.enum(["INVALID", "INSTANCE", "SERVICE", "SUBSET", "GLOBAL_SUBSET", "GLOBAL"]); export const serviceScopesServiceScopeScope = z.object({instance: z.string().optional(), subset: z.string().optional(), service: z.string().optional(), namespace: z.string().optional(), cluster: z.string().optional()}); export const serviceScopesServiceScope = z.object({type: serviceScopesServiceScopeScopeType.optional(), scope: serviceScopesServiceScopeScope.optional(), deployment: z.string().optional()}); export const sourceScopeServiceScopes = z.object({scopes: z.array(serviceScopesServiceScope).optional()}); export const ingressScopesIngressScopeScopeType = z.enum(["INVALID", "HOSTNAME", "GLOBAL"]); export const ingressScopesIngressScopeScope = z.object({hostname: z.string().optional(), ingressService: z.string().optional(), cluster: z.string().optional()}); export const ingressScopesIngressScope = z.object({type: ingressScopesIngressScopeScopeType.optional(), scope: ingressScopesIngressScopeScope.optional(), deployment: z.string().optional()}); export const sourceScopeIngressScopes = z.object({scopes: z.array(ingressScopesIngressScope).optional()}); export const relationScopesRelationScopeScopeType = z.enum(["INVALID", "SERVICE"]); export const relationScopeServiceRelation = z.object({source: z.string().optional(), target: z.string().optional()}); export const relationScopesRelationScopeScope = z.object({serviceRelation: relationScopeServiceRelation.optional()}); export const relationScopesRelationScope = z.object({type: relationScopesRelationScopeScopeType.optional(), scope: relationScopesRelationScopeScope.optional()}); export const sourceScopeRelationScopes = z.object({scopes: z.array(relationScopesRelationScope).optional()}); export const v2SourceScope = z.object({serviceScopes: sourceScopeServiceScopes.optional(), ingressScopes: sourceScopeIngressScopes.optional(), relationScopes: sourceScopeRelationScopes.optional()}); export const v2Source = z.object({fqn: z.string().optional(), displayName: z.string().optional(), etag: z.string().optional(), description: z.string().optional(), belongsTo: z.string().optional(), metricSourceKey: z.string().optional(), type: v2SourceScopeType.optional(), scope: v2SourceScope.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 }; /** * Get the details of an existing telemetry source. * * GET /v2/organizations/{organization}/telemetry/sources/{source} */ export const getApiV2OrganizationsOrganizationTelemetrySourcesSource = async (args: GetApiV2OrganizationsOrganizationTelemetrySourcesSourceArgs, options: GetApiV2OrganizationsOrganizationTelemetrySourcesSourceOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v2/organizations/${encodeURIComponent(String(args.organization))}/telemetry/sources/${encodeURIComponent(String(args.source))}${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(v2Source, await res.json()) };