import {z} from 'zod' export type GetApiApiV30OrgsOrgUuidDependenciesEventsZerodayArgs = {limit?: string | undefined, cursor?: string | undefined, orgUuid: string, fromDate?: string | undefined, toDate?: string | undefined}; export type GetApiApiV30OrgsOrgUuidDependenciesEventsZerodayOptions = {baseUrl?: string | undefined, bearerKey?: string | undefined, fetch?: typeof fetch | undefined}; export const zeroDayEventDTOV3 = z.object({uuid: z.string().optional(), name: z.string().optional(), description: z.string().optional(), publishedAt: z.string().optional(), updatedAt: z.string().optional()}); export const dWRResponsePageableV3ListZeroDayEventDTOV3 = z.object({additionalData: z.object({}).optional(), supportToken: z.string().optional(), response: z.array(zeroDayEventDTOV3).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 all Zero-Day Events * * GET /api/v3.0/orgs/{orgUuid}/dependencies/events/zeroday */ export const getApiApiV30OrgsOrgUuidDependenciesEventsZeroday = async (args: GetApiApiV30OrgsOrgUuidDependenciesEventsZerodayArgs, options?: GetApiApiV30OrgsOrgUuidDependenciesEventsZerodayOptions) => { const {baseUrl = "https://baseUrl", fetch: fetchFn = fetch, bearerKey} = 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.cursor != null) query.append("cursor", String(args.cursor)) if (args.fromDate != null) query.append("fromDate", String(args.fromDate)) if (args.toDate != null) query.append("toDate", String(args.toDate)) if (bearerKey !== undefined) headers.set('authorization', `Bearer ${bearerKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v3.0/orgs/${encodeURIComponent(String(args.orgUuid))}/dependencies/events/zeroday${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(dWRResponsePageableV3ListZeroDayEventDTOV3, await res.json()) };