import {z} from 'zod' export type GetApiApiV2ApprovalflowsApprovalFlowIdArgs = {approvalFlowId: string, organizationObjectId?: string | undefined}; export type GetApiApiV2ApprovalflowsApprovalFlowIdOptions = {baseUrl?: string | undefined, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const jumpcloudIngressoApproverResource = z.object({requireAll: z.boolean().optional(), resourceId: z.string().optional(), resourceName: z.string().optional(), resourceOrder: z.number().int().optional(), resourceType: z.string().optional()}); export const jumpcloudIngressoAccessWorkflowResources = z.object({resourceId: z.string().optional(), resourceName: z.string().optional(), resourceType: z.string().optional()}); export const jumpcloudIngressoSlackConfig = z.object({slackResourceId: z.string().optional()}); export const jumpcloudIngressoTtlConfig = z.enum(["TTL_CONFIG_UNSPECIFIED", "TTL_CONFIG_MULTI_SELECT_DURATIONS", "TTL_CONFIG_FIXED_DURATION"]); export const jumpcloudIngressoVisibleTo = z.object({id: z.string().optional(), name: z.string().optional()}); export const jumpcloudIngressoAccessWorkflow = z.object({approvalType: z.string().optional(), approverRequirement: z.string().optional(), approverResources: z.array(jumpcloudIngressoApproverResource).optional(), category: z.string().optional(), createdBy: z.string().optional(), description: z.string().optional(), deviceLevelPermission: z.array(z.string()).optional(), fixedDuration: z.string().optional(), iconColor: z.string().optional(), iconUrl: z.string().optional(), id: z.string().optional(), multiSelectDuration: z.array(z.string()).optional(), name: z.string().optional(), nonAdminApproval: z.boolean().optional(), organizationId: z.string().optional(), resources: z.array(jumpcloudIngressoAccessWorkflowResources).optional(), slackConfig: z.array(jumpcloudIngressoSlackConfig).optional(), slackDmEnabled: z.boolean().optional(), slackEnabled: z.boolean().optional(), status: z.string().optional(), timeBasedAccess: z.boolean().optional(), ttlConfig: jumpcloudIngressoTtlConfig.optional(), updatedBy: z.string().optional(), visibleTo: z.array(jumpcloudIngressoVisibleTo).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 }; /** * Get AccessWorkflow by id * * GET /api/v2/approvalflows/{approvalFlowId} */ export const getApiApiV2ApprovalflowsApprovalFlowId = async (args: GetApiApiV2ApprovalflowsApprovalFlowIdArgs, options?: GetApiApiV2ApprovalflowsApprovalFlowIdOptions) => { const {baseUrl = "https://console.jumpcloud.com", fetch: fetchFn = fetch, xApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.organizationObjectId != null) query.append("organizationObjectId", String(args.organizationObjectId)) if (xApiKey !== undefined) headers.set("x-api-key", xApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/approvalflows/${encodeURIComponent(String(args.approvalFlowId))}${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(jumpcloudIngressoAccessWorkflow, await res.json()) };