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 */
  baseURL?: string;
  
}

Example Usage

typescript
import GetProntoClient from "@getpronto-io/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;

  /** Secure URL for file access with authentication */
  secureUrl: string;

  /** Secure URL for thumbnail access with authentication */
  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;
}

Example Usage

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

console.log(metadata.secureUrl);  // Authenticated 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 items for the current page */
  items: 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.items;
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 = "jpg" | "png" | "webp" | "avif";

// 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) */
  q?: number;
  
  /** 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;
}

Example Usage

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

APIError

Error structure returned by the API

Definition

typescript
interface APIError extends Error {
  /** HTTP status code */
  status: number;
  
  /** Error message */
  message: string;
  
  /** Error code identifier */
  code: string;
  
  /** Additional error details */
  details?: Record<string, any>;
  
  /** Original response body */
  body?: any;
}

Example Usage

typescript
try {
  await client.files.upload(file);
} catch (error) {
  if (error instanceof APIError) {
    console.error("API Error:", error.message);
    console.error("Status:", error.status);
    console.error("Code:", error.code);
  }
}

Importing Types

All types are available for import from the SDK package:

typescript
import type {
  ClientConfig,
  FileMetadata,
  PaginatedResponse,
  APIResponse,
  ImageFit,
  ImageFormat,
  TransformOptions,
  APIError
} from "@getpronto-io/getpronto-sdk";

Next Steps

Continue exploring our documentation with these related topics: