import {z} from 'zod' export type GetApiApiV2SaasManagementApplicationsArgs = {limit?: number | undefined, offset?: number | undefined, expand?: Array<'discovery_source_types'> | undefined}; export type GetApiApiV2SaasManagementApplicationsOptions = {baseUrl?: string | undefined, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const jumpcloudHttpSaasAppManagementPublicAPIApplicationListEntity = z.object({id: 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(), custom_restriction_message: z.string().optional(), discovered_at: z.string().optional(), restriction_excluded_group_ids: z.array(z.string()).optional(), discovery_source_types: z.array(z.string()).optional()}); export const jumpcloudHttpSaasAppManagementPublicAPIListApplicationsResponse = z.object({results: z.array(jumpcloudHttpSaasAppManagementPublicAPIApplicationListEntity).optional(), totalCount: z.number().int().gte(0).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 }; /** * List applications * * GET /api/v2/saas-management/applications */ export const getApiApiV2SaasManagementApplications = async (args: GetApiApiV2SaasManagementApplicationsArgs, options?: GetApiApiV2SaasManagementApplicationsOptions) => { 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.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.expand != null) query.append("expand", args.expand.join(',')) if (xApiKey !== undefined) headers.set("x-api-key", xApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/saas-management/applications${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(jumpcloudHttpSaasAppManagementPublicAPIListApplicationsResponse, await res.json()) };