Documentation

TypeScript types

The Get Pronto SDK is written in TypeScript and provides comprehensive type definitions for all its features. This page documents the main types and interfaces you'll encounter when using the SDK.

ClientConfig

Configuration options for initializing the Get Pronto client

Definition

typescript
interface ClientConfig {
  /** Your Get Pronto API key */
  apiKey: string;

  /** Base URL for API requests. Defaults to https://api.getpronto.io/v1 */
  baseUrl?: string;

  /** Request timeout in milliseconds */
  timeout?: number;

  /** Number of retries for failed requests */
  retries?: number;

  /** Additional headers to include in all requests */
  headers?: Record<string, string>;
}

Example usage

typescript
import GetProntoClient from "getpronto-sdk";

const client = new GetProntoClient({
  apiKey: "your_api_key",
});

FileMetadata

Metadata for files stored in Get Pronto

Definition

typescript
interface FileMetadata {
  /** Unique identifier for the file */
  id: string;

  /** Name of the file */
  name: string;

  /** Public HTTPS delivery URL; no authentication required */
  secureUrl: string;

  /** Public thumbnail URL; no authentication required */
  secureThumbnailUrl: string;

  /** Raw URL for public file access */
  rawUrl: string;

  /** Formatted file type */
  type: string;

  /** Raw MIME type */
  rawType: string;

  /** Formatted file size (e.g., "1.5 MB") */
  size: string;

  /** File size in bytes */
  rawSize: number;

  /** Formatted update timestamp */
  updated: string;

  /** Raw update timestamp */
  rawUpdated: string;

  /** ID of the folder the file belongs to, or null */
  folderId: string | null;

  /** Image dimensions, when available (absent for non-images and older uploads) */
  width?: number;
  height?: number;
}

Example usage

typescript
// Example response from file upload
const result = await client.files.upload(file);
const metadata: FileMetadata = result.data;

console.log(metadata.secureUrl);  // Public image delivery URL
console.log(metadata.rawSize);    // Size in bytes
console.log(metadata.type);       // Formatted type (e.g., "PDF")

PaginatedResponse

Structure for paginated API responses

Definition

typescript
interface PaginatedResponse<T> {
  /** Array of files for the current page */
  files: T[];

  /** Pagination metadata */
  pagination: {
    /** Current page number */
    page: number;
    
    /** Number of items per page */
    pageSize: number;
    
    /** Total number of items across all pages */
    totalCount: number;
    
    /** Total number of pages */
    totalPages: number;
  };
}

Example usage

typescript
// List files with pagination
const response = await client.files.list({
  page: 2,
  pageSize: 50
});

const files: FileMetadata[] = response.data.files;
const { totalPages } = response.data.pagination;

APIResponse

Standard wrapper for API responses

Definition

typescript
interface APIResponse<T> {
  /** Response data */
  data: T;
  
  /** Response status code */
  status: number;
  
  /** Response headers */
  headers?: Record<string, string>;
}

Example usage

typescript
// Example API response handling
const response = await client.files.get(fileId);
const file: FileMetadata = response.data;
const status: number = response.status;

ImageTransformation types

Types related to image transformation options

Definition

typescript
// Resize fit options
type ImageFit = "cover" | "contain" | "fill" | "inside" | "outside";

// Supported output formats
type ImageFormat = "jpeg" | "png" | "webp" | "avif" | "gif" | "tiff";
type ImageFormatAuto = "auto";
type ImageQualityAuto = "auto";

// Full transformation options
interface TransformOptions {
  /** Target width in pixels (1-5000) */
  w?: number;
  
  /** Target height in pixels (1-5000) */
  h?: number;
  
  /** How the image should fit the target dimensions */
  fit?: ImageFit;
  
  /** Output quality (1-100), or automatic selection */
  q?: number | ImageQualityAuto;
  
  /** Gaussian blur radius (0.3-1000) */
  blur?: number;
  
  /** Apply sharpening */
  sharp?: boolean;
  
  /** Convert to grayscale */
  gray?: boolean;
  
  /** Rotation angle (-360 to 360) */
  rot?: number;
  
  /** Border width and color (e.g., "5_FF0000") */
  border?: string;
  
  /** Crop coordinates (e.g., "100,100,500,500") */
  crop?: string;
  
  /** Output format */
  format?: ImageFormat | ImageFormatAuto;
}

Example usage

typescript
// Example image transformation
const url = await client.images
  .transform(fileId)
  .resize(800, 600, "contain")
  .quality(90)
  .format("webp")
  .toURL();

Responsive image types

Inputs and attributes for imageProps(), available in SDK 1.4.1

Definition

typescript
interface ImagePropsOptions extends Omit<TransformOptions, "w" | "h"> {
  /** Up to six unique candidate widths; defaults to [400, 800, 1200, 1600] */
  widths?: number[];
  /** Display size in your layout; supplied by the application */
  sizes?: string;
}

interface ImageProps {
  src: string;
  srcSet: string;
  sizes?: string;
  /** Included only when both source dimensions are known */
  width?: number;
  height?: number;
}

Example usage

typescript
import { imageProps, type ImagePropsOptions } from "getpronto-sdk";

const options: ImagePropsOptions = {
  widths: [400, 800, 1200],
  sizes: "(max-width: 768px) 100vw, 50vw",
  format: "auto",
  q: "auto",
};

// file is the FileMetadata returned by an upload
const props = imageProps(file, options);

APIError

Error class thrown by the SDK when API requests fail

Definition

typescript
class APIError extends Error {
  /** HTTP status code */
  status: number;

  /** HTTP status text */
  statusText: string;

  /** Response headers */
  headers: Record<string, string>;

  /** Original response body */
  body: any;
}

Example usage

typescript
import { APIError } from "getpronto-sdk/core/http-client";

try {
  await client.files.upload(file);
} catch (error) {
  if (error.name === "APIError") {
    console.error("API Error:", error.message);
    console.error("Status:", error.status);
    console.error("Body:", error.body);
  }
}

Importing types

All types are available for import from the SDK package:

typescript
import type {
  ClientConfig,
  FileMetadata,
  PaginatedResponse,
  APIResponse,
  ImageFit,
  ImageFormat,
  ImageFormatAuto,
  ImageQualityAuto,
  TransformOptions,
  ImagePropsOptions,
  ImageProps,
} from "getpronto-sdk";

Next steps

Continue exploring our documentation with these related topics: