import {z} from 'zod' export type GetApiV2WorkflowsWorkflowIdApprovalProceduresArgs = {workflow_id: string}; export type GetApiV2WorkflowsWorkflowIdApprovalProceduresOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const svflowPubapimodelsAppOwnerApprover = z.object({}); export const svflowPubapimodelsGroupApprover = z.object({groupId: z.string().optional()}); export const svflowPubapimodelsManagerApprover = z.object({}); export const svflowPubapimodelsResourceOwnerApprover = z.object({}); export const svflowPubapimodelsRoleOwnerApprover = z.object({}); export const svflowPubapimodelsTeamOwnerApprover = z.object({}); export const svflowPubapimodelsUserApprover = z.object({userId: z.string().optional()}); export const svflowPubapimodelsApprover = z.union([z.object({appOwner: svflowPubapimodelsAppOwnerApprover, notify: z.boolean().optional()}), z.object({group: svflowPubapimodelsGroupApprover, notify: z.boolean().optional()}), z.object({manager: svflowPubapimodelsManagerApprover, notify: z.boolean().optional()}), z.object({resourceOwner: svflowPubapimodelsResourceOwnerApprover, notify: z.boolean().optional()}), z.object({roleOwner: svflowPubapimodelsRoleOwnerApprover, notify: z.boolean().optional()}), z.object({teamOwner: svflowPubapimodelsTeamOwnerApprover, notify: z.boolean().optional()}), z.object({user: svflowPubapimodelsUserApprover, notify: z.boolean().optional()})]); export const svflowPubapimodelsCustomWorkflowConfig = z.object({workflowId: z.string().optional()}); export const svflowPubapimodelsApprovalStep = z.object({id: z.string().optional(), allowSelfApproval: z.boolean().nullable().optional(), approvers: z.array(svflowPubapimodelsApprover).optional(), customWorkflow: svflowPubapimodelsCustomWorkflowConfig.optional(), approverJustificationMode: z.string().optional()}); export const svflowPubapimodelsWorkflowApprovalProcedure = z.object({id: z.string().optional(), workflowId: z.string().optional(), steps: z.array(svflowPubapimodelsApprovalStep).optional()}); export const svflowPublicapiListWorkflowApprovalProceduresResponse = z.object({data: z.array(svflowPubapimodelsWorkflowApprovalProcedure).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 }; /** * List Workflow Approval Procedures * * GET /v2/workflows/{workflow_id}/approval-procedures */ export const getApiV2WorkflowsWorkflowIdApprovalProcedures = async (args: GetApiV2WorkflowsWorkflowIdApprovalProceduresArgs, options?: GetApiV2WorkflowsWorkflowIdApprovalProceduresOptions) => { const {baseUrl = "https://public.api.serval.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/workflows/${encodeURIComponent(String(args.workflow_id))}/approval-procedures${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(svflowPublicapiListWorkflowApprovalProceduresResponse, await res.json()) };