OpenForm

identification

Last updated on

Build and validate identification documents

Build and validate identification document information. The Identification primitive captures ID document details like passports, driver's licenses, and national IDs.

Examples

Creating identifications

// Object pattern
const id = open.identification({
  type: 'passport',
  number: 'AB1234567'
})

// Builder pattern
const id = open.identification()
  .type('passport')
  .number('AB1234567')
  .issuer('US')
  .issueDate('2020-01-15')
  .expiryDate('2030-01-14')
  .build()

// Copy and modify
const renewed = open.identification()
  .from(id)
  .issueDate('2024-01-15')
  .expiryDate('2034-01-14')
  .build()

Parsing external data

// Parse unknown input (throws on error)
const id = open.identification.parse(jsonData)

// Safe parsing (returns result object)
const result = open.identification.safeParse(jsonData)
if (result.success) {
  console.log(`${result.data.type}: ${result.data.number}`)
} else {
  console.error(result.error.message)
}

Using with forms

const form = open.form({
  name: 'kyc',
  fields: {
    primaryId: { type: 'identification', label: 'Primary ID' },
    secondaryId: { type: 'identification', label: 'Secondary ID' }
  }
})

const filled = form.fill({
  fields: {
    primaryId: open.identification()
      .type('drivers_license')
      .number('D1234567')
      .issuer('CA')
      .expiryDate('2028-06-30')
      .build()
  }
})

API

Object Pattern

open.identification(input: Identification): Identification

Pass an Identification object for validation. Returns the validated Identification or throws on error.

const id = open.identification({
  type: 'national_id',
  number: '123-45-6789'
})

Builder Pattern

Chain methods to build an Identification value incrementally:

All methods return IdentificationBuilder and are chainable.

open.identification()
type: (val: string) => IdentificationBuilder
Set document type (passport, drivers_license, etc.)
number: (val: string) => IdentificationBuilder
Set document number
issuer: (val: string | undefined) => IdentificationBuilder
Set issuing authority or country
issueDate: (val: string | undefined) => IdentificationBuilder
Set issue date (YYYY-MM-DD)
expiryDate: (val: string | undefined) => IdentificationBuilder
Set expiry date (YYYY-MM-DD)
from: (value: Identification) => IdentificationBuilder
Initialize from existing Identification
build: () => Identification
Build and validate

Static Methods

parse: (input: unknown) => Identification
Parse unknown input (throws on error)
safeParse: (input: unknown) => Result<Identification>
Parse unknown input (returns result object)

Properties

type: string
Type of identification document.
number: string
Document number or identifier.
issuer: string?
Issuing authority, country, or organization.
issueDate: string?
Date of issue in YYYY-MM-DD format.
expiryDate: string?
Expiration date in YYYY-MM-DD format.

Common ID Types

TypeDescription
passportInternational travel passport
drivers_licenseDriver's license
national_idNational identity card
ssnSocial Security Number (US)
tax_idTax identification number
voter_idVoter registration card
military_idMilitary identification

Validation

The Identification primitive validates:

  • type must be a non-empty string
  • number must be a non-empty string
  • issueDate and expiryDate must be valid dates if provided
// Valid
open.identification({ type: 'passport', number: 'AB123456' })
open.identification({
  type: 'drivers_license',
  number: 'D9876543',
  issuer: 'CA',
  expiryDate: '2028-12-31'
})

// Invalid - throws Error
open.identification({ type: 'passport' })
// Error: Invalid Identification: number is required

open.identification({ type: '', number: 'AB123456' })
// Error: Invalid Identification: type cannot be empty

Related

On this page