import {z} from 'zod' export type JumpcloudHttpSaasAppManagementPublicAPIUpdateApplicationRequest = {owner_user_id?: string | undefined, app_name?: string | undefined, app_domains?: Array | undefined, description?: string | undefined, status?: ('NEWLY_DISCOVERED' | 'APPROVED' | 'UNAPPROVED' | 'IGNORED') | undefined, access_restriction?: ('NO_ACTION' | 'WARNING' | 'BLOCK' | 'DISMISSIBLE_WARNING' | 'DEFAULT_ACTION') | undefined, alternative_button?: string | undefined, alternative_button_url?: string | undefined, custom_restriction_message?: string | undefined, restriction_excluded_group_ids?: Array | undefined}; export type UpdateApiApiV2SaasManagementApplicationsApplicationIdArgs = {application_id: string, body: JumpcloudHttpSaasAppManagementPublicAPIUpdateApplicationRequest}; export type UpdateApiApiV2SaasManagementApplicationsApplicationIdOptions = {baseUrl?: string | undefined, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const jumpcloudHttpSaasAppManagementPublicAPISSOApp = z.object({id: z.string().optional(), app_name: z.string().optional(), display_label: z.string().optional(), template_name: z.string().optional(), status: z.enum(["NOT_CONNECTED", "CONNECTED"]).optional()}); export const jumpcloudHttpSaasAppManagementPublicAPIApplication = z.object({id: z.string().optional(), name: z.string().optional(), catalog_app_id: z.string().optional(), owner_user_id: z.string().optional(), status: z.enum(["NEWLY_DISCOVERED", "APPROVED", "UNAPPROVED", "IGNORED"]).optional(), access_restriction: z.enum(["NO_ACTION", "WARNING", "BLOCK", "DISMISSIBLE_WARNING", "DEFAULT_ACTION"]).optional(), alternative_button: z.string().optional(), alternative_button_url: z.string().optional(), custom_restriction_message: z.string().optional(), discovered_at: z.string().optional(), restriction_excluded_group_ids: z.array(z.string()).optional(), sso_apps: z.array(jumpcloudHttpSaasAppManagementPublicAPISSOApp).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 application * * PUT /api/v2/saas-management/applications/{application_id} */ export const updateApiApiV2SaasManagementApplicationsApplicationId = async (args: UpdateApiApiV2SaasManagementApplicationsApplicationIdArgs, options?: UpdateApiApiV2SaasManagementApplicationsApplicationIdOptions) => { 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/saas-management/applications/${encodeURIComponent(String(args.application_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(jumpcloudHttpSaasAppManagementPublicAPIApplication, await res.json()) };