import {z} from 'zod' export type SvflowPubapimodelsAppOwnerApprover = Record; export type SvflowPubapimodelsGroupApprover = {groupId?: string | undefined}; export type SvflowPubapimodelsManagerApprover = Record; export type SvflowPubapimodelsResourceOwnerApprover = Record; export type SvflowPubapimodelsRoleOwnerApprover = Record; export type SvflowPubapimodelsTeamOwnerApprover = Record; export type SvflowPubapimodelsUserApprover = {userId?: string | undefined}; export type SvflowPubapimodelsApprover = {appOwner: SvflowPubapimodelsAppOwnerApprover, notify?: boolean | undefined} | {group: SvflowPubapimodelsGroupApprover, notify?: boolean | undefined} | {manager: SvflowPubapimodelsManagerApprover, notify?: boolean | undefined} | {resourceOwner: SvflowPubapimodelsResourceOwnerApprover, notify?: boolean | undefined} | {roleOwner: SvflowPubapimodelsRoleOwnerApprover, notify?: boolean | undefined} | {teamOwner: SvflowPubapimodelsTeamOwnerApprover, notify?: boolean | undefined} | {user: SvflowPubapimodelsUserApprover, notify?: boolean | undefined}; export type SvflowPubapimodelsCustomWorkflowConfig = {workflowId?: string | undefined}; export type SvflowPubapimodelsApprovalStep = {id?: string | undefined, allowSelfApproval?: (boolean | null) | undefined, approvers?: Array | undefined, customWorkflow?: SvflowPubapimodelsCustomWorkflowConfig | undefined, approverJustificationMode?: string | undefined}; export type UpdateApiV2WorkflowsWorkflowIdApprovalProceduresIdArgs = {workflow_id: string, id: string, body: {steps?: Array | undefined}}; export type UpdateApiV2WorkflowsWorkflowIdApprovalProceduresIdOptions = {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 svflowPublicapiUpdateWorkflowApprovalProcedureResponse = z.object({data: 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 }; /** * Update Workflow Approval Procedure * * PUT /v2/workflows/{workflow_id}/approval-procedures/{id} */ export const updateApiV2WorkflowsWorkflowIdApprovalProceduresId = async (args: UpdateApiV2WorkflowsWorkflowIdApprovalProceduresIdArgs, options?: UpdateApiV2WorkflowsWorkflowIdApprovalProceduresIdOptions) => { const {baseUrl = "https://public.api.serval.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") 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/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(svflowPublicapiUpdateWorkflowApprovalProcedureResponse, await res.json()) };