import {z} from 'zod' export type GetApiPublicV1EnterpriseExportScoresArgs = {page?: number | undefined, size?: number | undefined, sort?: Array | undefined}; export type GetApiPublicV1EnterpriseExportScoresOptions = {baseUrl?: string | undefined, TokenAuthentication?: string | undefined, fetch?: typeof fetch | undefined}; export const edgeNumber = z.object({number: z.string(), source: z.string().nullable().optional(), existingEdgeId: z.number().int().nullable().optional()}); export const publicActionPriorityData = z.object({value: z.number().int(), riskLevel: z.string()}); export const publicScoreGroup: z.ZodType = z.object({groupId: z.number().int(), name: z.string(), score: z.number().int().nullable().optional(), riskLevel: z.string().nullable().optional(), groups: z.array(z.lazy(() => publicScoreGroup)).nullable().optional()}); export const publicScoreComponentData = z.object({riskLevel: z.string().nullable().optional(), name: z.string(), score: z.number().int().nullable().optional()}); export const publicScoreDataEntry = z.object({targetId: z.number().int(), targetName: z.string(), edgeNumbers: z.array(edgeNumber).nullable().optional(), perspectiveId: z.number().int(), perspectiveName: z.string(), calculatedAt: z.string(), calculatedAtIso: z.string(), score: z.number().int(), riskLevel: z.string().nullable().optional(), actionPriority: publicActionPriorityData.nullable().optional(), groups: z.array(publicScoreGroup).nullable().optional(), components: z.array(publicScoreComponentData).nullable().optional(), subComponents: z.array(publicScoreComponentData).nullable().optional()}); export const getApiPublicV1EnterpriseExportScoresResponse = z.object({content: z.array(publicScoreDataEntry).optional(), size: z.number().int().optional(), number: z.number().int().optional(), totalElements: z.number().int().optional(), totalPages: z.number().int().optional(), numberOfElements: z.number().int().optional(), first: z.boolean().optional(), last: z.boolean().optional(), empty: z.boolean().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 }; /** * Retrieve Latest Score Results * * GET /public/v1/enterprise-export/scores */ export const getApiPublicV1EnterpriseExportScores = async (args: GetApiPublicV1EnterpriseExportScoresArgs, options?: GetApiPublicV1EnterpriseExportScoresOptions) => { const {baseUrl = "https://api.prewave.com", fetch: fetchFn = fetch, TokenAuthentication} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.size != null) query.append("size", String(args.size)) for (const item of args.sort ?? []) query.append("sort", String(item)) if (TokenAuthentication !== undefined) headers.set("X-Auth-Token", TokenAuthentication) const url = `${baseUrl.replace(/\/+$/, '')}/public/v1/enterprise-export/scores${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(getApiPublicV1EnterpriseExportScoresResponse, await res.json()) };