import {z} from 'zod' export type GetApiApiV2CompaniesIdTrendTechnicalArgs = {id: number, timeframe?: ('OneYear' | 'TwoYears') | undefined, resolution?: ('Monthly' | 'Weekly' | 'Daily') | undefined}; export type GetApiApiV2CompaniesIdTrendTechnicalOptions = {baseUrl?: string | undefined, OAuthv2?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV2CompaniesIdTrendTechnicalResponse = z.array(z.object({GradeLetter: z.enum(["A+", "A", "A-", "B+", "B", "B-", "C+", "C", "C-", "D+", "D", "D-", "F", "n/a"]).optional(), CyberRating: z.number().gte(0).lte(100).optional(), IndustryAverageCyberRating: z.number().gte(0).lte(100).nullable().optional(), IndustryAverageGradeLetter: z.enum(["A+", "A", "A-", "B+", "B", "B-", "C+", "C", "C-", "D+", "D", "D-", "F", "n/a"]).optional(), BreachIndex: z.number().gte(0).lte(1).nullable().optional(), RansomwareIndex: z.number().gte(0).lte(1).nullable().optional(), SnapshotDate: z.string().nullable().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 }; /** * Get technical risk trend of a monitored company. * * GET /api/v2/companies/{id}/trend/technical */ export const getApiApiV2CompaniesIdTrendTechnical = async (args: GetApiApiV2CompaniesIdTrendTechnicalArgs, options?: GetApiApiV2CompaniesIdTrendTechnicalOptions) => { const {baseUrl = "https://app.blackkitetech.com", fetch: fetchFn = fetch, OAuthv2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.timeframe != null) query.append("timeframe", String(args.timeframe)) if (args.resolution != null) query.append("resolution", String(args.resolution)) if (OAuthv2 !== undefined) headers.set('authorization', `Bearer ${OAuthv2}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/companies/${encodeURIComponent(String(args.id))}/trend/technical${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(getApiApiV2CompaniesIdTrendTechnicalResponse, await res.json()) };