import {z} from 'zod' export type DomainPartial = {commit?: number | undefined, index?: number | undefined, labels?: {[key: string]: string} | undefined, name?: string | undefined}; export type PatchApiLandscapesLandscapeIdVersionsVersionIdDomainsDomainIdArgs = {landscapeId: string, versionId: string, domainId: string, body: DomainPartial}; export type PatchApiLandscapesLandscapeIdVersionsVersionIdDomainsDomainIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const authType = z.enum(["user", "api-key", "notification-key", "service"]); export const domain = z.object({commit: z.number(), index: z.number(), labels: z.record(z.string(), z.string().max(5000)), name: z.string().max(4000), handleId: z.string(), createdAt: z.string(), createdBy: authType, createdById: z.string(), deletedAt: z.string().optional(), deletedBy: authType.optional(), deletedById: z.string().optional(), id: z.string(), landscapeId: z.string(), latestEntityId: z.string().optional(), updatedAt: z.string(), updatedBy: authType, updatedById: z.string(), version: z.number(), versionId: z.string()}); export const patchApiLandscapesLandscapeIdVersionsVersionIdDomainsDomainIdResponse = z.object({domain: domain}); 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 }; /** * Update * * PATCH /landscapes/{landscapeId}/versions/{versionId}/domains/{domainId} * * Also accepts auth: BearerAuth */ export const patchApiLandscapesLandscapeIdVersionsVersionIdDomainsDomainId = async (args: PatchApiLandscapesLandscapeIdVersionsVersionIdDomainsDomainIdArgs, options?: PatchApiLandscapesLandscapeIdVersionsVersionIdDomainsDomainIdOptions) => { const {baseUrl = "https://api.icepanel.io/v1", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/landscapes/${encodeURIComponent(String(args.landscapeId))}/versions/${encodeURIComponent(String(args.versionId))}/domains/${encodeURIComponent(String(args.domainId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(patchApiLandscapesLandscapeIdVersionsVersionIdDomainsDomainIdResponse, await res.json()) };