import {z} from 'zod' export type CreateApiV1ExplorerDashboardsIdCloneArgs = {id: string, 'Idempotency-Key': string, body: {name?: string | undefined, scope?: ('private' | 'shared' | 'global') | undefined, dashboardConfig?: ({showback: number | null, showbackValues: Array | null, filters?: (Array<{dimension: string, mode: 'include' | 'exclude', values: Array, valueModes?: ({[key: string]: 'include' | 'exclude'}) | undefined, texts?: (Array<{mode: 'include' | 'exclude', text: string}>) | undefined, textCombinator?: ('and' | 'or') | undefined, keyCombinator?: ('and' | 'or') | undefined, tagKeyOnly?: boolean | undefined, includePreAttributionHistory?: true | undefined}>) | undefined, dateRange?: {start: string, end: string} | undefined, datePreset?: ('7D' | '14D' | '30D' | '60D' | '90D' | '1M' | '3M' | '6M' | '1Y' | '3Y' | 'MTD' | 'YTD' | '1Y+MTD' | '+0M' | '+1M' | '+3M' | '+6M' | '+1Y' | '+3Y' | '+4Y') | undefined, granularity?: ('hour' | 'day' | 'week' | 'month' | 'quarter') | undefined, costType?: ('line_item_unblended_cost' | 'line_item_amortized_cost' | 'line_item_blended_cost' | 'pricing_public_on_demand_cost' | 'nops_line_item_net_unblended_cost' | 'nops_line_item_net_amortized_cost' | 'nops_pricing_net_public_on_demand_cost') | undefined, layoutMode?: ('grid' | 'sections') | undefined, sections?: (Array<{kind: 'budget', id: string, title?: string | undefined, budgetId: string, position: number} | {kind?: 'report' | undefined, id: string, title?: string | undefined, explorerReportId: string, config?: ({dateRange?: {start: string, end: string} | undefined, dateRangeMode?: ('rolling' | 'fixed') | undefined, datePreset?: ('7D' | '14D' | '30D' | '60D' | '90D' | '1M' | '3M' | '6M' | '1Y' | '3Y' | 'MTD' | 'YTD' | '1Y+MTD' | '+0M' | '+1M' | '+3M' | '+6M' | '+1Y' | '+3Y' | '+4Y') | undefined, groupBy?: string | undefined, costType?: ('line_item_unblended_cost' | 'line_item_amortized_cost' | 'line_item_blended_cost' | 'pricing_public_on_demand_cost' | 'nops_line_item_net_unblended_cost' | 'nops_line_item_net_amortized_cost' | 'nops_pricing_net_public_on_demand_cost') | undefined, granularity?: ('hour' | 'day' | 'week' | 'month' | 'quarter') | undefined, filters?: (Array<{dimension: string, mode: 'include' | 'exclude', values: Array, valueModes?: ({[key: string]: 'include' | 'exclude'}) | undefined, texts?: (Array<{mode: 'include' | 'exclude', text: string}>) | undefined, textCombinator?: ('and' | 'or') | undefined, keyCombinator?: ('and' | 'or') | undefined, tagKeyOnly?: boolean | undefined, includePreAttributionHistory?: true | undefined}>) | undefined, tagKeyCombinators?: ({[key: string]: 'and' | 'or'}) | undefined, topN?: (number | null) | undefined, usageChart?: ('Hide' | 'Usage' | 'Normalized Usage') | undefined, widgetChartView?: ('all' | 'spend' | 'usage') | undefined, widgetTargetChartView?: ('all' | 'spend' | 'target') | undefined, widgetBusinessUnitChartView?: ('all' | 'spend' | 'unit') | undefined, page?: number | undefined, pageSize?: (number | null) | undefined, sortColumn?: ('name' | 'total' | 'lastPeriod' | 'periodChange' | string) | undefined, sortDir?: ('asc' | 'desc') | undefined, nameSearch?: string | undefined, budgetOverlay?: ({budgetId: string, enabled: boolean} | null) | undefined, bueOverlay?: ({economicsId: number, enabled: boolean} | null) | undefined, showbackOverlay?: ({showbackId: number, enabled: boolean, dimension?: (string | null) | undefined, grouping?: ('allocation' | 'dimension') | undefined, valueFilter?: ({mode: 'include' | 'exclude', values: Array, valueModes?: ({[key: string]: 'include' | 'exclude'}) | undefined} | null) | undefined, dataSource?: ('live' | 'processed' | 'force_processed') | undefined, drilldownGroupBy?: (string | null) | undefined} | null) | undefined, heatmap?: ({enabled: boolean, xAxis: string, yAxis: string} | null) | undefined, forecastHorizon?: number | undefined, bypassCache?: boolean | undefined, flexTable?: ({customColumns: Array<{id: string, dimension: string, label: string, tagKey?: string | undefined}>} | null) | undefined}) | undefined, panels: Array<'metricTiles' | 'pie' | 'history' | 'table'>, position: number, suppressUsageBand?: boolean | undefined}>) | undefined, showbackScope?: {showbackId: number, values: Array} | undefined} | null) | undefined}}; export type CreateApiV1ExplorerDashboardsIdCloneOptions = {baseUrl?: string | undefined, bearerApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const publicApiError = z.object({error: z.object({code: z.string(), message: z.string(), request_id: z.string()})}); 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 }; /** * Clone Explorer dashboard * * POST /v1/explorer/dashboards/{id}/clone */ export const createApiV1ExplorerDashboardsIdClone = async (args: CreateApiV1ExplorerDashboardsIdCloneArgs, options?: CreateApiV1ExplorerDashboardsIdCloneOptions) => { const {baseUrl = "https://api.nops.io", fetch: fetchFn = fetch, bearerApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (bearerApiKey !== undefined) headers.set('authorization', `Bearer ${bearerApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/explorer/dashboards/${encodeURIComponent(String(args.id))}/clone${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(publicApiError, await res.json()) };