import {z} from 'zod' export type GetApiV7ReportRunnersArgs = {type?: string | undefined, report_type?: string | undefined, display_name?: string | undefined, user_ids?: Array | undefined, having_any_tags?: string | undefined, having_all_tags?: string | undefined, exclude_having_any_tags?: string | undefined, exclude_having_all_tags?: string | undefined, search_query?: string | undefined, pause_status?: string | undefined, aggregation_status?: string | undefined, offset?: string | undefined, limit?: string | undefined, order_by?: string | undefined, order?: string | undefined, report_type_name?: string | undefined}; export type GetApiV7ReportRunnersOptions = {baseUrl?: string | undefined, HEADER?: string | undefined, fetch?: typeof fetch | undefined}; export const componentReferenceResponse = z.object({component_id: z.string().optional(), socket_names: z.array(z.string()).optional()}); export const zonedDateTime = z.string(); export const mergingConfigurationResponse = z.object({deliverable_type: z.enum(["ACCUMULATING", "INDIVIDUAL", "NEW_ENTRIES"]).optional(), formats: z.array(z.enum(["CSV", "HEADLESS_CSV", "HEADLESS_PSV", "JSON", "JSONL", "PSV", "XLSX"])).optional(), sort_by: z.array(z.string()).optional(), unique_by: z.array(z.string()).optional()}); export const reportParameterTypeResponse = z.object({name: z.enum(["AUDIENCE_ID", "AUDIENCE_IDS", "AUDIENCE_MEMBERSHIPS_METRIC_MAPPING", "AUDIENCE_MEMBERSHIPS_ROW_MAPPINGS", "AUDIENCE_MEMBERS_ROW_MAPPINGS", "BOOLEAN", "CAMPAIGN_ID", "CAMPAIGN_IDS", "CHANNEL_MAPPING", "CLIENT_EVENT_METRIC_MAPPINGS", "CLIENT_ID", "CLIENT_IDS", "DATE", "DATE_RANGE", "DECIMAL", "EMAIL_NAMES", "ENUM", "ENUM_LIST", "EQUALITY", "FILTER_MAPPINGS", "FLOWS", "FLOW_FILTER", "GRANULAR_TIME_RANGE", "ID", "IDS", "INPUT_RECORD_METRIC_MAPPING", "INPUT_RECORD_ROW_MAPPINGS", "INTEGER", "LONG", "MESSAGE_SUMMARY_METRIC_MAPPINGS", "METRIC_MAPPINGS", "MODEL_CONFIGURATION_METRIC_MAPPING", "NORMALIZED_EMAIL", "NOT_ARCHIVED_CAMPAIGN_ID", "PERSON_DIMENSION_MAPPINGS", "PERSON_MAPPINGS", "PROGRAM_LABEL", "PROGRAM_LABELS", "REGEX", "REWARD_EVENT_METRIC_MAPPINGS", "REWARD_ROW_MAPPINGS", "REWARD_SUPPLIER_DISPLAY_TYPES", "REWARD_SUPPLIER_IDS", "REWARD_SUPPLIER_TYPES", "ROW_MAPPINGS", "SORT_ORDER_MAPPINGS", "SORT_ORDER_MAPPINGS_ON_STEPS", "STEP", "STEPS", "STEP_COLUMN_LIST", "STRING", "STRING_LIST", "TIERS", "TIME", "TIME_RANGE", "WEBHOOK_DISPATCH_METRIC_MAPPING", "WEBHOOK_DISPATCH_ROW_MAPPINGS", "WEBHOOK_METRIC_MAPPING", "WEBHOOK_ROW_MAPPINGS"]).optional(), value_type: z.enum(["DYNAMIC", "STATIC"]).nullable().optional(), values: z.array(z.string()).nullable().optional()}); export const reportParameterDetailsResponse = z.object({category: z.string().nullable().optional(), display_name: z.string().optional(), is_required: z.boolean().optional(), name: z.string().optional(), order: z.number().int().optional(), type: reportParameterTypeResponse.optional()}); export const reportParameterResponse = z.object({details: reportParameterDetailsResponse.optional(), value: z.string().optional()}); export const instant = z.string(); export const pauseInfoResponse = z.object({description: z.string().optional(), updated_date: instant.optional(), user_id: z.string().optional()}); export const reportNamePatternInReportRunnerResponseBase = z.union([z.string(), z.string()]); export const sftpReportNamePatternInReportRunnerResponseBase = z.union([z.string(), z.string()]); export const reportRunnerResponse = z.discriminatedUnion("type", [z.object({component_ids: z.array(z.string()), component_references: z.array(componentReferenceResponse), created_date: zonedDateTime, deliver_empty_reports_to_sftp: z.boolean(), enabled: z.boolean(), execution_policy: z.enum(["AWAIT_DATA", "IMMEDIATE"]), formats: z.array(z.enum(["CSV", "HEADLESS_CSV", "HEADLESS_PSV", "JSON", "JSONL", "PSV", "XLSX"])), id: z.string(), merging_configuration: mergingConfigurationResponse, name: z.string(), parameters: z.record(z.string(), reportParameterResponse), pause_info: pauseInfoResponse, paused: pauseInfoResponse, report_name_pattern: reportNamePatternInReportRunnerResponseBase, report_type: z.string(), report_type_name: z.string(), scopes: z.array(z.enum(["CLIENT_ADMIN", "CLIENT_SUPERUSER", "CONSUMER_PUBLIC"])), sftp_report_name_pattern: sftpReportNamePatternInReportRunnerResponseBase, sftp_server_id: z.string().nullable(), tags: z.array(z.string()), type: z.literal("REFRESHING"), updated_date: zonedDateTime, user_id: z.string(), expiration_ms: z.number().int()}), z.object({component_ids: z.array(z.string()), component_references: z.array(componentReferenceResponse), created_date: zonedDateTime, deliver_empty_reports_to_sftp: z.boolean(), enabled: z.boolean(), execution_policy: z.enum(["AWAIT_DATA", "IMMEDIATE"]), formats: z.array(z.enum(["CSV", "HEADLESS_CSV", "HEADLESS_PSV", "JSON", "JSONL", "PSV", "XLSX"])), id: z.string(), merging_configuration: mergingConfigurationResponse, name: z.string(), parameters: z.record(z.string(), reportParameterResponse), pause_info: pauseInfoResponse, paused: pauseInfoResponse, report_name_pattern: reportNamePatternInReportRunnerResponseBase, report_type: z.string(), report_type_name: z.string(), scopes: z.array(z.enum(["CLIENT_ADMIN", "CLIENT_SUPERUSER", "CONSUMER_PUBLIC"])), sftp_report_name_pattern: sftpReportNamePatternInReportRunnerResponseBase, sftp_server_id: z.string().nullable(), tags: z.array(z.string()), type: z.literal("SCHEDULED"), updated_date: zonedDateTime, user_id: z.string(), frequency: z.enum(["DAILY", "HOURLY", "LOGIN", "MONTHLY", "QUARTERLY", "WEEKLY"]), legacy_sftp_report_name_format: z.boolean(), schedule_start_date: zonedDateTime})]); export const getApiV7ReportRunnersResponse = z.array(reportRunnerResponse); 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 report runners * * GET /v7/report-runners * * Also accepts auth: QUERY, COOKIE */ export const getApiV7ReportRunners = async (args: GetApiV7ReportRunnersArgs, options?: GetApiV7ReportRunnersOptions) => { const {baseUrl = "https://api.extole.io", fetch: fetchFn = fetch, HEADER} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.type != null) query.append("type", String(args.type)) if (args.report_type != null) query.append("report_type", String(args.report_type)) if (args.display_name != null) query.append("display_name", String(args.display_name)) for (const item of args.user_ids ?? []) query.append("user_ids", String(item)) if (args.having_any_tags != null) query.append("having_any_tags", String(args.having_any_tags)) if (args.having_all_tags != null) query.append("having_all_tags", String(args.having_all_tags)) if (args.exclude_having_any_tags != null) query.append("exclude_having_any_tags", String(args.exclude_having_any_tags)) if (args.exclude_having_all_tags != null) query.append("exclude_having_all_tags", String(args.exclude_having_all_tags)) if (args.search_query != null) query.append("search_query", String(args.search_query)) if (args.pause_status != null) query.append("pause_status", String(args.pause_status)) if (args.aggregation_status != null) query.append("aggregation_status", String(args.aggregation_status)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.order_by != null) query.append("order_by", String(args.order_by)) if (args.order != null) query.append("order", String(args.order)) if (args.report_type_name != null) query.append("report_type_name", String(args.report_type_name)) if (HEADER !== undefined) headers.set("Authorization", HEADER) const url = `${baseUrl.replace(/\/+$/, '')}/v7/report-runners${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(getApiV7ReportRunnersResponse, await res.json()) };