import {z} from 'zod' export type HelmPortProtocolEnum = 'HTTP' | 'GRPC'; export type KubernetesSelector = {key: string, value: string}; export type HelmGitRepositoryRequest = {url: string, branch?: string | undefined, root_path?: string | undefined, git_token_id?: (string | null) | undefined}; export type HelmKeyValues = Array>; export type GitProviderEnum = 'BITBUCKET' | 'GITHUB' | 'GITLAB'; export type ApplicationGitRepositoryRequest = {url: string, branch?: string | undefined, root_path?: string | undefined, git_token_id?: (string | null) | undefined, provider: GitProviderEnum}; export type HelmRequest = {ports?: (Array<{name?: string | undefined, internal_port: number, external_port?: number | undefined, namespace?: string | undefined, protocol?: HelmPortProtocolEnum | undefined, is_default?: boolean | undefined, service_selectors?: Array | undefined} | {name?: string | undefined, internal_port: number, external_port?: number | undefined, namespace?: string | undefined, protocol?: HelmPortProtocolEnum | undefined, is_default?: boolean | undefined, service_name?: string | undefined}>) | undefined, name: string, description?: string | undefined, timeout_sec?: number | undefined, auto_preview?: (boolean | null) | undefined, auto_deploy: boolean, source: {git_repository?: HelmGitRepositoryRequest | undefined} | {helm_repository?: ({repository?: (unknown | null) | undefined, chart_name?: string | undefined, chart_version?: string | undefined}) | undefined}, arguments: Array, allow_cluster_wide_resources?: boolean | undefined, values_override: {set?: HelmKeyValues | undefined, set_string?: HelmKeyValues | undefined, set_json?: HelmKeyValues | undefined, file?: ({git?: ({git_repository: ApplicationGitRepositoryRequest, paths: Array} | null) | undefined, raw?: ({values?: (Array<{name?: string | undefined, content?: string | undefined}>) | undefined} | null) | undefined} | null) | undefined}, icon_uri?: string | undefined}; export type CreateApiEnvironmentEnvironmentIdHelmArgs = {environmentId: string, body: HelmRequest}; export type CreateApiEnvironmentEnvironmentIdHelmOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const referenceObject = z.object({id: z.string()}); export const helmPortProtocolEnum = z.enum(["HTTP", "GRPC"]); export const helmPortResponseWithServiceName = z.object({id: z.string(), port_type: z.string(), name: z.string().optional(), internal_port: z.number().int(), external_port: z.number().int().optional(), namespace: z.string().optional(), protocol: helmPortProtocolEnum, is_default: z.boolean().optional(), service_name: z.string()}); export const kubernetesSelector = z.object({key: z.string(), value: z.string()}); export const helmPortResponseWithServiceSelectors = z.object({id: z.string(), port_type: z.string(), name: z.string().optional(), internal_port: z.number().int(), external_port: z.number().int().optional(), namespace: z.string().optional(), protocol: helmPortProtocolEnum, is_default: z.boolean().optional(), service_selectors: z.array(kubernetesSelector)}); export const gitProviderEnum = z.enum(["BITBUCKET", "GITHUB", "GITLAB"]); export const applicationGitRepository = z.object({has_access: z.boolean().optional(), provider: gitProviderEnum, owner: z.string(), url: z.string(), name: z.string(), branch: z.string().optional(), root_path: z.string().optional(), deployed_commit_id: z.string().optional(), deployed_commit_date: z.string().optional(), deployed_commit_contributor: z.string().optional(), deployed_commit_tag: z.string().optional(), git_token_id: z.string().nullable().optional(), git_token_name: z.string().nullable().optional()}); export const helmSourceGitResponse = z.object({git_repository: applicationGitRepository}); export const helmSourceRepositoryResponse = z.object({chart_name: z.string(), chart_version: z.string(), repository: z.object({id: z.string(), name: z.string(), url: z.string()})}); export const helmKeyValues = z.array(z.array(z.string())); export const serviceTypeEnum = z.enum(["APPLICATION", "DATABASE", "CONTAINER", "JOB", "HELM", "TERRAFORM"]); export const helmResponse = z.object({id: z.string(), created_at: z.string(), updated_at: z.string().optional(), environment: referenceObject, name: z.string(), description: z.string().optional(), timeout_sec: z.number().int().gte(0).optional(), auto_preview: z.boolean(), auto_deploy: z.boolean(), ports: z.array(z.discriminatedUnion("port_type", [helmPortResponseWithServiceName, helmPortResponseWithServiceSelectors])).optional(), source: z.union([z.object({git: helmSourceGitResponse}), z.object({repository: helmSourceRepositoryResponse})]), arguments: z.array(z.string()), allow_cluster_wide_resources: z.boolean(), values_override: z.object({set: helmKeyValues.optional(), set_string: helmKeyValues.optional(), set_json: helmKeyValues.optional(), file: z.object({raw: z.object({values: z.array(z.object({name: z.string(), content: z.string()}))}).nullable().optional(), git: z.object({git_repository: applicationGitRepository, paths: z.array(z.string())}).nullable().optional()}).nullable().optional()}), icon_uri: z.string(), service_type: serviceTypeEnum}); 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 a helm * * POST /environment/{environmentId}/helm * * Also accepts auth: bearerAuth */ export const createApiEnvironmentEnvironmentIdHelm = async (args: CreateApiEnvironmentEnvironmentIdHelmArgs, options?: CreateApiEnvironmentEnvironmentIdHelmOptions) => { const {baseUrl = "https://api.qovery.com", 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("Authorization", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/environment/${encodeURIComponent(String(args.environmentId))}/helm${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(helmResponse, await res.json()) };