import {z} from 'zod' export type VersionIdPathParam = string | 'latest'; export type RealityConnectorUrl = {type: 'url', url: string}; export type RealityConnectorAzureDevopsRepo = {accountName: string, projectId: string, repositoryId: string, type: 'azure-devops-repo'}; export type RealityConnectorAzureDevopsBranch = {accountName: string, branchName: string, projectId: string, repositoryId: string, type: 'azure-devops-branch'}; export type RealityConnectorAzureDevopsFolder = {accountName: string, branchName: string, path: string, projectId: string, repositoryId: string, type: 'azure-devops-folder'}; export type RealityConnectorAzureDevopsFile = {accountName: string, branchName: string, path: string, projectId: string, repositoryId: string, type: 'azure-devops-file'}; export type RealityConnectorBitbucketRepo = {projectId: string, repositoryId: string, type: 'bitbucket-repo', workspaceId: string}; export type RealityConnectorBitbucketBranch = {branchName: string, projectId: string, repositoryId: string, type: 'bitbucket-branch', workspaceId: string}; export type RealityConnectorBitbucketFolder = {branchName: string, path: string, projectId: string, repositoryId: string, type: 'bitbucket-folder', workspaceId: string}; export type RealityConnectorBitbucketFile = {branchName: string, path: string, projectId: string, repositoryId: string, type: 'bitbucket-file', workspaceId: string}; export type RealityConnectorBitbucketServerRepo = {projectId: number, repositoryId: number, serverUrl: string, type: 'bitbucket-server-repo'}; export type RealityConnectorBitbucketServerBranch = {branchName: string, projectId: number, repositoryId: number, serverUrl: string, type: 'bitbucket-server-branch'}; export type RealityConnectorBitbucketServerFolder = {branchName: string, path: string, projectId: number, repositoryId: number, serverUrl: string, type: 'bitbucket-server-folder'}; export type RealityConnectorBitbucketServerFile = {branchName: string, path: string, projectId: number, repositoryId: number, serverUrl: string, type: 'bitbucket-server-file'}; export type RealityConnectorGithubRepo = {ownerId: number, repositoryId: number, type: 'github-repo'}; export type RealityConnectorGithubBranch = {branchName: string, ownerId: number, repositoryId: number, type: 'github-branch'}; export type RealityConnectorGithubFolder = {branchName: string, ownerId: number, path: string, repositoryId: number, type: 'github-folder'}; export type RealityConnectorGithubFile = {branchName: string, ownerId: number, path: string, repositoryId: number, type: 'github-file'}; export type RealityConnectorGitlabRepo = {projectId: number, type: 'gitlab-repo'}; export type RealityConnectorGitlabBranch = {branchName: string, projectId: number, type: 'gitlab-branch'}; export type RealityConnectorGitlabFolder = {branchName: string, path: string, projectId: number, type: 'gitlab-folder'}; export type RealityConnectorGitlabFile = {branchName: string, path: string, projectId: number, type: 'gitlab-file'}; export type RealityConnector = RealityConnectorUrl | RealityConnectorAzureDevopsRepo | RealityConnectorAzureDevopsBranch | RealityConnectorAzureDevopsFolder | RealityConnectorAzureDevopsFile | RealityConnectorBitbucketRepo | RealityConnectorBitbucketBranch | RealityConnectorBitbucketFolder | RealityConnectorBitbucketFile | RealityConnectorBitbucketServerRepo | RealityConnectorBitbucketServerBranch | RealityConnectorBitbucketServerFolder | RealityConnectorBitbucketServerFile | RealityConnectorGithubRepo | RealityConnectorGithubBranch | RealityConnectorGithubFolder | RealityConnectorGithubFile | RealityConnectorGitlabRepo | RealityConnectorGitlabBranch | RealityConnectorGitlabFolder | RealityConnectorGitlabFile; export type RealityLinkStatus = 'valid' | 'invalid'; export type RealityLink = {connectionResolveUrl?: string | undefined, connector?: RealityConnector | undefined, customName?: (string | null) | undefined, index: number, url?: string | undefined, errorMessage?: string | undefined, id: string, name?: string | undefined, status?: RealityLinkStatus | undefined}; export type ADRRelatedItemType = 'adr' | 'diagram' | 'draft' | 'link'; export type ADRRelatedItem = {adrId?: string | undefined, diagramId?: string | undefined, draftId?: string | undefined, id: string, index: number, link?: RealityLink | undefined, type: ADRRelatedItemType}; export type ADRStatus = 'accepted' | 'draft' | 'rejected'; export type AuthType = 'user' | 'api-key' | 'notification-key' | 'service'; export type ADRStatusChange = {createdAt: string, createdBy: AuthType, createdById: string, status: ADRStatus}; export type ADRRequired = {commit?: number | undefined, content?: string | undefined, description?: string | undefined, name: string, relatedItems?: {[key: string]: ADRRelatedItem} | undefined, status: ADRStatus, statusChanges?: Array | undefined, handleId?: unknown | undefined}; export type CreateApiLandscapesLandscapeIdVersionsVersionIdAdrsArgs = {landscapeId: string, versionId: VersionIdPathParam, body: ADRRequired}; export type CreateApiLandscapesLandscapeIdVersionsVersionIdAdrsOptions = {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 createApiLandscapesLandscapeIdVersionsVersionIdAdrsResponse = z.object({adr: aDR}); 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 }; /** * Create * * POST /landscapes/{landscapeId}/versions/{versionId}/adrs * * Also accepts auth: BearerAuth */ export const createApiLandscapesLandscapeIdVersionsVersionIdAdrs = async (args: CreateApiLandscapesLandscapeIdVersionsVersionIdAdrsArgs, options?: CreateApiLandscapesLandscapeIdVersionsVersionIdAdrsOptions) => { 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))}/adrs${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApiLandscapesLandscapeIdVersionsVersionIdAdrsResponse, await res.json()) };