/** * Normalize request bodies for Harness NG APIs. * - Strip null/undefined to avoid "Unable to process JSON" from invalid values. * - Unwrap common wrapper keys (environment, service, connector) when APIs expect the entity at top level. * - Optionally synthesize ``body.yaml`` for APIs that require it (see ``ensureYamlWrapper``). * * Service/environment create do NOT need yaml synthesis — NG fills ``yaml`` server-side when * omitted. Infrastructure create/update DOES: NG returns ``yaml: must not be empty`` if the * client sends only flat JSON fields. Wire ``ensureYamlWrapper: "infrastructureDefinition"`` * for those operations only. */ /** Recursively remove null and undefined so they are omitted from JSON. */ export declare function stripNulls(obj: unknown): unknown; /** Return body[wrapperKey] if present, else body. Use when API expects the entity at top level. */ export declare function unwrapBody(body: unknown, wrapperKey: string): unknown; /** * Ensure ``body.yaml`` is a non-empty string for NG APIs that reject missing yaml * even when the same entity fields are present as JSON (infra create/update). * * Unlike service/environment, NG does not synthesize infra yaml server-side. * Agents often send flat ``{ identifier, name, type, environmentRef, spec }`` * (or a raw ``infrastructureDefinition:`` YAML string body). This helper: * - keeps an existing non-empty ``yaml`` string * - stringifies an object-shaped ``yaml`` under ``wrapperKey`` if needed * - otherwise builds ``yaml: ":\\n ..."`` from the remaining fields */ export declare function ensureYamlField(body: unknown, wrapperKey: string): unknown; /** * Options for the standardized body builder factory. */ export interface BodyBuilderOptions { /** Unwrap a wrapper key (e.g., "service", "connector", "environment") */ unwrapKey?: string; /** Wrap the body under a key (e.g., "service" → {"service": {...}}). Use when API expects wrapped bodies. */ wrapKey?: string; /** Auto-inject identifier from input field if missing from body */ injectIdentifier?: { inputField: string; bodyField: string; }; /** Auto-inject additional fields if missing */ injectFields?: Array<{ from: string; to: string; onlyIfMissing?: boolean; }>; /** * Root key for synthesized ``body.yaml`` (e.g. ``infrastructureDefinition``). * When set, after unwrap/strip, ensure a non-empty ``yaml`` string exists — * NG ``POST/PUT /ng/api/infrastructures`` requires it; service/env must not * set this (NG fills yaml for those). See ``ensureYamlField``. */ ensureYamlWrapper?: string; } /** * Factory: returns a bodyBuilder function that handles unwrap, stripNulls, and field injection. * Replaces repetitive inline bodyBuilder patterns across toolsets. */ export declare function buildBodyNormalized(opts?: BodyBuilderOptions): (input: Record) => unknown; //# sourceMappingURL=body-normalizer.d.ts.map