TypeScript Types

Complete type definitions exported by the @mims/sdk-react package.

Importing Types

import type {
  // Field Types
  FieldType,
  FieldDefinition,
  TextFieldDefinition,
  SignatureFieldDefinition,
  CheckboxFieldDefinition,
  DateFieldDefinition,
  InitialsFieldDefinition,
  AnyFieldDefinition,
  
  // Field Values
  TextFieldValue,
  SignatureFieldValue,
  CheckboxFieldValue,
  DateFieldValue,
  InitialsFieldValue,
  AnyFieldValue,
  
  // State
  FieldState,
  RenderContext,
  PageInfo,
  
  // Payloads
  DocumentSubmissionPayload,
  
  // Config
  SDKConfig,
  ApiKeyValidationResponse,
  DocumentMetadata,
} from '@mims/sdk-react';

Field Types

FieldType

type FieldType = 'text' | 'signature' | 'checkbox' | 'date' | 'initials';

FieldDefinition (Base)

interface FieldDefinition {
  /** Unique identifier for the field */
  id: string;
  /** Type of field */
  type: FieldType;
  /** Page number (1-indexed) */
  page: number;
  /** X coordinate relative to page width (0-1) */
  x: number;
  /** Y coordinate relative to page height (0-1) */
  y: number;
  /** Width relative to page width (0-1) */
  width: number;
  /** Height relative to page height (0-1) */
  height: number;
  /** Whether the field is required */
  required: boolean;
  /** Whether the field is editable by the user */
  editable: boolean;
  /** Optional label for the field */
  label?: string;
  /** Optional placeholder text */
  placeholder?: string;
}

TextFieldDefinition

interface TextFieldDefinition extends FieldDefinition {
  type: 'text';
  /** Maximum character length */
  maxLength?: number;
  /** Font size in points */
  fontSize?: number;
  /** Font family */
  fontFamily?: string;
  /** Text alignment */
  textAlign?: 'left' | 'center' | 'right';
  /** Whether the field is multiline */
  multiline?: boolean;
}

SignatureFieldDefinition

interface SignatureFieldDefinition extends FieldDefinition {
  type: 'signature';
  /** Signature mode */
  signatureMode?: 'draw' | 'type' | 'upload';
}

CheckboxFieldDefinition

interface CheckboxFieldDefinition extends FieldDefinition {
  type: 'checkbox';
  /** Checkbox style */
  checkStyle?: 'check' | 'cross' | 'circle';
}

DateFieldDefinition

interface DateFieldDefinition extends FieldDefinition {
  type: 'date';
  /** Date format for display */
  dateFormat?: string;
  /** Minimum date (ISO format) */
  minDate?: string;
  /** Maximum date (ISO format) */
  maxDate?: string;
}

InitialsFieldDefinition

interface InitialsFieldDefinition extends FieldDefinition {
  type: 'initials';
}

AnyFieldDefinition

type AnyFieldDefinition =
  | TextFieldDefinition
  | SignatureFieldDefinition
  | CheckboxFieldDefinition
  | DateFieldDefinition
  | InitialsFieldDefinition;

Field Values

TextFieldValue

interface TextFieldValue {
  type: 'text';
  content: string;
}

SignatureFieldValue

interface SignatureFieldValue {
  type: 'signature';
  /** Base64 encoded PNG image */
  imageData?: string;
  /** SVG path data for vector representation */
  pathData?: string;
  /** Typed signature text */
  typedText?: string;
}

CheckboxFieldValue

interface CheckboxFieldValue {
  type: 'checkbox';
  checked: boolean;
}

DateFieldValue

interface DateFieldValue {
  type: 'date';
  /** ISO 8601 date string */
  value: string;
}

InitialsFieldValue

interface InitialsFieldValue {
  type: 'initials';
  /** Base64 encoded PNG image */
  imageData?: string;
  /** Typed initials text */
  typedText?: string;
}

AnyFieldValue

type AnyFieldValue =
  | TextFieldValue
  | SignatureFieldValue
  | CheckboxFieldValue
  | DateFieldValue
  | InitialsFieldValue;

State Types

FieldState

interface FieldState {
  /** Field definition with type and position */
  definition: AnyFieldDefinition;
  /** Current value, null if not filled */
  value: AnyFieldValue | null;
  /** Whether the field has been touched by the user */
  touched: boolean;
  /** Validation errors */
  errors: string[];
}

RenderContext

interface RenderContext {
  /** Current zoom level (1 = 100%) */
  scale: number;
  /** Viewport width in pixels */
  viewportWidth: number;
  /** Viewport height in pixels */
  viewportHeight: number;
  /** Device pixel ratio for HiDPI displays */
  devicePixelRatio: number;
}

PageInfo

interface PageInfo {
  /** Page number (1-indexed) */
  pageNumber: number;
  /** Original PDF page width in points */
  width: number;
  /** Original PDF page height in points */
  height: number;
  /** Page rotation in degrees */
  rotation: number;
}

Payload Types

DocumentSubmissionPayload

interface DocumentSubmissionPayload {
  /** Unique document identifier from the backend */
  documentId: string;
  /** Timestamp of submission */
  submittedAt: string;
  /** Rendering context at time of submission */
  renderContext: RenderContext;
  /** Array of pages with their info */
  pages: PageInfo[];
  /** All fields with their final values */
  fields: Array<{
    /** Field unique identifier */
    id: string;
    /** Field type */
    type: FieldType;
    /** Page number */
    page: number;
    /** Normalized position (0-1 relative to page) */
    position: {
      x: number;
      y: number;
      width: number;
      height: number;
    };
    /** Field value */
    value: AnyFieldValue;
    /** Style properties for text fields */
    style?: {
      fontSize?: number;
      fontFamily?: string;
      textAlign?: 'left' | 'center' | 'right';
    };
  }>;
  /** Client-generated hash for integrity verification */
  checksum: string;
}

Configuration Types

SDKConfig

interface SDKConfig {
  /** API base URL */
  apiBaseUrl: string;
  /** API Key for authentication */
  apiKey: string;
  /** Enable debug mode */
  debug?: boolean;
  /** Custom headers to include in requests */
  customHeaders?: Record<string, string>;
  /** Request timeout in milliseconds */
  timeout?: number;
}

ApiKeyValidationResponse

interface ApiKeyValidationResponse {
  valid: boolean;
  organizationId?: string;
  organizationName?: string;
  scopes?: string[];
  expiresAt?: string;
  error?: string;
}

DocumentMetadata

interface DocumentMetadata {
  id: string;
  filename: string;
  mimeType: string;
  pageCount: number;
  fileSize: number;
  createdAt: string;
  updatedAt: string;
  version: number;
}

Component Props

MIMSProviderProps

interface MIMSProviderProps {
  /** API Key for authentication (required) */
  apiKey: string;
  /** API base URL (defaults to production) */
  apiBaseUrl?: string;
  /** Enable debug mode */
  debug?: boolean;
  /** Custom headers */
  customHeaders?: Record<string, string>;
  /** Request timeout in ms */
  timeout?: number;
  /** Children components */
  children: ReactNode;
  /** Callback when SDK is ready */
  onReady?: () => void;
  /** Callback on validation error */
  onError?: (error: string) => void;
}

Type Guards

Use TypeScript's type guards to narrow field types:
function isTextField(field: AnyFieldDefinition): field is TextFieldDefinition {
  return field.type === 'text';
}

function isSignatureField(field: AnyFieldDefinition): field is SignatureFieldDefinition {
  return field.type === 'signature';
}

// Usage
if (isTextField(field.definition)) {
  // TypeScript knows field.definition is TextFieldDefinition
  console.log(field.definition.maxLength);
}

Related