import {z} from 'zod' export type JumpcloudIngressoApproverResource = {requireAll?: boolean | undefined, resourceId?: string | undefined, resourceName?: string | undefined, resourceOrder?: number | undefined, resourceType?: string | undefined}; export type JumpcloudIngressoSlackConfig = {slackResourceId?: string | undefined}; export type JumpcloudIngressoTtlConfig = 'TTL_CONFIG_UNSPECIFIED' | 'TTL_CONFIG_MULTI_SELECT_DURATIONS' | 'TTL_CONFIG_FIXED_DURATION'; export type JumpcloudIngressoCreateAccessWorkflowRequest = {approvalType?: string | undefined, approverRequirement?: string | undefined, approverResources?: Array | undefined, category?: string | undefined, description?: string | undefined, deviceLevelPermission?: Array | undefined, fixedDuration?: string | undefined, iconColor?: string | undefined, iconUrl?: string | undefined, multiSelectDuration?: Array | undefined, name?: string | undefined, nonAdminApproval?: boolean | undefined, organizationObjectId?: string | undefined, resourceId?: string | undefined, resourceType?: string | undefined, slackConfig?: Array | undefined, slackDmEnabled?: boolean | undefined, slackEnabled?: boolean | undefined, status?: string | undefined, timeBasedAccess?: boolean | undefined, ttlConfig?: JumpcloudIngressoTtlConfig | undefined, visibleTo?: Array | undefined}; export type CreateApiApiV2ApprovalflowsArgs = {body: JumpcloudIngressoCreateAccessWorkflowRequest}; export type CreateApiApiV2ApprovalflowsOptions = {baseUrl?: string | undefined, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const jumpcloudIngressoCreateAccessWorkflowResponse = z.object({id: z.string().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 }; /** * Create Access Workflow * * POST /api/v2/approvalflows */ export const createApiApiV2Approvalflows = async (args: CreateApiApiV2ApprovalflowsArgs, options?: CreateApiApiV2ApprovalflowsOptions) => { const {baseUrl = "https://console.jumpcloud.com", fetch: fetchFn = fetch, xApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (xApiKey !== undefined) headers.set("x-api-key", xApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/approvalflows${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(jumpcloudIngressoCreateAccessWorkflowResponse, await res.json()) };