diff --git a/src/index.ts b/src/index.ts index bb316e1..8c8add3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -112,6 +112,7 @@ export type { IdentificationStatus, IdentifyParams, DocumentType, + ConversionMode, ValidationErrorInfo, ValidationWarningInfo, ValidationResult, diff --git a/src/types/document-type.ts b/src/types/document-type.ts index ade7a63..b8e59dc 100644 --- a/src/types/document-type.ts +++ b/src/types/document-type.ts @@ -1,3 +1,8 @@ +/** + * Conversion mode used when extracting from a document type. + */ +export type ConversionMode = 'json' | 'toon' | 'multi_prompt'; + /** * A document type definition from the API. */ @@ -22,6 +27,8 @@ export interface DocumentType { updatedAt: string | null; /** The JSON Schema defining the extraction structure. */ jsonSchema: Record | null; + /** Conversion mode used when extracting from this document type. */ + conversionMode?: ConversionMode; } /** @@ -73,7 +80,7 @@ export interface DocumentTypeCreateParams { /** Hints to guide the identification prompt. */ identifyPromptHints?: string; /** The conversion mode to use. */ - conversionMode?: 'json' | 'toon' | 'multi_prompt'; + conversionMode?: ConversionMode; /** Whether to preserve property ordering in extraction output. */ keepPropertyOrdering?: boolean; /** Whether the document type is publicly available. */ @@ -97,7 +104,7 @@ export interface DocumentTypeUpdateParams { /** Updated identification prompt hints. */ identifyPromptHints?: string; /** Updated conversion mode. */ - conversionMode?: 'json' | 'toon' | 'multi_prompt'; + conversionMode?: ConversionMode; /** Whether to preserve property ordering. */ keepPropertyOrdering?: boolean; /** Whether the document type is publicly available. */ diff --git a/src/types/index.ts b/src/types/index.ts index cc9f8db..2ba9edf 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -37,6 +37,7 @@ export { // Document type types export type { + ConversionMode, DocumentType, DocumentTypeCreateParams, DocumentTypeUpdateParams, diff --git a/tests/helpers/fixtures.ts b/tests/helpers/fixtures.ts index ba12fc8..e9dae00 100644 --- a/tests/helpers/fixtures.ts +++ b/tests/helpers/fixtures.ts @@ -72,6 +72,7 @@ export const mockDocumentType: DocumentType = { createdAt: '2025-01-01T00:00:00Z', updatedAt: '2025-01-01T00:00:00Z', jsonSchema: { fields: ['total', 'date'] }, + conversionMode: 'json', }; export const mockDocumentTypeCreated: DocumentType = { @@ -85,6 +86,7 @@ export const mockDocumentTypeCreated: DocumentType = { createdAt: '2025-06-01T00:00:00Z', updatedAt: '2025-06-01T00:00:00Z', jsonSchema: { fields: ['total', 'merchant'] }, + conversionMode: 'multi_prompt', }; export const mockValidationResult: ValidationResult = { diff --git a/tests/resources/document-types.test.ts b/tests/resources/document-types.test.ts index 4198201..d641393 100644 --- a/tests/resources/document-types.test.ts +++ b/tests/resources/document-types.test.ts @@ -3,6 +3,7 @@ import { server, http, HttpResponse } from '../helpers/mock-server.js'; import { DocumentTypes } from '../../src/resources/document-types.js'; import { APIClient } from '../../src/core/api-client.js'; import { RawResponse } from '../../src/core/raw-response.js'; +import type { ConversionMode } from '../../src/types/document-type.js'; import { TEST_BASE_URL, mockDocumentType, @@ -98,6 +99,23 @@ describe('DocumentTypes', () => { expect(result.name).toBe('Invoice'); expect(result.codeType).toBe('invoice'); expect(result.jsonSchema).toEqual({ fields: ['total', 'date'] }); + expect(result.conversionMode).toBe('json'); + }); + + it('exposes conversionMode without requiring a cast', async () => { + server.use( + http.get(`${TEST_BASE_URL}/api/document-types/dt-789`, () => { + return HttpResponse.json({ + data: { ...mockDocumentType, conversionMode: 'toon' }, + }); + }), + ); + + const dt = createDocumentTypes(); + const result = await dt.get('dt-789'); + + const mode: ConversionMode | undefined = result.conversionMode; + expect(mode).toBe('toon'); }); });