import {z} from 'zod' export type GetApiVcsProvidersVcsProviderArgs = {vcs_provider: string, include?: Array<'agent-pool'> | undefined, fields?: ({'agent-pools'?: string | undefined, 'vcs-providers'?: string | undefined}) | undefined}; export type GetApiVcsProvidersVcsProviderOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const vcsProvider = z.object({attributes: z.object({"applies-enabled": z.boolean().optional(), "auth-type": z.enum(["oauth2", "personal_token"]), "auto-merge": z.boolean().optional(), "comments-enabled": z.boolean().optional(), "compare-strategy": z.enum(["base-commit", "previous-commit"]).optional(), "draft-pr-runs-enabled": z.boolean().optional(), "error-message": z.string().nullable().optional(), "inaccessible-repos": z.array(z.string()).optional(), "is-shared": z.boolean().optional(), name: z.string().min(1).max(255), "plans-enabled": z.boolean().optional(), "pr-merge-comments-enabled": z.boolean().optional(), "report-method": z.enum(["commit-status", "check", "both"]).optional(), "report-mode": z.enum(["per-workspace", "cumulative"]).optional(), token: z.string().nullable().optional(), url: z.string().min(1).max(255).nullable().optional(), username: z.string().max(255).nullable().optional(), "vcs-type": z.enum(["github", "gitlab", "bitbucket", "bitbucket_enterprise", "gitlab_enterprise", "github_enterprise", "azure_dev_ops_services"])}), id: z.string().optional(), links: z.object({self: z.string().optional()}).optional(), relationships: z.object({account: z.object({data: z.object({id: z.string(), type: z.enum(["accounts", ""])}).nullable()}).optional(), "agent-pool": z.object({data: z.object({id: z.string(), type: z.enum(["agent-pools", ""])}).nullable()}).optional(), environments: z.object({data: z.array(z.object({id: z.string(), type: z.enum(["environments", ""])})).nullable()}).optional()}).optional(), type: z.literal("vcs-providers")}); export const vcsProviderDocument = z.object({data: vcsProvider.optional(), included: z.array(z.object({})).optional(), meta: z.object({}).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 }; /** * Get a VCS Provider * * GET /vcs-providers/{vcs_provider} */ export const getApiVcsProvidersVcsProvider = async (args: GetApiVcsProvidersVcsProviderArgs, options?: GetApiVcsProvidersVcsProviderOptions) => { const {baseUrl = "https://example.scalr.io/api/iacp/v3", fetch: fetchFn = fetch, APIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/vnd.api+json") if (args.include != null) query.append("include", args.include.join(',')) if (args.fields != null) query.append("fields", JSON.stringify(args.fields)) if (APIKey !== undefined) headers.set('authorization', `Bearer ${APIKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/vcs-providers/${encodeURIComponent(String(args.vcs_provider))}${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(vcsProviderDocument, await res.json()) };