TypeScript SDK
TypeScript types and API client for INHERIT estate documents. Full type coverage for 100+ entity types with auto-generated API client stubs.
Installation#
npm install @openinherit/sdkThe SDK requires a peer dependency for HTTP client support:
npm install @hey-api/client-fetchRequires Node.js 18 or later.
Quick start#
import { validateDocument, type Estate, type Person } from '@openinherit/sdk';
// Validate a document via the INHERIT API
const result = await validateDocument({
body: estateDocument
});
if (result.data?.valid) {
console.log('Document is valid');
console.log('Conformance level:', result.data.conformanceLevel);
} else {
console.error('Validation errors:', result.data?.errors);
}How it works#
This SDK is auto-generated from the INHERIT OpenAPI specification using @hey-api/openapi-ts ↗ . It provides:
- TypeScript types for every INHERIT entity (Estate, Person, Asset, Trust, Bequest, Guardian, Executor, and 100+ more)
- API client stubs for the INHERIT validation API
- Multiple schema versions via separate entry points
Entry points#
| Import path | Contents |
|---|---|
@openinherit/sdk |
Estate v3 types and validation client |
@openinherit/sdk/v2 |
Estate v2 types (legacy) |
@openinherit/sdk/reference |
Reference data API client |
API reference#
validateDocument(options)#
Validates an INHERIT document against the v3 JSON Schema via the INHERIT API.
Parameters:
options.body— the INHERIT document (estate or catalogue) as a JavaScript object
Returns: Promise<ValidateDocumentResponse> containing:
valid—boolean— whether the document passed validationschemaMode—"estate"or"catalogue"conformanceLevel—0(failed),1(schema valid), or2(schema + referential integrity valid)errors— array of{ path, message }objectsdisclaimer— legal disclaimer string
Type exports#
All INHERIT entity types are exported for use in your application code:
import type {
Estate,
Person,
Asset,
Property,
Trust,
Bequest,
Executor,
Guardian,
Wish,
Document,
Relationship,
NonprobateTransfer,
ValidationResult
} from '@openinherit/sdk';Examples#
Build a typed estate document#
import type { Estate, Person, Asset } from '@openinherit/sdk';
const testator: Person = {
id: '550e8400-e29b-41d4-a716-446655440000',
name: { full: 'Margaret Chen' },
dateOfBirth: '1952-03-14',
role: ['testator']
};
const estate: Estate = {
testatorPersonId: testator.id,
status: 'draft',
jurisdictions: ['england-wales']
};Validate and handle errors#
import { validateDocument } from '@openinherit/sdk';
async function checkDocument(doc: unknown) {
const { data, error } = await validateDocument({ body: doc });
if (error) {
console.error('API error:', error);
return;
}
if (data.valid) {
console.log(`Valid (Level ${data.conformanceLevel})`);
} else {
for (const err of data.errors) {
console.log(` ${err.path}: ${err.message}`);
}
}
}Local validation#
For local validation without an API call, use the @openinherit/schema
package with a JSON Schema library like Ajv ↗
:
import Ajv from 'ajv/dist/2020';
import estateSchema from '@openinherit/schema/v3/schema.json';
const ajv = new Ajv();
const validate = ajv.compile(estateSchema);
const valid = validate(document);