import {z} from 'zod' export type VersionIdPathParam = string | 'latest'; export type ADRStatus = 'accepted' | 'draft' | 'rejected'; export type ADRFilter = {name?: string | undefined, status?: (ADRStatus | Array) | undefined}; export type GetApiLandscapesLandscapeIdVersionsVersionIdAdrsArgs = {landscapeId: string, versionId: VersionIdPathParam, filter?: ADRFilter | undefined, cursor?: string | undefined, limit?: number | undefined}; export type GetApiLandscapesLandscapeIdVersionsVersionIdAdrsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const realityConnectorUrl = z.object({type: z.literal("url"), url: z.string()}); export const realityConnectorAzureDevopsRepo = z.object({accountName: z.string(), projectId: z.string(), repositoryId: z.string(), type: z.literal("azure-devops-repo")}); export const realityConnectorAzureDevopsBranch = z.object({accountName: z.string(), branchName: z.string(), projectId: z.string(), repositoryId: z.string(), type: z.literal("azure-devops-branch")}); export const realityConnectorAzureDevopsFolder = z.object({accountName: z.string(), branchName: z.string(), path: z.string(), projectId: z.string(), repositoryId: z.string(), type: z.literal("azure-devops-folder")}); export const realityConnectorAzureDevopsFile = z.object({accountName: z.string(), branchName: z.string(), path: z.string(), projectId: z.string(), repositoryId: z.string(), type: z.literal("azure-devops-file")}); export const realityConnectorBitbucketRepo = z.object({projectId: z.string(), repositoryId: z.string(), type: z.literal("bitbucket-repo"), workspaceId: z.string()}); export const realityConnectorBitbucketBranch = z.object({branchName: z.string(), projectId: z.string(), repositoryId: z.string(), type: z.literal("bitbucket-branch"), workspaceId: z.string()}); export const realityConnectorBitbucketFolder = z.object({branchName: z.string(), path: z.string(), projectId: z.string(), repositoryId: z.string(), type: z.literal("bitbucket-folder"), workspaceId: z.string()}); export const realityConnectorBitbucketFile = z.object({branchName: z.string(), path: z.string(), projectId: z.string(), repositoryId: z.string(), type: z.literal("bitbucket-file"), workspaceId: z.string()}); export const realityConnectorBitbucketServerRepo = z.object({projectId: z.number(), repositoryId: z.number(), serverUrl: z.string(), type: z.literal("bitbucket-server-repo")}); export const realityConnectorBitbucketServerBranch = z.object({branchName: z.string(), projectId: z.number(), repositoryId: z.number(), serverUrl: z.string(), type: z.literal("bitbucket-server-branch")}); export const realityConnectorBitbucketServerFolder = z.object({branchName: z.string(), path: z.string(), projectId: z.number(), repositoryId: z.number(), serverUrl: z.string(), type: z.literal("bitbucket-server-folder")}); export const realityConnectorBitbucketServerFile = z.object({branchName: z.string(), path: z.string(), projectId: z.number(), repositoryId: z.number(), serverUrl: z.string(), type: z.literal("bitbucket-server-file")}); export const realityConnectorGithubRepo = z.object({ownerId: z.number(), repositoryId: z.number(), type: z.literal("github-repo")}); export const realityConnectorGithubBranch = z.object({branchName: z.string(), ownerId: z.number(), repositoryId: z.number(), type: z.literal("github-branch")}); export const realityConnectorGithubFolder = z.object({branchName: z.string(), ownerId: z.number(), path: z.string(), repositoryId: z.number(), type: z.literal("github-folder")}); export const realityConnectorGithubFile = z.object({branchName: z.string(), ownerId: z.number(), path: z.string(), repositoryId: z.number(), type: z.literal("github-file")}); export const realityConnectorGitlabRepo = z.object({projectId: z.number(), type: z.literal("gitlab-repo")}); export const realityConnectorGitlabBranch = z.object({branchName: z.string(), projectId: z.number(), type: z.literal("gitlab-branch")}); export const realityConnectorGitlabFolder = z.object({branchName: z.string(), path: z.string(), projectId: z.number(), type: z.literal("gitlab-folder")}); export const realityConnectorGitlabFile = z.object({branchName: z.string(), path: z.string(), projectId: z.number(), type: z.literal("gitlab-file")}); export const realityConnector = z.union([realityConnectorUrl, realityConnectorAzureDevopsRepo, realityConnectorAzureDevopsBranch, realityConnectorAzureDevopsFolder, realityConnectorAzureDevopsFile, realityConnectorBitbucketRepo, realityConnectorBitbucketBranch, realityConnectorBitbucketFolder, realityConnectorBitbucketFile, realityConnectorBitbucketServerRepo, realityConnectorBitbucketServerBranch, realityConnectorBitbucketServerFolder, realityConnectorBitbucketServerFile, realityConnectorGithubRepo, realityConnectorGithubBranch, realityConnectorGithubFolder, realityConnectorGithubFile, realityConnectorGitlabRepo, realityConnectorGitlabBranch, realityConnectorGitlabFolder, realityConnectorGitlabFile]); export const realityLinkStatus = z.enum(["valid", "invalid"]); export const realityLink = z.object({connectionResolveUrl: z.string().optional(), connector: realityConnector.optional(), customName: z.string().nullable().optional(), index: z.number(), url: z.string().optional(), errorMessage: z.string().optional(), id: z.string(), name: z.string().optional(), status: realityLinkStatus.optional()}); export const aDRRelatedItemType = z.enum(["adr", "diagram", "draft", "link"]); export const aDRRelatedItem = z.object({adrId: z.string().optional(), diagramId: z.string().optional(), draftId: z.string().optional(), id: z.string(), index: z.number().gte(0), link: realityLink.optional(), type: aDRRelatedItemType}); export const aDRStatus = z.enum(["accepted", "draft", "rejected"]); export const authType = z.enum(["user", "api-key", "notification-key", "service"]); export const aDRStatusChange = z.object({createdAt: z.string(), createdBy: authType, createdById: z.string(), status: aDRStatus}); export const aDR = z.object({commit: z.number().gte(0), content: z.string().max(100000).optional(), description: z.string().max(6000).optional(), name: z.string().max(1000), relatedItems: z.record(z.string(), aDRRelatedItem).optional(), status: aDRStatus, statusChanges: z.array(aDRStatusChange).optional(), 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(), number: z.number(), updatedAt: z.string(), updatedBy: authType, updatedById: z.string(), version: z.number().gte(0), versionId: z.string()}); export const getApiLandscapesLandscapeIdVersionsVersionIdAdrsResponse = z.object({adrs: z.array(aDR), nextCursor: z.string().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 }; /** * List * * GET /landscapes/{landscapeId}/versions/{versionId}/adrs * * Also accepts auth: BearerAuth */ export const getApiLandscapesLandscapeIdVersionsVersionIdAdrs = async (args: GetApiLandscapesLandscapeIdVersionsVersionIdAdrsArgs, options?: GetApiLandscapesLandscapeIdVersionsVersionIdAdrsOptions) => { const {baseUrl = "https://api.icepanel.io/v1", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.filter != null) query.append("filter", JSON.stringify(args.filter)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.limit != null) query.append("limit", String(args.limit)) if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/landscapes/${encodeURIComponent(String(args.landscapeId))}/versions/${encodeURIComponent(String(args.versionId))}/adrs${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(getApiLandscapesLandscapeIdVersionsVersionIdAdrsResponse, await res.json()) };