/** * API Client Type Definitions * * This module contains all type definitions related to the Zapier API client, * including configuration options, client interfaces, request/response types, * and API response models. * * API response model types are inferred from Zod schemas defined in api/schemas.ts * to ensure a single source of truth and eliminate duplication. */ import type { ConnectionSchema, ConnectionsResponseSchema } from "@zapier/zapier-sdk-core/v0/schemas/connections"; import type { ImplementationMetaSchema, ImplementationsMetaResponseSchema } from "@zapier/zapier-sdk-core/v0/schemas/implementations"; import type { SdkEvent } from "../types/events"; import type { Credentials } from "../types/credentials"; import type { RequestContext } from "@zapier/policy-context"; import type { ZapierCache } from "../cache"; import type { z } from "zod"; import type { NeedChoicesSchema, NeedSchema, ActionLinksSchema, ActionPermissionsSchema, ActionSchema, ChoiceSchema, FieldSchema, ActionExecutionResultSchema, ActionFieldChoiceSchema, ActionFieldSchema, UserProfileSchema, AppSchema, NeedsRequestSchema, NeedsResponseSchema, ImplementationSchema, ImplementationsResponseSchema, ServiceSchema, ServicesResponseSchema, NeedChoicesRequestSchema, NeedChoicesResponseSchema, NeedChoicesResponseMetaSchema, NeedChoicesResponseLinksSchema } from "./schemas"; export interface ApiClientOptions { baseUrl: string; /** * Authentication credentials. */ credentials?: Credentials; /** * @deprecated Use `credentials` instead. */ token?: string; debug?: boolean; fetch?: typeof globalThis.fetch; onEvent?: (event: SdkEvent) => void; /** * Maximum number of retries for rate-limited requests (429 responses). * Set to 0 to disable retries. Default is 3. */ maxNetworkRetries?: number; /** * Maximum delay in milliseconds to wait for a rate limit retry. * If the server requests a longer delay, the request fails immediately. * Default is 60000 (60 seconds). */ maxNetworkRetryDelayMs?: number; /** * Maximum number of concurrent in-flight HTTP requests per client. * Requests beyond this limit queue in FIFO order until a slot frees. * Pass `Infinity` to disable. Default: 200. */ maxConcurrentRequests?: number; /** * Controls how the approval flow is handled. * - "poll": Create the approval, open the URL in a browser, poll until * resolved, and retry the original request on success. * - "throw": Create the approval and throw a ZapierApprovalError immediately * with the approval URL so the caller can surface it. * - "disabled": Throw a ZapierApprovalError on approval-required responses * without creating an approval. * Resolution order is: explicit option, then ZAPIER_APPROVAL_MODE, then a * TTY-based default ("poll" if interactive, "throw" otherwise). */ approvalMode?: "disabled" | "poll" | "throw"; /** * Timeout in ms for approval polling. Default: 600000 (10 minutes). */ approvalTimeoutMs?: number; /** * Maximum number of sequential approval rounds for a single request before * giving up. A single request can legitimately require multiple approvals * (one per gating policy); this cap prevents a runaway loop if the server * keeps returning approval_required. Default: 2. */ maxApprovalRetries?: number; /** * Identifies the wrapping package that built this client (e.g., the CLI or * MCP server). When set, emitted as `x-zapier-sdk-package` / * `x-zapier-sdk-package-version` telemetry headers. Omitted by direct * `createZapierSdk` callers — their identity is captured by * `x-zapier-sdk-version` alone. */ callerPackage?: { name: string; version: string; }; /** * Pluggable key-value cache used to cache access tokens across * invocations. See ZapierCache in ../cache.ts. */ cache?: ZapierCache; } export interface ApiClient { get: (path: string, options?: RequestOptions) => Promise; post: (path: string, data?: unknown, options?: RequestOptions) => Promise; put: (path: string, data?: unknown, options?: RequestOptions) => Promise; patch: (path: string, data?: unknown, options?: RequestOptions) => Promise; delete: (path: string, data?: unknown, options?: RequestOptions) => Promise; poll: (path: string, options?: PollOptions) => Promise; fetch: (path: string, init?: RequestInit & { searchParams?: Record; authRequired?: boolean; approvalContext?: () => RequestContext; }) => Promise; } export interface RequestOptions { headers?: Record; searchParams?: Record; authRequired?: boolean; /** * OAuth scopes required for this request. When using client credentials, * these scopes will be requested during token exchange (merged with any * scopes specified in the credentials object). */ requiredScopes?: string[]; customErrorHandler?: (errorInfo: { status: number; statusText: string; data: unknown; }) => Error | undefined; /** * Optional metadata about what this request is fetching/affecting. When * set, 404 responses throw `ZapierResourceNotFoundError` with * `resourceType` / `resourceId` populated. The `type` is free-form; * conventionally it matches how the resource appears in API URL segments * (`"table"`, `"record"`, `"connection"`, etc.). */ resource?: { type: string; id?: string | number; }; /** * Builds the policy context for this request if it triggers the approval * flow. Callers that may receive a 403 `approval_required` response MUST * provide this so the SDK can create an approval with the correct context. */ approvalContext?: () => RequestContext; /** * Abort signal forwarded to the underlying `fetch`. Aborting cancels * the in-flight request and any rate-limit retry sleep before the * next attempt; the resulting `AbortError` is the caller's * responsibility to handle. */ signal?: AbortSignal; } export interface PollOptions extends RequestOptions { initialDelay?: number; timeoutMs?: number; successStatus?: number; pendingStatus?: number; /** Function to check if the response body indicates pending state (return true to continue polling) */ isPending?: (response: unknown) => boolean; resultExtractor?: (response: unknown) => unknown; } export interface DebugLogger { (message: string, data?: unknown): void; } export type NeedChoices = z.infer; export type Need = z.infer; export type ActionLinks = z.infer; export type ActionPermissions = z.infer; export type Action = z.infer; export type Choice = z.infer; export type Field = z.infer; export type ActionExecutionResult = z.infer; export type ActionFieldChoice = z.infer; export type ActionField = z.infer; export type Connection = z.infer; export type ConnectionsResponse = z.infer; export type UserProfile = z.infer; export type App = z.infer; export type Service = z.infer; export type ServicesResponse = z.infer; export type NeedsRequest = z.infer; export type NeedsResponse = z.infer; export type Implementation = z.infer; export type ImplementationsResponse = z.infer; export type ImplementationMeta = z.infer; export type ImplementationsMetaResponse = z.infer; export type NeedChoicesRequest = z.infer; export type NeedChoicesResponse = z.infer; export type NeedChoicesResponseMeta = z.infer; export type NeedChoicesResponseLinks = z.infer; //# sourceMappingURL=types.d.ts.map