import type { ApiContract, InferSchemaInput, Prettify } from '@lokalise/api-contracts'; import { z } from 'zod/v4'; import type { FallbackRequestParams } from './types.ts'; type RequiredWhenDefined = [T] extends [undefined] ? { [K in TKey]?: undefined; } : { [K in TKey]: T; }; /** * Like {@link RequiredWhenDefined}, but for the one part a subscription may * legitimately supply only in part. * * A request's headers come from two layers: these, captured once, and the * transport's own `headers` option, resolved fresh for every poll and every * reconnect. `requestHeaderSchema` describes the request, not this layer's * contribution to it, so demanding all of it here would force a rotating * credential into the layer that cannot refresh it. What *is* supplied is * still checked against the contract. */ type PartialWhenDefined = [T] extends [undefined] ? { [K in TKey]?: undefined; } : { [K in TKey]?: Partial; }; type ExtractRequestBody = T extends { requestBodySchema: z.ZodType; } ? T['requestBodySchema'] : undefined; /** * Subscription params typed from a contract: the same inference * `sendByApiContract` applies to a one-shot request, applied to the params a * fallback subscription is created with. */ export type FallbackContractParams = Prettify, 'pathParams'> & RequiredWhenDefined>, 'body'> & RequiredWhenDefined, 'queryParams'> & PartialWhenDefined, 'headers'>>; /** * Build the params a fallback subscription is created with, typed and * validated against the contract. * * `createResilientSubscription` takes `params` as an untyped string map, so a * misspelled path param or a query value of the wrong type surfaces as a * 404/400 that the subscription then retries on a backoff — a slow, confusing * failure. This validates against the contract's own schemas up front and * throws immediately instead, and returns the parsed output so Zod defaults * apply. Where a parsed value has no place on the wire — a query schema that * coerces a string into a `Date` — the value you supplied is sent, which is * what `sendByApiContract` would have put on the query string too. * * Header values that change over time (a bearer token) do NOT belong here: * params are captured once when the subscription is created, whereas the * transport's own `headers` option is resolved fresh for every poll and every * reconnect. That is what lets `onAuthChallenge` recover an expired token. * Headers supplied here are checked against `requestHeaderSchema`, but only * the ones supplied — a header the contract requires and the transport layer * provides is not demanded twice. * * @example * ```typescript * const subscription = createResilientSubscription(uploadStatusBinding, { * transport: createFallbackTransport(client, { contract: uploadStatusContract }), * params: buildFallbackParams(uploadStatusContract, { pathParams: { uploadId } }), * }) * ``` */ export declare function buildFallbackParams(contract: TContract, params: FallbackContractParams): FallbackRequestParams; export {};