import type { ReclaimProvider } from '../provider/schema.ts'; import type { AllowedJsRequest } from '../provider/to-version.ts'; import type { RegisterProviderBody, UpdateProviderConfigBody } from './client.ts'; /** * Translate a drafted `ReclaimProvider` (from `propose_provider`) into the * devtools backend shapes. Deliberately a SEPARATE module from * `provider/to-version.ts` (the builder translator) — the two backends have * structurally different bodies: * * - builder NESTS each redaction into its match's `extract`; * - devtools keeps `responseMatches` and `responseRedactions` as * PARALLEL arrays on each `requestData` entry. * * Devtools limit we enforce here (a clear error beats a confusing * server-side 400): only `GET` / `POST` methods. OPRF redactions are passed * through unchanged — the backend's `hash` field accepts them. */ export interface OldProviderOpts { initialUrl: string; description?: string; /** Defaults to `{{DYNAMIC_GEO}}` when omitted. */ geoLocation?: string; /** Defaults to `true` when omitted. Register only (Provider-level flag). */ useProxy?: boolean; providerType?: 'PRIVATE' | 'PUBLIC'; /** Page-injection script — the devtools name for the builder's * `webSettings.jsUserScripts`. Top-level on register, nested under * `providerConfig` on config (add-version). The backend rejects a few * deprecated injection APIs (for example, `window.payloadData`) with a * 400. */ customInjection?: string; /** Accepted at register too (unlike the four fields below, which the * backend only accepts on config/add-version). */ userAgent?: { ios?: string; android?: string; }; /** Accepted at register too. */ pageTitle?: string; /** Config (add-version) ONLY — the register endpoint hardcodes this to * `[]` and ignores whatever is sent. Already old-backend-shaped: build * fresh entries with {@link injectedRequestDataFrom}; a carried-forward * value (read back from an existing version) passes through unchanged. */ allowedInjectedRequestData?: OldInjectedRequestData[]; /** Accepted at register too (verified from the register controller's * destructure + providerConfig write — same as `userAgent`/`pageTitle`). */ stepsToFollow?: string; /** Config (add-version) ONLY — the register endpoint never reads this * field from the request body. */ useIncognitoWebview?: boolean; /** Config (add-version) ONLY — the register endpoint never reads this * field from the request body. Free-form JSON. */ extensionConfig?: unknown; /** Provider-level `disableRequestReplay` (HAWKEYE document replay skip). * The publish tool always forces this `true` — there is no author-facing * way to enable document replay. Config (add-version) ONLY: the register * endpoint hardcodes it to false regardless of what's sent, so the * publish tool always follows a register up with an add-version call to * actually apply it (see `old/tools/publish.ts`). The builder backend's * inverse-named equivalent, `webSettings.clientOptions.inapp * .interceptorOptions.isDocumentRequestReplayEnabled`, is likewise always * force-disabled by `providerToCreateVersionRequest`. */ disableRequestReplay?: boolean; /** Interception mechanism — `NONE` (the publish tool's default) for the * standard capture→replay flow; `HAWKEYE`/`MSWJS`/`XHOOK`/`CDP` for a * genuine live-interception provider. Old-devtools calls this * `injectionType`; builder's equivalent is `webSettings.clientOptions * .inapp.interceptorOptions.interceptorType` (no `NONE` value there — * omitting the whole object is builder's no-interception signal * instead). See `old/client.ts`'s `RegisterProviderBody.injectionType` * doc for the register-persistence caveat. */ injectionType?: 'NONE' | 'MSWJS' | 'XHOOK' | 'CDP' | 'HAWKEYE'; } interface OldResponseMatch { value: string; type: string; isOptional: boolean; order: number; } interface OldResponseRedaction { xPath?: string; jsonPath?: string; regex?: string; /** OPRF mode (`oprf` / `oprf-raw` / `oprf-mpc`) — the backend stores it as * a free-form string and the attestor interprets it at verification. */ hash?: string; order: number; } interface OldRequestData { url: string; urlType: 'REGEX' | 'CONSTANT' | 'TEMPLATE'; method: 'GET' | 'POST'; responseMatches: OldResponseMatch[]; responseRedactions: OldResponseRedaction[]; credentials: 'omit' | 'same-origin' | 'include'; bodySniff?: { enabled: boolean; template: string; }; } /** One `allowedInjectedRequestData` entry — an `OldRequestData` plus the * pagination/optionality flags the old backend stores alongside it. */ export interface OldInjectedRequestData extends OldRequestData { required?: boolean; multiple?: boolean; templateParams?: string[]; templateParamsMode?: 'separate' | 'merge'; } /** Translate fresh `allowedInjectedRequestData` drafts (the author's input * shape, `AllowedJsRequest[]` — same shape the builder translator uses for * its own `allowedJsRequests`) into the devtools backend's shape. A * carried-forward value read back from an existing version is ALREADY in * this shape and should be passed straight through instead — don't run it * through this a second time. */ export declare function injectedRequestDataFrom(requests: AllowedJsRequest[]): OldInjectedRequestData[]; /** Body for `POST /api/providers/register` — new provider + v1.0.0. Every * drafted request becomes a `requestData` entry; provider-level fields (name) * come from the first draft. */ export declare function providerToRegisterBody(providers: ReclaimProvider[], opts: OldProviderOpts): RegisterProviderBody; /** Body for `POST /api/providers/:providerId/config` — adds a new version to * an EXISTING provider. `version` must not already exist; `versionInfo` is * required and must be ≥10 chars (enforced by the backend). */ export declare function providerToConfigBody(providers: ReclaimProvider[], opts: OldProviderOpts, version: string, versionInfo: string): UpdateProviderConfigBody; /** Minimal version triplet as the devtools backend stores it. */ export interface SemverTriplet { major: number; minor: number; patch: number; } export type SemverBump = 'major' | 'minor' | 'patch'; /** * Pull `{major,minor,patch}` triplets out of a `/versions` response, tolerant * of the exact envelope (array, `{ providerVersions: [...] }`, `{ items }`, *, and so on). Each entry's `version` is the triplet. */ export declare function extractVersions(resp: unknown): SemverTriplet[]; /** * Next version string for an update: the highest existing triplet with its * patch bumped, as `"major.minor.patch"`. Falls back to `"1.0.1"` when no * versions are found (a provider being updated always has ≥1, but stay safe * rather than collide with the guaranteed 1.0.0). */ export declare function bumpPatchString(versions: SemverTriplet[]): string; /** Resolve a strictly newer immutable version for old-devtools publishing. */ export declare function resolveNewVersionString(versions: SemverTriplet[], input?: { version?: SemverTriplet; bump?: SemverBump; }): string; export {};