import {z} from 'zod' export type GetApiApiV1PolicyPacksSummaryArgs = {'X-Org-ID': string}; export type GetApiApiV1PolicyPacksSummaryOptions = {baseUrl?: string | undefined, InternalServiceID?: string | undefined, InternalServiceToken?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1PolicyPacksSummaryResponse = z.object({success: z.boolean(), scope: z.literal("decide"), shipped: z.number().int(), organization: z.number().int(), pack: z.number().int(), packs_counted: z.boolean(), disabled: z.number().int(), total: z.number().int(), not_bound_here: z.array(z.string()).optional(), detector_not_run_here: z.array(z.object({id: z.string().optional(), detector: z.string().optional(), runs_on: z.array(z.string()).optional()})).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 }; /** * What this agent enforces on an organization, installed policy packs counted (internal service) * * GET /api/v1/policy-packs/summary */ export const getApiApiV1PolicyPacksSummary = async (args: GetApiApiV1PolicyPacksSummaryArgs, options?: GetApiApiV1PolicyPacksSummaryOptions) => { const {baseUrl = "https://agent.getaxonflow.com", fetch: fetchFn = fetch, InternalServiceID, InternalServiceToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-Org-ID'] != null) headers.set("X-Org-ID", String(args['X-Org-ID'])) if (InternalServiceID !== undefined) headers.set("X-Internal-Service-ID", InternalServiceID) if (InternalServiceToken !== undefined) headers.set("X-Internal-Service-Token", InternalServiceToken) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/policy-packs/summary${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(getApiApiV1PolicyPacksSummaryResponse, await res.json()) };