From c14e48c53540f3409712c492c0e73c49a486c103 Mon Sep 17 00:00:00 2001 From: Roberto Arce Date: Thu, 7 May 2026 14:44:52 -0400 Subject: [PATCH 1/2] feat(types): expose conversionMode on DocumentType MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The API returns conversionMode on document types and the create/update params already accept it, but the response type omitted it — forcing consumers (e.g. docutray-cli) to cast the result to read the field. Add conversionMode to DocumentType, extract a shared ConversionMode type, and re-export it from the public surface. Closes #21 Co-Authored-By: Claude Opus 4.7 (1M context) --- src/index.ts | 1 + src/types/document-type.ts | 11 +++++++++-- src/types/index.ts | 1 + tests/helpers/fixtures.ts | 2 ++ tests/resources/document-types.test.ts | 17 +++++++++++++++++ 5 files changed, 30 insertions(+), 2 deletions(-) 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..823949e 100644 --- a/tests/resources/document-types.test.ts +++ b/tests/resources/document-types.test.ts @@ -98,6 +98,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: 'json' | 'toon' | 'multi_prompt' | undefined = result.conversionMode; + expect(mode).toBe('toon'); }); }); From d61bba77cec67d7d03b5c965e51190a7fbea1e0a Mon Sep 17 00:00:00 2001 From: Roberto Arce Date: Thu, 7 May 2026 14:51:39 -0400 Subject: [PATCH 2/2] test(types): use ConversionMode type in regression test Co-Authored-By: Claude Opus 4.7 (1M context) --- tests/resources/document-types.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/resources/document-types.test.ts b/tests/resources/document-types.test.ts index 823949e..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, @@ -113,7 +114,7 @@ describe('DocumentTypes', () => { const dt = createDocumentTypes(); const result = await dt.get('dt-789'); - const mode: 'json' | 'toon' | 'multi_prompt' | undefined = result.conversionMode; + const mode: ConversionMode | undefined = result.conversionMode; expect(mode).toBe('toon'); }); });