import {z} from 'zod' export type ModelCodeInfo = {branch?: string | undefined, commit?: string | undefined, user?: string | undefined}; export type ModelImageRepository = {createTime?: string | undefined, fullName: string, name: string, namespace: string, region?: string | undefined, type: string}; export type ModelImageResource = {createTime?: string | undefined, digest: string, tag: string, url: string}; export type ModelImageInfo = {repository?: ModelImageRepository | undefined, resource?: ModelImageResource | undefined, type: string}; export type V1ApplicationDeployRequest = {codeInfo?: ModelCodeInfo | undefined, force: boolean, imageInfo?: ModelImageInfo | undefined, note: string, triggerType: string, workflowName: string}; export type CreateApiApiV1ApplicationsAppNameDeployArgs = {appName: string, body: V1ApplicationDeployRequest}; export type CreateApiApiV1ApplicationsAppNameDeployOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const modelCodeInfo = z.object({branch: z.string().optional(), commit: z.string().optional(), user: z.string().optional()}); export const v1NameAlias = z.object({alias: z.string(), name: z.string()}); export const modelImageRepository = z.object({createTime: z.string().optional(), fullName: z.string(), name: z.string(), namespace: z.string(), region: z.string().optional(), type: z.string()}); export const modelImageResource = z.object({createTime: z.string().optional(), digest: z.string(), tag: z.string(), url: z.string()}); export const modelImageInfo = z.object({repository: modelImageRepository.optional(), resource: modelImageResource.optional(), type: z.string()}); export const v1WorkflowRecordBase = z.object({applicationRevision: z.string(), endTime: z.string().optional(), message: z.string(), mode: z.string(), name: z.string(), namespace: z.string(), startTime: z.string().optional(), status: z.string(), workflowAlias: z.string(), workflowName: z.string()}); export const v1ApplicationDeployResponse = z.object({codeInfo: modelCodeInfo.optional(), createTime: z.string(), deployUser: v1NameAlias.optional(), envName: z.string(), imageInfo: modelImageInfo.optional(), note: z.string(), reason: z.string().optional(), record: v1WorkflowRecordBase, status: z.string(), triggerType: z.string(), version: z.string(), warnings: z.array(z.string()).optional(), workflowName: 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 }; /** * deploy or upgrade the application * * POST /api/v1/applications/{appName}/deploy */ export const createApiApiV1ApplicationsAppNameDeploy = async (args: CreateApiApiV1ApplicationsAppNameDeployArgs, options: CreateApiApiV1ApplicationsAppNameDeployOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/applications/${encodeURIComponent(String(args.appName))}/deploy${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(v1ApplicationDeployResponse, await res.json()) };