import {z} from 'zod' export type ModelConnectionDirectionNullable = 'outgoing' | 'bidirectional'; 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 RealityLinkRequired = {connectionResolveUrl?: string | undefined, connector?: RealityConnector | undefined, customName?: (string | null) | undefined, index?: number | undefined, url?: string | undefined}; export type ModelConnectionStatus = 'deprecated' | 'future' | 'live' | 'removed'; export type ModelConnectionRequired = {commit?: number | undefined, description?: string | undefined, direction: ModelConnectionDirectionNullable, labels?: {[key: string]: string} | undefined, links?: {[key: string]: RealityLinkRequired} | undefined, name: string, originId: string, status?: ModelConnectionStatus | undefined, tagIds?: Array | undefined, targetId: string, technologyIds?: Array | undefined, viaId?: (string | null) | undefined, handleId?: string | undefined}; export type CreateApiLandscapesLandscapeIdVersionsVersionIdModelConnectionsArgs = {landscapeId: string, versionId: string, body: ModelConnectionRequired}; export type CreateApiLandscapesLandscapeIdVersionsVersionIdModelConnectionsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const modelConnectionDirectionNullable = z.enum(["outgoing", "bidirectional"]); 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 modelConnectionStatus = z.enum(["deprecated", "future", "live", "removed"]); export const authType = z.enum(["user", "api-key", "notification-key", "service"]); export const modelConnectionDiagram = z.object({connectionId: z.string(), id: z.string(), originModelId: z.string(), targetModelId: z.string()}); export const modelConnectionFlow = z.object({id: z.string(), stepId: z.string()}); export const modelConnection = z.object({commit: z.number(), description: z.string().max(950000).optional(), direction: modelConnectionDirectionNullable, labels: z.record(z.string(), z.string().max(5000)), links: z.record(z.string(), realityLink), name: z.string().max(4000), originId: z.string(), status: modelConnectionStatus, tagIds: z.array(z.string()), targetId: z.string(), technologyIds: z.array(z.string()), viaId: z.string().nullable(), handleId: z.string(), createdAt: z.string(), createdBy: authType, createdById: z.string(), deletedAt: z.string().optional(), deletedBy: authType.optional(), deletedById: z.string().optional(), diagrams: z.record(z.string(), modelConnectionDiagram), flows: z.record(z.string(), modelConnectionFlow), id: z.string(), landscapeId: z.string(), latestEntityId: z.string().optional(), linked: z.boolean(), updatedAt: z.string(), updatedBy: authType, updatedById: z.string(), version: z.number(), versionId: z.string()}); export const createApiLandscapesLandscapeIdVersionsVersionIdModelConnectionsResponse = z.object({modelConnection: modelConnection}); 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}/model/connections * * Also accepts auth: BearerAuth */ export const createApiLandscapesLandscapeIdVersionsVersionIdModelConnections = async (args: CreateApiLandscapesLandscapeIdVersionsVersionIdModelConnectionsArgs, options?: CreateApiLandscapesLandscapeIdVersionsVersionIdModelConnectionsOptions) => { 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))}/model/connections${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(createApiLandscapesLandscapeIdVersionsVersionIdModelConnectionsResponse, await res.json()) };