import {z} from 'zod' export type GetApiApiOrgIdConfigArgs = {org_id: string}; export type GetApiApiOrgIdConfigOptions = {baseUrl: string, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const usageResult = z.object({ts: z.string(), value: z.number()}); export const dataRetentionDefaults = z.object({default: z.number().int().optional(), logs: z.number().int().optional(), metrics: z.number().int().optional(), profiles: z.number().int().optional(), traces: z.number().int().optional()}); export const zoFunction = z.object({name: z.string(), text: z.string()}); export const featureState = z.enum(["enabled", "locked", "hidden"]); export const rumConfig = z.object({api_version: z.string(), application_id: z.string(), client_token: z.string(), enabled: z.boolean(), env: z.string(), insecure_http: z.boolean(), organization_identifier: z.string(), service: z.string(), site: z.string(), version: z.string()}); export const disabledReason = z.enum(["edition", "license", "flag", "master_key", "super_cluster"]); export const configResponse = z.object({ingestion_history: z.array(usageResult), ingestion_quota_used: z.number(), license_expiry: z.number().int(), license_server_url: z.string(), ai_chat_persistence_enabled: z.boolean(), ai_enabled: z.boolean(), alert_calibration_enabled: z.boolean(), alert_preview_timerange_minutes: z.number().int(), all_fields_name: z.string(), anomaly_detection_enabled: z.boolean(), auto_query_enabled: z.boolean(), billing_group_allowed_orgs: z.string(), build_date: z.string(), build_type: z.string(), cluster_name: z.string(), commit_hash: z.string(), composite_alerts_available: z.boolean(), custom_docs_url: z.string(), custom_hide_menus: z.string(), custom_hide_self_logo: z.boolean(), custom_logo_dark_img: z.string().nullable().optional(), custom_logo_img: z.string().nullable().optional(), custom_logo_text: z.string(), custom_slack_url: z.string(), dashboard_placeholder: z.string(), dashboard_show_field_as_json_enabled: z.boolean(), dashboard_show_symbol_enabled: z.boolean(), data_retention_days: z.number().int(), data_retention_defaults: dataRetentionDefaults, database_monitoring_enabled: z.boolean(), default_fts_keys: z.array(z.string()), default_functions: z.array(zoFunction), default_quick_mode_fields: z.array(z.string()), default_secondary_index_fields: z.array(z.string()), downtimes_enabled: z.boolean(), editor_suggest_mode: z.string(), enable_cross_linking: z.boolean(), experimental: z.boolean(), extended_data_retention_days: z.number().int(), feature_names: z.record(z.string(), z.string()), feature_revision: z.number().int().gte(0), features: z.record(z.string(), featureState), fleet_enabled: z.boolean(), histogram_enabled: z.boolean(), incidents_enabled: z.boolean(), incidents_rca_enabled: z.boolean(), ingest_allowed_in_future: z.number().int(), ingest_allowed_upto: z.number().int(), ingest_flatten_level: z.number().int().gte(0), ingestion_url: z.string(), is_org_admin: z.boolean(), last_usage_report_ts: z.number().int(), log_page_default_field_list: z.string(), max_dashboard_hostmap_cells: z.number().int().gte(0), max_dashboard_series: z.number().int().gte(0), max_dashboard_state_timeline_series: z.number().int().gte(0), max_query_range: z.number().int(), meta_org: z.string(), min_auto_refresh_interval: z.number().int().gte(0), model_pricing_enabled: z.boolean(), native_login_enabled: z.boolean(), oncall_enabled: z.boolean(), online_evals_enabled: z.boolean(), org_deletion_grace_period_days: z.number().int(), org_storage_providers: z.string(), org_storage_region: z.string(), profiling_enabled: z.boolean(), public_ai_chat_enabled: z.boolean(), public_ai_chat_max_expiry_days: z.number().int().gte(0), public_dashboard_min_refresh_secs: z.number().int().gte(0), public_dashboards_enabled: z.boolean(), query_default_limit: z.number().int(), query_history_enabled: z.boolean(), query_history_retention_days: z.number().int(), query_on_stream_selection: z.boolean(), query_values_default_num: z.number().int(), quick_mode_enabled: z.boolean(), rbac_enabled: z.boolean(), resolved_data_retention: dataRetentionDefaults, restricted_routes_on_empty_data: z.boolean(), rum: rumConfig, sample_data_onboarding_enabled: z.boolean(), search_inspector_enabled: z.boolean(), service_account_enabled: z.boolean(), service_streams_enabled: z.boolean(), show_fts_field_values: z.boolean(), show_stream_stats_doc_num: z.boolean(), slack_disabled_reason: disabledReason.nullable().optional(), slack_enabled: z.boolean(), sql_base64_enabled: z.boolean(), sql_reserved_keywords: z.array(z.string()), sso_enabled: z.boolean(), streaming_aggregation_enabled: z.boolean(), streaming_enabled: z.boolean(), super_cluster_enabled: z.boolean(), synthetics_browser_max_steps: z.number().int().gte(0), synthetics_enabled: z.boolean(), synthetics_private_locations_enabled: z.boolean(), synthetics_recorder_extension_url: z.string(), telemetry_enabled: z.boolean(), timechart_enabled: z.boolean(), timestamp_column: z.string(), usage_enabled: z.boolean(), usage_publish_interval: z.number().int(), user_defined_schema_max_fields: z.number().int().gte(0), user_defined_schemas_enabled: z.boolean(), version: z.string(), web_url: z.string(), workflow_hooks_enabled: z.boolean(), workflows_enabled: z.boolean()}); 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 the configuration for an organization * * GET /api/{org_id}/config */ export const getApiApiOrgIdConfig = async (args: GetApiApiOrgIdConfigArgs, options: GetApiApiOrgIdConfigOptions) => { const {baseUrl, fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/api/${encodeURIComponent(String(args.org_id))}/config${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(configResponse, await res.json()) };