import {z} from 'zod' export type SvflowPubapimodelsBuiltinWorkflowProvisioning = Record; export type SvflowPubapimodelsCustomWorkflowProvisioning = {provisionWorkflowId?: string | undefined, deprovisionWorkflowId?: string | undefined}; export type SvflowPubapimodelsLinkedRolesProvisioning = {linkedRoleIds?: Array | undefined}; export type SvflowPubapimodelsManualProvisioningAssigneeType = 'MANUAL_PROVISIONING_ASSIGNEE_TYPE_UNSPECIFIED' | 'MANUAL_PROVISIONING_ASSIGNEE_TYPE_USER' | 'MANUAL_PROVISIONING_ASSIGNEE_TYPE_GROUP'; export type SvflowPubapimodelsManualProvisioningAssignee = {assigneeId?: string | undefined, assigneeType?: SvflowPubapimodelsManualProvisioningAssigneeType | undefined}; export type SvflowPubapimodelsManualProvisioning = {assignees?: Array | undefined}; export type SvflowPubapimodelsRoleProvisioningMethod = {builtinWorkflow: SvflowPubapimodelsBuiltinWorkflowProvisioning} | {customWorkflow: SvflowPubapimodelsCustomWorkflowProvisioning} | {linkedRoles: SvflowPubapimodelsLinkedRolesProvisioning} | {manual: SvflowPubapimodelsManualProvisioning}; export type SvflowPublicapiUpdateAppResourceRoleInput = {id?: string | undefined, name?: string | undefined, description?: string | undefined, requestsEnabled?: boolean | undefined, accessPolicyId?: (string | null) | undefined, provisioningMethod?: SvflowPubapimodelsRoleProvisioningMethod | undefined, externalId?: (string | null) | undefined, externalData?: (string | null) | undefined, requireFormConfirmation?: (boolean | null) | undefined}; export type SvflowPublicapiBatchUpdateAppResourceRolesRequest = {roles?: Array | undefined}; export type UpdateApiV2AppResourceRolesBatchArgs = {body: SvflowPublicapiBatchUpdateAppResourceRolesRequest}; export type UpdateApiV2AppResourceRolesBatchOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const svflowPubapimodelsBuiltinWorkflowProvisioning = z.object({}); export const svflowPubapimodelsCustomWorkflowProvisioning = z.object({provisionWorkflowId: z.string().optional(), deprovisionWorkflowId: z.string().optional()}); export const svflowPubapimodelsLinkedRolesProvisioning = z.object({linkedRoleIds: z.array(z.string()).optional()}); export const svflowPubapimodelsManualProvisioningAssigneeType = z.enum(["MANUAL_PROVISIONING_ASSIGNEE_TYPE_UNSPECIFIED", "MANUAL_PROVISIONING_ASSIGNEE_TYPE_USER", "MANUAL_PROVISIONING_ASSIGNEE_TYPE_GROUP"]); export const svflowPubapimodelsManualProvisioningAssignee = z.object({assigneeId: z.string().optional(), assigneeType: svflowPubapimodelsManualProvisioningAssigneeType.optional()}); export const svflowPubapimodelsManualProvisioning = z.object({assignees: z.array(svflowPubapimodelsManualProvisioningAssignee).optional()}); export const svflowPubapimodelsRoleProvisioningMethod = z.union([z.object({builtinWorkflow: svflowPubapimodelsBuiltinWorkflowProvisioning}), z.object({customWorkflow: svflowPubapimodelsCustomWorkflowProvisioning}), z.object({linkedRoles: svflowPubapimodelsLinkedRolesProvisioning}), z.object({manual: svflowPubapimodelsManualProvisioning})]); export const svflowPubapimodelsRole = z.object({id: z.string().optional(), resourceId: z.string().optional(), name: z.string().optional(), description: z.string().optional(), requestsEnabled: z.boolean().optional(), accessPolicyId: z.string().nullable().optional(), provisioningMethod: svflowPubapimodelsRoleProvisioningMethod.optional(), externalId: z.string().nullable().optional(), externalData: z.string().nullable().optional(), requireFormConfirmation: z.boolean().optional(), tagIds: z.array(z.string()).optional()}); export const svflowPublicapiBatchUpdateAppResourceRolesResponse = z.object({data: z.array(svflowPubapimodelsRole).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 }; /** * Batch Update App Resource Roles * * PUT /v2/app-resource-roles/batch */ export const updateApiV2AppResourceRolesBatch = async (args: UpdateApiV2AppResourceRolesBatchArgs, options?: UpdateApiV2AppResourceRolesBatchOptions) => { 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/app-resource-roles/batch${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(svflowPublicapiBatchUpdateAppResourceRolesResponse, await res.json()) };