import {z} from 'zod' export type GetApiConstraintsBindingHeatMapArgs = {api_key?: (string | null) | undefined, dataset_id: string, start_time: string, end_time: string, timezone?: (string | null) | undefined, bucket_mode?: ('auto' | 'raw' | 'hourly' | 'daily') | undefined, group_by?: ('constraint' | 'constraint_contingency') | undefined, days_of_week?: (string | null) | undefined, hours?: (string | null) | undefined, 'x-api-key'?: (string | null) | undefined}; export type GetApiConstraintsBindingHeatMapOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const constraintBindingHeatMapCellResponse = z.object({absolute_cost: z.number().nullable(), peak_shadow_price: z.number(), mean_shadow_price: z.number(), binding_interval_count: z.number().int(), bucket_start_utc: z.string(), interval_start_utc: z.string(), constraint_gs_entity_id: z.string(), contingency_gs_entity_id: z.string().nullable().optional()}); export const constraintBindingHeatMapMetrics = z.object({absolute_cost: z.number().nullable(), peak_shadow_price: z.number(), mean_shadow_price: z.number(), binding_interval_count: z.number().int()}); export const constraintBindingHeatMapRowSummaryResponse = z.object({constraint_gs_entity_id: z.string(), contingency_gs_entity_id: z.string().nullable().optional(), metrics: constraintBindingHeatMapMetrics}); export const constraintBindingHeatMapSupportedResponse = z.object({timezone: z.string(), group_by: z.enum(["constraint", "constraint_contingency"]), supports_contingency_grouping: z.boolean(), constraint_names: z.record(z.string(), z.string()).optional(), contingency_names: z.record(z.string(), z.string()).optional(), native_interval_minutes: z.number().int(), interval_minutes: z.number().int(), bucket_mode: z.enum(["raw", "hourly", "daily"]), available_bucket_modes: z.array(z.enum(["raw", "hourly", "daily"])), cells: z.array(constraintBindingHeatMapCellResponse).optional(), row_summaries: z.array(constraintBindingHeatMapRowSummaryResponse).optional(), unsupported_reason: z.unknown()}); export const constraintBindingHeatMapUnsupportedResponse = z.object({timezone: z.string(), group_by: z.enum(["constraint", "constraint_contingency"]), supports_contingency_grouping: z.boolean(), constraint_names: z.record(z.string(), z.string()).optional(), contingency_names: z.record(z.string(), z.string()).optional(), native_interval_minutes: z.unknown(), interval_minutes: z.unknown(), bucket_mode: z.unknown(), available_bucket_modes: z.array(z.enum(["raw", "hourly", "daily"])).optional(), cells: z.array(constraintBindingHeatMapCellResponse).optional(), row_summaries: z.array(constraintBindingHeatMapRowSummaryResponse).optional(), unsupported_reason: z.string()}); export const getApiConstraintsBindingHeatMapResponse = z.union([constraintBindingHeatMapSupportedResponse, constraintBindingHeatMapUnsupportedResponse]); 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 Constraint Binding Heat Map * * GET /constraints/binding/heat_map */ export const getApiConstraintsBindingHeatMap = async (args: GetApiConstraintsBindingHeatMapArgs, options?: GetApiConstraintsBindingHeatMapOptions) => { const {baseUrl = "https://api.gridstatus.io/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.api_key != null) query.append("api_key", String(args.api_key)) if (args.dataset_id != null) query.append("dataset_id", String(args.dataset_id)) if (args.start_time != null) query.append("start_time", String(args.start_time)) if (args.end_time != null) query.append("end_time", String(args.end_time)) if (args.timezone != null) query.append("timezone", String(args.timezone)) if (args.bucket_mode != null) query.append("bucket_mode", String(args.bucket_mode)) if (args.group_by != null) query.append("group_by", String(args.group_by)) if (args.days_of_week != null) query.append("days_of_week", String(args.days_of_week)) if (args.hours != null) query.append("hours", String(args.hours)) if (args['x-api-key'] != null) headers.set("x-api-key", String(args['x-api-key'])) const url = `${baseUrl.replace(/\/+$/, '')}/constraints/binding/heat_map${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(getApiConstraintsBindingHeatMapResponse, await res.json()) };