import {z} from 'zod' export type GetApiApiV2SoftwareappsSoftwareAppIdSystemgroupsArgs = {limit?: number | undefined, 'x-org-id'?: string | undefined, skip?: number | undefined, filter?: Array | undefined}; export type GetApiApiV2SoftwareappsSoftwareAppIdSystemgroupsOptions = {baseUrl?: string | undefined, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const graphAttributes = z.record(z.string(), z.unknown()).nullable(); export const graphObject = z.object({attributes: graphAttributes.optional(), id: z.string(), type: z.string()}); export const graphConnection = z.object({attributes: graphAttributes.optional(), from: graphObject.optional(), to: graphObject}); export const graphType = z.enum(["active_directory", "agent", "agent_group", "application", "command", "g_suite", "idp_routing_policy", "ldap_server", "office_365", "policy", "policy_group", "radius_server", "password_manager_item", "system", "system_group", "user", "user_group"]); export const syncStatus = z.object({syncedAt: z.string().optional(), code: z.number().int().optional(), message: z.string().optional(), details: z.array(z.object({})).optional()}); export const graphObjectWithPaths = z.object({compiledAttributes: graphAttributes.optional(), id: z.string(), paths: z.array(z.array(graphConnection)), type: graphType, externalId: z.string().optional(), syncStatus: syncStatus.optional()}); export const getApiApiV2SoftwareappsSoftwareAppIdSystemgroupsResponse = z.array(graphObjectWithPaths); 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 the System Groups bound to a Software App. * * GET /api/v2/softwareapps/{software_app_id}/systemgroups */ export const getApiApiV2SoftwareappsSoftwareAppIdSystemgroups = async (args: GetApiApiV2SoftwareappsSoftwareAppIdSystemgroupsArgs, options?: GetApiApiV2SoftwareappsSoftwareAppIdSystemgroupsOptions) => { 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['x-org-id'] != null) headers.set("x-org-id", String(args['x-org-id'])) if (args.skip != null) query.append("skip", String(args.skip)) if (args.filter != null) query.append("filter", args.filter.join(',')) if (xApiKey !== undefined) headers.set("x-api-key", xApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/softwareapps/${encodeURIComponent(String(args.software_app_id))}/systemgroups${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(getApiApiV2SoftwareappsSoftwareAppIdSystemgroupsResponse, await res.json()) };