import {z} from 'zod' export type CreateReleaseCommandV1 = {ChannelName?: string | undefined, CustomFields?: {[key: string]: string} | undefined, GitCommit?: string | undefined, GitRef?: string | undefined, GitResources?: Array | undefined, IgnoreChannelRules?: boolean | undefined, IgnoreIfAlreadyExists?: boolean | undefined, PackagePrerelease?: string | undefined, Packages?: Array | undefined, PackageVersion?: string | undefined, ProjectName: string, ReleaseNotes?: string | undefined, ReleaseVersion?: string | undefined, SpaceId: string, SpaceIdOrName: string}; export type CreateApiSpacesSpaceIdentifierReleasesCreateV1Args = {spaceIdentifier: string, body: CreateReleaseCommandV1}; export type CreateApiSpacesSpaceIdentifierReleasesCreateV1Options = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const createReleaseResponseV1 = z.object({ReleaseId: z.string(), ReleaseVersion: z.string().min(1)}); 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 Release * * POST /spaces/{spaceIdentifier}/releases/create/v1 * * Also accepts auth: APIKeyQuery, NugetApiKeyHeader */ export const createApiSpacesSpaceIdentifierReleasesCreateV1 = async (args: CreateApiSpacesSpaceIdentifierReleasesCreateV1Args, options?: CreateApiSpacesSpaceIdentifierReleasesCreateV1Options) => { const {baseUrl = "https://demo.octopus.app/api", fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (APIKeyHeader !== undefined) headers.set("X-Octopus-ApiKey", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/spaces/${encodeURIComponent(String(args.spaceIdentifier))}/releases/create/v1${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(createReleaseResponseV1, await res.json()) };