import {z} from 'zod' export type GetApiApiV2ReportingDatasetDatasetIdSchedulesArgs = {dataset_id: string}; export type GetApiApiV2ReportingDatasetDatasetIdSchedulesOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, appKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const datasetReportScheduleResourceType = z.literal("widget_dataset_list"); export const reportScheduleStatus = z.enum(["active", "inactive"]); export const datasetReportScheduleResponseAttributes = z.object({cell_id: z.string().nullable(), dataset_id: z.string().nullable(), description: z.string(), file_row_limit: z.number().int().nullable(), inline_row_limit: z.number().int().nullable(), next_recurrence: z.number().int().nullable(), notebook_id: z.number().int().nullable(), recipients: z.array(z.string()), resource_id: z.string(), resource_type: datasetReportScheduleResourceType, rrule: z.string(), status: reportScheduleStatus, timeframe: z.string(), timezone: z.string(), title: z.string()}); export const reportScheduleAuthorType = z.literal("users"); export const reportScheduleAuthorRelationshipData = z.object({id: z.string(), type: reportScheduleAuthorType}); export const reportScheduleAuthorRelationship = z.object({data: reportScheduleAuthorRelationshipData}); export const reportScheduleResponseRelationships = z.object({author: reportScheduleAuthorRelationship}); export const reportScheduleType = z.literal("schedule"); export const datasetReportScheduleResponseData = z.object({attributes: datasetReportScheduleResponseAttributes, id: z.string(), relationships: reportScheduleResponseRelationships, type: reportScheduleType}); export const reportScheduleAuthorAttributes = z.object({email: z.string().nullable(), name: z.string().nullable()}); export const reportScheduleAuthor = z.object({attributes: reportScheduleAuthorAttributes, id: z.string(), type: reportScheduleAuthorType}); export const reportScheduleResourceType = z.enum(["dashboard", "integration_dashboard"]); export const reportScheduleIndexTemplateVariable = z.object({available_values: z.array(z.string()).nullable().optional(), defaults: z.array(z.string()).nullable().optional(), name: z.string().nullable().optional(), prefix: z.string().nullable().optional()}); export const reportScheduleResourceAttributes = z.object({resource_type: reportScheduleResourceType, template_variables: z.array(reportScheduleIndexTemplateVariable).nullable().optional(), title: z.string().nullable().optional()}); export const reportScheduleIncludedResourceType = z.literal("resource"); export const reportScheduleResource = z.object({attributes: reportScheduleResourceAttributes, id: z.string(), type: reportScheduleIncludedResourceType}); export const reportScheduleIncludedResource = z.union([reportScheduleAuthor, reportScheduleResource]); export const datasetReportScheduleListResponse = z.object({data: z.array(datasetReportScheduleResponseData), included: z.array(reportScheduleIncludedResource).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 }; /** * List dataset report schedules * * GET /api/v2/reporting/dataset/{dataset_id}/schedules * * Also accepts auth: AuthZ */ export const getApiApiV2ReportingDatasetDatasetIdSchedules = async (args: GetApiApiV2ReportingDatasetDatasetIdSchedulesArgs, options?: GetApiApiV2ReportingDatasetDatasetIdSchedulesOptions) => { const {baseUrl = "https://api.datadoghq.com", fetch: fetchFn = fetch, apiKeyAuth, appKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apiKeyAuth !== undefined) headers.set("DD-API-KEY", apiKeyAuth) if (appKeyAuth !== undefined) headers.set("DD-APPLICATION-KEY", appKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/reporting/dataset/${encodeURIComponent(String(args.dataset_id))}/schedules${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(datasetReportScheduleListResponse, await res.json()) };