import {z} from 'zod' export type GetApiApiProjectsProjectIdChangeRequestsArgs = {page?: number | undefined, perPage?: number | undefined, documentId?: (string | null) | undefined, releaseId?: (string | null) | undefined, type?: (Array<'decisions' | 'deployments' | 'publish_document' | 'unpublish_document' | 'deploy_environment' | 'undeploy_environment'> | 'decisions' | 'deployments' | 'publish_document' | 'unpublish_document' | 'deploy_environment' | 'undeploy_environment' | null) | undefined, status?: ('pending' | 'closed' | 'null' | null) | undefined, projectId: string}; export type GetApiApiProjectsProjectIdChangeRequestsOptions = {baseUrl: string, personalAccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiProjectsProjectIdChangeRequestsResponse = z.object({results: z.array(z.object({id: z.string(), type: z.enum(["publish_document", "unpublish_document", "deploy_environment", "undeploy_environment", "merge_branch"]), status: z.enum(["pending", "rejected", "cancelled", "completed"]), description: z.string().nullable().optional(), projectId: z.string(), document: z.object({id: z.string(), name: z.string(), key: z.string().nullable().optional()}).nullable().optional(), documentId: z.string().nullable().optional(), environment: z.object({id: z.string(), name: z.string()}).nullable().optional(), environmentId: z.string().nullable().optional(), release: z.object({id: z.string(), name: z.string(), version: z.string().nullable().optional()}).nullable().optional(), releaseId: z.string().nullable().optional(), branch: z.object({id: z.string(), name: z.string()}).nullable().optional(), branchId: z.string().nullable().optional(), commit: z.object({id: z.string(), message: z.string().nullable().optional()}).nullable().optional(), createdAt: z.string(), createdBy: z.object({id: z.string(), email: z.string(), firstName: z.string().nullable(), lastName: z.string().nullable()}).nullable().optional(), updatedAt: z.string()})), paginate: z.object({current: z.number(), from: z.number(), to: z.number(), total: z.number(), pageSize: z.number()})}); 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 }; /** * List change requests * * GET /api/projects/{projectId}/change-requests * * Also accepts auth: internalAuth */ export const getApiApiProjectsProjectIdChangeRequests = async (args: GetApiApiProjectsProjectIdChangeRequestsArgs, options: GetApiApiProjectsProjectIdChangeRequestsOptions) => { const {baseUrl, fetch: fetchFn = fetch, personalAccessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.perPage != null) query.append("perPage", String(args.perPage)) if (args.documentId != null) query.append("documentId", String(args.documentId)) if (args.releaseId != null) query.append("releaseId", String(args.releaseId)) if (args.type != null) query.append("type", String(args.type)) if (args.status != null) query.append("status", String(args.status)) if (personalAccessToken !== undefined) headers.set('authorization', `Bearer ${personalAccessToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/projects/${encodeURIComponent(String(args.projectId))}/change-requests${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(getApiApiProjectsProjectIdChangeRequestsResponse, await res.json()) };