import {z} from 'zod' export type GitProviderType = 'GITHUB_CLOUD' | 'GITHUB_SERVER' | 'GITLAB_CLOUD' | 'GITLAB_SELF_MANAGED' | 'BITBUCKET_CLOUD' | 'BITBUCKET_DATACENTER' | 'AZURE'; export type CreateRemote = {mountPath: string, type: 'CICD' | 'GIT' | 'URL', autoSync?: boolean | undefined, autoMerge?: boolean | undefined, createdAt?: string | undefined, updatedAt?: string | undefined, providerType?: GitProviderType | undefined, namespaceId?: string | undefined, repositoryId?: string | undefined, projectId?: (string | null) | undefined, mountBranchName?: string | undefined, contentPath?: string | undefined, credentialId?: string | undefined, branchName?: string | undefined, contentType?: ('FOLDER' | 'FILE') | undefined}; export type CreateApiOrgsOrgIdProjectsProjectIdRemotesArgs = {body: CreateRemote}; export type CreateApiOrgsOrgIdProjectsProjectIdRemotesOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const gitProviderType = z.enum(["GITHUB_CLOUD", "GITHUB_SERVER", "GITLAB_CLOUD", "GITLAB_SELF_MANAGED", "BITBUCKET_CLOUD", "BITBUCKET_DATACENTER", "AZURE"]); export const remote = z.object({mountPath: z.string(), type: z.enum(["CICD", "GIT", "URL"]), autoSync: z.boolean().optional(), autoMerge: z.boolean().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), providerType: gitProviderType.optional(), namespaceId: z.string().optional(), repositoryId: z.string().optional(), projectId: z.string().nullable().optional(), mountBranchName: z.string().optional(), contentPath: z.string().optional(), credentialId: z.string().optional(), branchName: z.string().optional(), contentType: z.enum(["FOLDER", "FILE"]).optional(), id: z.string()}); 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 }; /** * Upsert remote * * POST /orgs/{orgId}/projects/{projectId}/remotes * * Also accepts auth: UserCookie */ export const createApiOrgsOrgIdProjectsProjectIdRemotes = async (args: CreateApiOrgsOrgIdProjectsProjectIdRemotesArgs, options?: CreateApiOrgsOrgIdProjectsProjectIdRemotesOptions) => { const {baseUrl = "https://app.cloud.redocly.com/api", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/orgs/${encodeURIComponent(String(args.orgId))}/projects/${encodeURIComponent(String(args.projectId))}/remotes${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(remote, await res.json()) };