import {z} from 'zod' export type ModelConnectionDirection = 'outgoing' | 'bidirectional'; export type ModelConnectionStatus = 'deprecated' | 'future' | 'live' | 'removed'; export type ModelConnectionFilter = {direction?: ModelConnectionDirection | undefined, handleId?: (string | Array) | undefined, labels?: {[key: string]: string} | undefined, linked?: boolean | undefined, name?: string | undefined, originId?: (string | Array) | undefined, status?: (ModelConnectionStatus | Array) | undefined, tagIds?: (string | Array) | undefined, targetId?: (string | Array) | undefined, technologyIds?: (string | Array) | undefined, viaId?: (string | Array) | undefined}; export type ModelConnectionExpandKey = 'technologies' | 'tags'; export type GetApiLandscapesLandscapeIdVersionsVersionIdModelConnectionsArgs = {landscapeId: string, versionId: string, filter?: ModelConnectionFilter | undefined, expand?: Array | undefined, cursor?: string | undefined, limit?: number | undefined}; export type GetApiLandscapesLandscapeIdVersionsVersionIdModelConnectionsOptions = {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 tagColor = z.enum(["blue", "green", "yellow", "orange", "red", "beaver", "dark-blue", "purple", "pink", "white", "grey", "black"]); export const tagExport = z.object({color: tagColor, groupId: z.string(), id: z.string(), name: z.string()}); export const catalogProviderNullable = z.enum(["aws", "azure", "gcp", "microsoft", "salesforce", "atlassian", "apache", "supabase", "null"]).nullable(); export const catalogTechnologyTypeNullable = z.enum(["data-storage", "deployment", "framework-library", "gateway", "other", "language", "message-broker", "network", "protocol", "runtime", "service-tool", "null"]).nullable(); export const technologyExport = z.object({color: tagColor, description: z.string().optional(), docsUrl: z.string().optional(), iconUrl: z.string().optional(), iconUrlDark: z.string().optional(), iconUrlLight: z.string().optional(), id: z.string(), name: z.string(), nameShort: z.string().optional(), provider: catalogProviderNullable, type: catalogTechnologyTypeNullable, updatesUrl: z.string().optional(), websiteUrl: z.string().optional()}); export const modelConnectionExpanded = 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(), tags: z.record(z.string(), tagExport).optional(), technologies: z.record(z.string(), technologyExport).optional()}); export const getApiLandscapesLandscapeIdVersionsVersionIdModelConnectionsResponse = z.object({modelConnections: z.array(modelConnectionExpanded), 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}/model/connections * * Also accepts auth: BearerAuth */ export const getApiLandscapesLandscapeIdVersionsVersionIdModelConnections = async (args: GetApiLandscapesLandscapeIdVersionsVersionIdModelConnectionsArgs, options?: GetApiLandscapesLandscapeIdVersionsVersionIdModelConnectionsOptions) => { 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)) for (const item of args.expand ?? []) query.append("expand", String(item)) 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))}/model/connections${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(getApiLandscapesLandscapeIdVersionsVersionIdModelConnectionsResponse, await res.json()) };