import {z} from 'zod' export type GetApiApiV2ReportsScheduledObjectIdArgs = {objectId: string}; export type GetApiApiV2ReportsScheduledObjectIdOptions = {baseUrl?: string | undefined, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const jumpcloudInsightsRecipient = z.object({channelType: z.string(), value: z.array(z.string())}); export const jumpcloudInsightsScheduledReport = z.object({createdAt: z.string().optional(), cronExpression: z.string().optional(), days: z.array(z.string()).optional(), description: z.string().optional(), displayName: z.string(), endDate: z.string().nullable().optional(), exportType: z.string(), id: z.string().optional(), isActive: z.boolean(), lastRunAt: z.string().nullable().optional(), lastRunStatus: z.string().optional(), nextRunAt: z.string().optional(), recipients: z.array(jumpcloudInsightsRecipient), reportId: z.string().nullable().optional(), reportType: z.string().nullable().optional(), scheduleFrequency: z.string(), scheduleTime: z.string(), startDate: z.string().nullable().optional(), timeZone: z.string(), updatedAt: z.string().optional()}); export const jumpcloudInsightsScheduledReportResponse = z.object({scheduledReport: jumpcloudInsightsScheduledReport.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 a Scheduled Report * * GET /api/v2/reports/scheduled/{objectId} */ export const getApiApiV2ReportsScheduledObjectId = async (args: GetApiApiV2ReportsScheduledObjectIdArgs, options?: GetApiApiV2ReportsScheduledObjectIdOptions) => { 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 (xApiKey !== undefined) headers.set("x-api-key", xApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/reports/scheduled/${encodeURIComponent(String(args.objectId))}${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(jumpcloudInsightsScheduledReportResponse, await res.json()) };