/** * Narrow transport contract for the direct Google Sheets API provider. * * All Google SDK types stay behind this module: the rest of the provider * works with a small discriminated union of write requests and treats every * response as an untrusted `unknown` value that the preflight/reply modules * validate with runtime guards. Tests implement the same interface with an * in-memory spreadsheet model, so the planner and batch builder are exercised * without credentials or network access. */ import { sheets, type sheets_v4 } from "@googleapis/sheets"; import { GoogleSheetsApiTransportError } from "../errors.js"; import type { GoogleSheetsApiBatchUpdateRequest, GoogleSheetsApiGetSpreadsheetRequest, GoogleSheetsApiTransport, GoogleSheetsApiValuesGetRequest, GoogleSheetsApiValuesGetResponse, GoogleSheetsApiWriteRequest } from "../../../../contracts/sheets/googleSheetsApi.js"; export type { GoogleSheetsApiBatchUpdateRequest, GoogleSheetsApiCell, GoogleSheetsApiCellRow, GoogleSheetsApiGetSpreadsheetRequest, GoogleSheetsApiNumberFormat, GoogleSheetsApiTransport, GoogleSheetsApiValuesGetRequest, GoogleSheetsApiValuesGetResponse, GoogleSheetsApiWriteRequest, } from "../../../../contracts/sheets/googleSheetsApi.js"; /** Auth type accepted by the sheets factory (may resolve to a nested version). */ export type SheetsAuth = NonNullable[0]["auth"]>; /** Options for the real HTTP transport backed by @googleapis/sheets. */ export interface GoogleSheetsApiHttpTransportOptions { /** * Injected auth for tests/alternate credentials. Defaults to Application * Default Credentials (`GOOGLE_APPLICATION_CREDENTIALS` service account). * Ignored when `authPool`/`serviceAccountKeyFiles` build a pool. */ readonly auth?: SheetsAuth; /** * Injected credential pool (one auth per Google quota principal). When * non-empty it replaces the single `auth`/ADC client; each pool entry gets * its own `sheets()` client. Provided for credential-free tests and for * callers that own auth construction; production wiring uses * `serviceAccountKeyFiles` instead. */ readonly authPool?: readonly SheetsAuth[]; /** * Service-account key-file pool: each entry is read and turned into its * own `GoogleAuth` client at construction (fail fast on unreadable or * malformed files). Error messages carry the PATH only — never the file * contents, client email, or any key material. */ readonly serviceAccountKeyFiles?: readonly string[]; readonly requestTimeoutMs: number; } /** * Real transport over the Google Sheets REST API. * * gaxios auto-retry is disabled for every call: retries are the durable * worker/recovery path's job, and a retried mutating request could replay an * already committed batch. All errors are mapped to * `GoogleSheetsApiTransportError` before leaving this module. */ export declare class GoogleSheetsApiHttpTransport implements GoogleSheetsApiTransport { private readonly clients; /** * Credential-pool selection: every pooled auth (injected, file-backed, * or the ADC default) owns one client at the same index. Rotation and * per-identity index binding live in the shared `@hikoutei/google-auth` * pool; this transport only maps the selected index to its client. */ private readonly credentialPool; private readonly requestTimeoutMs; constructor(options: GoogleSheetsApiHttpTransportOptions); /** * Picks the client for one request: the admitted pool identity when the * request carries a `credentialIndex` (provider-bound admission and * signing), otherwise the next round-robin entry (or the single default * client, byte-identical to the pre-pool transport). Selection (including * the fail-closed out-of-range guard) is owned by the shared pool. */ private clientFor; getSpreadsheet(request: GoogleSheetsApiGetSpreadsheetRequest): Promise; getValues(request: GoogleSheetsApiValuesGetRequest): Promise; batchUpdate(request: GoogleSheetsApiBatchUpdateRequest): Promise; } /** * Maps a thrown SDK/gaxios/network error to the provider transport error. * * Exported separately so tests can exercise the mapping with shaped fixtures * instead of real network failures. Any error without a proven HTTP status is * classified conservatively as delivery-uncertain material (network/timeout), * never as a proven pre-mutation rejection. */ export declare function classifyGoogleSheetsApiError(error: unknown): GoogleSheetsApiTransportError; /** * True when the status kind marks a transient remote condition. * * Mirrors the shared `isDeliveryUncertainTransport` boundary: an * absent status (timeout/network), HTTP 408 (request timeout — the proxy or * API may still have committed the write), HTTP 429, and every 5xx are * retryable/uncertain; the proven pre-mutation 4xx rejections (400, 401, * 403, 404) are not. This only buckets telemetry — gaxios auto-retry stays * disabled (`retry: false`), so a mutating call is never blindly retried * here; the durable worker owns retries through the shared outcome * classifier. */ export declare function isRetryableTransportStatus(status: number | undefined): boolean; /** * Builds the SDK batchUpdate body from provider write requests. The SDK * request union is wider than the provider's narrow shapes; this boundary * cast is the only place both types meet. */ export declare function toSdkBatchUpdateBody(requests: readonly GoogleSheetsApiWriteRequest[]): { readonly requests: sheets_v4.Schema$Request[]; }; /** * Serializes the batchUpdate body exactly as the transport sends it, so the * batch builder's byte budget measures the real wire bytes (SDK-wrapped * request shapes, not the internal request union). */ export declare function serializeBatchUpdateRequests(requests: readonly GoogleSheetsApiWriteRequest[]): string; //# sourceMappingURL=googleSheetsApiTransport.d.ts.map