@docmana/sdk 0.3.5 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CHANGELOG.md +33 -4
  2. package/README.md +175 -232
  3. package/dist/api/execution-result.d.ts +3 -0
  4. package/dist/api/execution-status.d.ts +6 -0
  5. package/dist/api/flow-definition.d.ts +3 -0
  6. package/dist/api/flow-metadata.d.ts +3 -0
  7. package/dist/api/list-flows.d.ts +3 -0
  8. package/dist/api/list-organizations.d.ts +3 -0
  9. package/dist/api/organization-documents.d.ts +7 -0
  10. package/dist/api/run-flow.d.ts +6 -0
  11. package/dist/cli.mjs +1022 -695
  12. package/dist/cli.mjs.map +1 -1
  13. package/dist/client.d.ts +26 -0
  14. package/dist/config.d.ts +21 -0
  15. package/dist/errors.d.ts +55 -0
  16. package/dist/files/resolve-input.d.ts +9 -0
  17. package/dist/http/http-client.d.ts +31 -0
  18. package/dist/index.d.ts +4 -349
  19. package/dist/index.js +323 -339
  20. package/dist/index.js.map +1 -1
  21. package/dist/index.mjs +319 -335
  22. package/dist/index.mjs.map +1 -1
  23. package/dist/models/docmana-api-document-execution-result.model.d.ts +9 -0
  24. package/dist/models/docmana-api-document-request.model.d.ts +15 -0
  25. package/dist/models/docmana-api-execution-result.model.d.ts +24 -0
  26. package/dist/models/docmana-api-node-result.model.d.ts +28 -0
  27. package/dist/models/docmana-classification-result.model.d.ts +3 -0
  28. package/dist/models/docmana-conclusion-result.model.d.ts +3 -0
  29. package/dist/models/docmana-cross-validation-result.model.d.ts +3 -0
  30. package/dist/models/docmana-document-mapping.model.d.ts +4 -0
  31. package/dist/models/docmana-document-result.model.d.ts +11 -0
  32. package/dist/models/docmana-execution-result.model.d.ts +15 -0
  33. package/dist/models/docmana-extraction-result.model.d.ts +3 -0
  34. package/dist/models/docmana-metadata-extraction-result.model.d.ts +3 -0
  35. package/dist/models/docmana-node-result.model.d.ts +7 -0
  36. package/dist/models/docmana-score-node-result.model.d.ts +5 -0
  37. package/dist/models/docmana-validation-result.model.d.ts +3 -0
  38. package/dist/models/document-content.model.d.ts +4 -0
  39. package/dist/models/execution-progress.model.d.ts +4 -0
  40. package/dist/models/execution-status.enum.d.ts +1 -0
  41. package/dist/models/flow-configs.model.d.ts +16 -0
  42. package/dist/models/flow-edge.model.d.ts +4 -0
  43. package/dist/models/flow-node-type.enum.d.ts +1 -0
  44. package/dist/models/flow-node.model.d.ts +33 -0
  45. package/dist/models/flow.model.d.ts +11 -0
  46. package/dist/models/index.d.ts +26 -0
  47. package/dist/models/node-translation-result.model.d.ts +7 -0
  48. package/dist/models/physical-document.model.d.ts +9 -0
  49. package/dist/models/virtual-document.model.d.ts +10 -0
  50. package/dist/polling/poll.d.ts +15 -0
  51. package/dist/types.d.ts +145 -0
  52. package/package.json +17 -14
  53. package/dist/index.d.cts +0 -349
@@ -0,0 +1,145 @@
1
+ export interface DocmanaConfig {
2
+ apiBaseUrl: string;
3
+ accessToken?: string;
4
+ getAccessToken?: (options?: {
5
+ forceRefresh?: boolean;
6
+ }) => string | Promise<string>;
7
+ timeoutMs?: number;
8
+ pollIntervalMs?: number;
9
+ pollMaxIntervalMs?: number;
10
+ fetch?: typeof fetch;
11
+ headers?: Record<string, string>;
12
+ }
13
+ export interface TokenCacheEntry {
14
+ accessToken: string;
15
+ expiresAt: number;
16
+ clientId: string;
17
+ tokenEndpoint: string;
18
+ scope: string;
19
+ }
20
+ export interface TokenCache {
21
+ read(): Promise<TokenCacheEntry | null>;
22
+ write(entry: TokenCacheEntry): Promise<void>;
23
+ clear(): Promise<void>;
24
+ }
25
+ export interface PathFileInput {
26
+ path: string;
27
+ }
28
+ export interface NamedFileInput {
29
+ data: Uint8Array | NodeJS.ReadableStream;
30
+ filename: string;
31
+ contentType?: string;
32
+ }
33
+ export type FileInput = string | PathFileInput | NamedFileInput;
34
+ export interface RunFlowParams {
35
+ files: FileInput[];
36
+ useDraftVersion?: boolean;
37
+ language?: string;
38
+ context?: Record<string, unknown>;
39
+ }
40
+ export interface RunFlowOptions {
41
+ signal?: AbortSignal;
42
+ timeoutMs?: number;
43
+ pollIntervalMs?: number;
44
+ pollMaxIntervalMs?: number;
45
+ onPoll?: (event: {
46
+ executionResultId: string;
47
+ status: string;
48
+ attempt: number;
49
+ elapsedMs: number;
50
+ nextPollAfterMs?: number;
51
+ }) => void;
52
+ onRateLimit?: (event: {
53
+ executionResultId: string;
54
+ attempt: number;
55
+ elapsedMs: number;
56
+ retryAfterMs: number;
57
+ }) => void;
58
+ }
59
+ export interface RunFlowAsyncOptions {
60
+ signal?: AbortSignal;
61
+ }
62
+ export interface RunFlowAsyncParams extends RunFlowParams {
63
+ /** URL Consumer will POST the completion result to (wire: `callback_url`). */
64
+ callbackUrl?: string;
65
+ }
66
+ export interface FlowListItem {
67
+ id: string;
68
+ name: string;
69
+ state: string;
70
+ }
71
+ export interface AccessibleOrganization {
72
+ id: string;
73
+ name: string;
74
+ }
75
+ export interface OrganizationDocument {
76
+ path: string;
77
+ name: string;
78
+ size: number;
79
+ lastModified: string;
80
+ contentType?: string;
81
+ }
82
+ export interface OrganizationDocumentsPayload {
83
+ configured: boolean;
84
+ documents: OrganizationDocument[];
85
+ }
86
+ export interface DownloadedOrganizationDocument {
87
+ bytes: Uint8Array;
88
+ filename: string;
89
+ contentType?: string;
90
+ }
91
+ export interface FlowDocumentRequirement {
92
+ docId: string;
93
+ label: string;
94
+ required: boolean;
95
+ }
96
+ export interface FlowMetadata {
97
+ flowId: string;
98
+ name?: string;
99
+ contextSchema: Record<string, unknown>;
100
+ languages: string[];
101
+ minScore?: number;
102
+ documents: FlowDocumentRequirement[];
103
+ }
104
+ export interface FlowDefinitionField {
105
+ fieldKey: string;
106
+ path: string;
107
+ type?: string;
108
+ }
109
+ export interface FlowDefinitionNodeMetadata {
110
+ title?: string;
111
+ uniqueName?: string;
112
+ assessmentType?: string;
113
+ scoreAssessment: boolean;
114
+ scoreAcceptanceThreshold?: number;
115
+ description?: string;
116
+ enabled?: boolean;
117
+ }
118
+ export interface FlowDefinitionNode {
119
+ nodeId: string;
120
+ type: string;
121
+ label: string;
122
+ uniqueName?: string;
123
+ parentId?: string;
124
+ fields: FlowDefinitionField[];
125
+ metadata?: FlowDefinitionNodeMetadata;
126
+ }
127
+ export interface FlowDefinition {
128
+ flowId: string;
129
+ name?: string;
130
+ languages: string[];
131
+ minScore?: number;
132
+ nodes: FlowDefinitionNode[];
133
+ }
134
+ export type { DocmanaExecutionResult } from "./models/docmana-execution-result.model.js";
135
+ export type { DocmanaDocumentMapping } from "./models/docmana-document-mapping.model.js";
136
+ export type { DocmanaDocumentResult } from "./models/docmana-document-result.model.js";
137
+ export type { DocmanaNodeResult } from "./models/docmana-node-result.model.js";
138
+ export type { DocmanaScoreNodeResult } from "./models/docmana-score-node-result.model.js";
139
+ export type { DocmanaCrossValidationResult } from "./models/docmana-cross-validation-result.model.js";
140
+ export type { DocmanaConclusionResult } from "./models/docmana-conclusion-result.model.js";
141
+ export type { DocmanaClassificationResult } from "./models/docmana-classification-result.model.js";
142
+ export type { DocmanaMetadataExtractionResult } from "./models/docmana-metadata-extraction-result.model.js";
143
+ export type { DocmanaExtractionResult } from "./models/docmana-extraction-result.model.js";
144
+ export type { DocmanaValidationResult } from "./models/docmana-validation-result.model.js";
145
+ export type { ExecutionStatus } from "./models/execution-status.enum.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docmana/sdk",
3
- "version": "0.3.5",
3
+ "version": "0.8.0",
4
4
  "description": "Official Docmana SDK — run document-analysis flows with a single call.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -18,7 +18,7 @@
18
18
  }
19
19
  },
20
20
  "bin": {
21
- "docmana": "./dist/cli.mjs"
21
+ "docmana": "dist/cli.mjs"
22
22
  },
23
23
  "files": [
24
24
  "dist",
@@ -27,10 +27,11 @@
27
27
  "CHANGELOG.md"
28
28
  ],
29
29
  "publishConfig": {
30
+ "registry": "https://registry.npmjs.org/",
30
31
  "access": "public"
31
32
  },
32
33
  "dependencies": {
33
- "commander": "^14.0.3"
34
+ "commander": "^15.0.0"
34
35
  },
35
36
  "scripts": {
36
37
  "build": "tsup",
@@ -48,17 +49,19 @@
48
49
  "prepublishOnly": "npm run check && npm run build"
49
50
  },
50
51
  "devDependencies": {
51
- "@types/node": "^22.0.0",
52
- "@typescript-eslint/eslint-plugin": "^8.0.0",
53
- "@typescript-eslint/parser": "^8.0.0",
54
- "@vitest/coverage-v8": "^2.0.0",
55
- "eslint": "^9.0.0",
56
- "prettier": "^3.0.0",
57
- "tsup": "^8.0.0",
58
- "typescript": "^5.6.0",
59
- "typescript-eslint": "^8.60.1",
60
- "undici": "^7.24.4",
61
- "vitest": "^2.0.0",
52
+ "@eslint/js": "^10.0.1",
53
+ "@types/node": "^25.9.3",
54
+ "@typescript-eslint/eslint-plugin": "^8.61.0",
55
+ "@typescript-eslint/parser": "^8.61.0",
56
+ "@vitest/coverage-v8": "^4.1.8",
57
+ "eslint": "^10.5.0",
58
+ "prettier": "^3.8.4",
59
+ "tsup": "^8.5.1",
60
+ "tsx": "^4.22.4",
61
+ "typescript": "^6.0.3",
62
+ "typescript-eslint": "^8.61.0",
63
+ "undici": "^8.4.1",
64
+ "vitest": "^4.1.8",
62
65
  "yalc": "^1.0.0-pre.53"
63
66
  }
64
67
  }
package/dist/index.d.cts DELETED
@@ -1,349 +0,0 @@
1
- interface DocmanaDocumentMapping {
2
- name: string;
3
- reference: string;
4
- }
5
-
6
- interface DocmanaNodeResult {
7
- status: string;
8
- errors?: string[];
9
- /** Human-readable rationale (language-specific). Returned for every node. */
10
- feedback?: string;
11
- data?: Record<string, unknown>;
12
- }
13
-
14
- interface DocmanaScoreNodeResult extends DocmanaNodeResult {
15
- /** Numeric confidence (0..100), identical across languages (not translated). */
16
- score?: number;
17
- }
18
-
19
- interface DocmanaClassificationResult extends DocmanaScoreNodeResult {
20
- }
21
-
22
- interface DocmanaMetadataExtractionResult extends DocmanaNodeResult {
23
- }
24
-
25
- interface DocmanaExtractionResult extends DocmanaNodeResult {
26
- }
27
-
28
- interface DocmanaValidationResult extends DocmanaScoreNodeResult {
29
- }
30
-
31
- interface DocmanaDocumentResult {
32
- status: string;
33
- classifications?: Record<string, DocmanaClassificationResult>;
34
- metadataExtraction?: DocmanaMetadataExtractionResult;
35
- extractions?: Record<string, DocmanaExtractionResult>;
36
- validations?: Record<string, DocmanaValidationResult>;
37
- }
38
-
39
- interface DocmanaCrossValidationResult extends DocmanaScoreNodeResult {
40
- }
41
-
42
- interface DocmanaConclusionResult extends DocmanaScoreNodeResult {
43
- }
44
-
45
- interface DocmanaExecutionResult {
46
- status: string;
47
- executionId: string;
48
- errors?: string[];
49
- documents: {
50
- mappings: DocmanaDocumentMapping[];
51
- [docKey: string]: DocmanaDocumentResult | DocmanaDocumentMapping[];
52
- };
53
- crossValidations?: Record<string, DocmanaCrossValidationResult>;
54
- conclusions?: Record<string, DocmanaConclusionResult>;
55
- }
56
-
57
- type ExecutionStatus = "Pending" | "Running" | "Incompleted" | "Completed" | "Failed";
58
-
59
- interface DocmanaConfig {
60
- clientId: string;
61
- clientSecret: string;
62
- apiBaseUrl?: string;
63
- tokenEndpoint?: string;
64
- scope?: string;
65
- timeoutMs?: number;
66
- pollIntervalMs?: number;
67
- fetch?: typeof fetch;
68
- headers?: Record<string, string>;
69
- tokenCache?: TokenCache;
70
- }
71
- interface TokenCacheEntry {
72
- accessToken: string;
73
- expiresAt: number;
74
- clientId: string;
75
- tokenEndpoint: string;
76
- scope: string;
77
- }
78
- interface TokenCache {
79
- read(): Promise<TokenCacheEntry | null>;
80
- write(entry: TokenCacheEntry): Promise<void>;
81
- clear(): Promise<void>;
82
- }
83
- interface PathFileInput {
84
- path: string;
85
- }
86
- type FileInput = string | PathFileInput | Uint8Array | NodeJS.ReadableStream;
87
- interface RunFlowInput {
88
- file?: FileInput;
89
- files?: FileInput[];
90
- fileName?: string;
91
- signal?: AbortSignal;
92
- timeoutMs?: number;
93
- pollIntervalMs?: number;
94
- once?: boolean;
95
- language?: string;
96
- context?: Record<string, unknown>;
97
- }
98
- interface RunFlowWithCallbackInput {
99
- file?: FileInput;
100
- files?: FileInput[];
101
- fileName?: string;
102
- signal?: AbortSignal;
103
- once?: boolean;
104
- context?: Record<string, unknown>;
105
- /** URL docmana-API will POST the completion notification to (wire: `callback_url`). */
106
- callbackUrl: string;
107
- }
108
-
109
- declare class Docmana {
110
- private readonly config;
111
- private readonly http;
112
- constructor(config: DocmanaConfig);
113
- runFlowAsync(flowId: string, input: RunFlowInput): Promise<{
114
- executionResultId: string;
115
- fileIds: string[];
116
- }>;
117
- runFlowWithCallback(flowId: string, input: RunFlowWithCallbackInput): Promise<{
118
- executionResultId: string;
119
- fileIds: string[];
120
- }>;
121
- getStatus(executionResultId: string, signal?: AbortSignal): Promise<{
122
- status: ExecutionStatus | string;
123
- }>;
124
- getResult(executionResultId: string, signal?: AbortSignal, language?: string): Promise<DocmanaExecutionResult>;
125
- runFlow(flowId: string, input: RunFlowInput): Promise<DocmanaExecutionResult>;
126
- }
127
-
128
- declare class DocmanaError extends Error {
129
- readonly status?: number;
130
- readonly requestId?: string;
131
- readonly code: string;
132
- constructor(message: string, opts?: {
133
- status?: number;
134
- requestId?: string;
135
- code?: string;
136
- });
137
- }
138
- declare class DocmanaAuthError extends DocmanaError {
139
- constructor(message: string, opts?: {
140
- status?: number;
141
- requestId?: string;
142
- });
143
- }
144
- declare class DocmanaPermissionError extends DocmanaError {
145
- constructor(message: string, opts?: {
146
- status?: number;
147
- requestId?: string;
148
- });
149
- }
150
- declare class DocmanaNotFoundError extends DocmanaError {
151
- constructor(message: string, opts?: {
152
- status?: number;
153
- requestId?: string;
154
- });
155
- }
156
- declare class DocmanaRequestError extends DocmanaError {
157
- constructor(message: string, opts?: {
158
- status?: number;
159
- requestId?: string;
160
- });
161
- }
162
- declare class DocmanaExecutionError extends DocmanaError {
163
- readonly errors: unknown[];
164
- readonly result?: DocmanaExecutionResult;
165
- constructor(message: string, errors?: unknown[], result?: DocmanaExecutionResult);
166
- }
167
- declare class DocmanaTimeoutError extends DocmanaError {
168
- constructor(message: string);
169
- }
170
- declare class DocmanaAbortError extends DocmanaError {
171
- constructor(message: string);
172
- }
173
-
174
- interface PhysicalDocument {
175
- physical_document_name: string;
176
- physical_document_id: string;
177
- physical_document_path?: string;
178
- page_from: number;
179
- page_to: number;
180
- physical_document_url?: string;
181
- metadata?: Record<string, unknown>;
182
- }
183
-
184
- interface DocumentContent {
185
- coordinates_unit?: string;
186
- pages?: Array<Array<Record<string, unknown>>>;
187
- }
188
-
189
- interface VirtualDocument {
190
- source: PhysicalDocument;
191
- virtual_document_name: string;
192
- virtual_document_id: string;
193
- is_translated: boolean;
194
- document_types?: string[];
195
- content?: DocumentContent;
196
- }
197
-
198
- type FlowNodeType = "Start" | "Finish" | "DataMapping" | "Classification" | "Extraction" | "Validation" | "CrossValidation" | "MetadataExtraction";
199
-
200
- interface FlowConfigs {
201
- description?: string | null;
202
- useIntelligentSplitting: boolean;
203
- useSplittingAsContextOnly: boolean;
204
- useDetectAndClassifyPII: boolean;
205
- enableChatFeature: boolean;
206
- defaultLanguage?: string | null;
207
- additionalLanguages?: string[] | null;
208
- enableDocumentPersistenceForViewing: boolean;
209
- preClassificationAggregatorPrompt?: string | null;
210
- preClassificationSummarizerPrompt?: string | null;
211
- enforceSingleClassificationPerDocument?: boolean | null;
212
- useFraudDetection: boolean;
213
- fraudDetectionThreshold: number;
214
- useMetadataExtraction: boolean;
215
- }
216
-
217
- interface FlowNodePromptMessage {
218
- role: string;
219
- content: string;
220
- type?: string | null;
221
- }
222
- interface FlowNodePromptOutputStructure {
223
- output_structure: Record<string, {
224
- type: string;
225
- description?: string | null;
226
- items?: Record<string, unknown> | null;
227
- properties?: Record<string, unknown> | null;
228
- context?: string | null;
229
- }>;
230
- }
231
- interface FlowNode {
232
- node_id: string;
233
- label: string;
234
- unique_name?: string | null;
235
- type: FlowNodeType;
236
- has_single_document_type: boolean;
237
- prompt_id?: string | null;
238
- commit?: string | null;
239
- target_language?: string | null;
240
- mock_results?: Record<string, unknown> | null;
241
- enabled?: boolean;
242
- model?: string | null;
243
- classification_priority?: number;
244
- prompt_messages?: {
245
- messages: FlowNodePromptMessage[];
246
- } | null;
247
- prompt_output_structure?: FlowNodePromptOutputStructure | null;
248
- }
249
-
250
- interface FlowEdge {
251
- source: string;
252
- target: string;
253
- }
254
-
255
- interface Flow {
256
- flow_id: string;
257
- name: string;
258
- version: number;
259
- configs: FlowConfigs;
260
- nodes: FlowNode[];
261
- edges: FlowEdge[];
262
- }
263
-
264
- interface NodeTranslationResult {
265
- status?: string;
266
- running_time?: number | null;
267
- feedback?: string | null;
268
- score?: number | null;
269
- [key: string]: unknown;
270
- }
271
-
272
- interface ExecutionProgress {
273
- status: string;
274
- errors?: string[];
275
- }
276
-
277
- interface DocmanaApiDocumentRequest {
278
- name: string;
279
- file_extension: string;
280
- sas_url: string;
281
- blob_name: string;
282
- uuid_file: string;
283
- physical_document_id?: string | null;
284
- doc_key: string | null;
285
- status?: string | null;
286
- error_message?: string | null;
287
- message?: string | null;
288
- message_code?: string | null;
289
- metadata?: Record<string, unknown> | null;
290
- is_temporary_upload?: boolean;
291
- }
292
-
293
- interface DocmanaApiNodeResult {
294
- node_id?: string;
295
- node_name?: string | null;
296
- node_type?: string | null;
297
- feature_name?: string | null;
298
- running_time?: number | null;
299
- status?: string;
300
- score?: number | null;
301
- feedback?: string | null;
302
- translations?: Record<string, NodeTranslationResult> | null;
303
- tokens?: number | null;
304
- input_tokens?: number | null;
305
- output_tokens?: number | null;
306
- errors?: string[];
307
- mana?: number | null;
308
- model?: string | null;
309
- tool_calls?: Record<string, unknown>[] | null;
310
- prompt_id?: string | null;
311
- prompt?: string | null;
312
- prompt_name?: string | null;
313
- label?: string | null;
314
- scoreDescription?: string | null;
315
- score_description?: string | null;
316
- result?: unknown;
317
- documentType?: string | null;
318
- [key: string]: unknown;
319
- }
320
-
321
- interface DocmanaApiDocumentExecutionResult {
322
- document?: DocmanaApiDocumentRequest;
323
- node_results?: DocmanaApiNodeResult[];
324
- status?: string;
325
- error?: string | null;
326
- [key: string]: unknown;
327
- }
328
-
329
- interface DocmanaApiExecutionResult {
330
- status: ExecutionStatus | string;
331
- error?: string;
332
- errors?: string[];
333
- document_requests?: DocmanaApiDocumentRequest[];
334
- flow?: Flow | null;
335
- results?: DocmanaApiDocumentExecutionResult[];
336
- restructured_documents?: VirtualDocument[];
337
- execution_id?: string;
338
- total_running_time?: number;
339
- total_running_time_node?: number;
340
- total_tokens?: number;
341
- total_input_tokens?: number;
342
- total_output_tokens?: number;
343
- total_documents?: number;
344
- total_pages?: number;
345
- event_timestamp?: string;
346
- [key: string]: unknown;
347
- }
348
-
349
- export { Docmana, DocmanaAbortError, type DocmanaApiDocumentExecutionResult, type DocmanaApiDocumentRequest, type DocmanaApiExecutionResult, type DocmanaApiNodeResult, DocmanaAuthError, type DocmanaClassificationResult, type DocmanaConclusionResult, type DocmanaConfig, type DocmanaCrossValidationResult, type DocmanaDocumentMapping, type DocmanaDocumentResult, DocmanaError, DocmanaExecutionError, type DocmanaExecutionResult, type DocmanaExtractionResult, type DocmanaMetadataExtractionResult, type DocmanaNodeResult, DocmanaNotFoundError, DocmanaPermissionError, DocmanaRequestError, type DocmanaScoreNodeResult, DocmanaTimeoutError, type DocmanaValidationResult, type DocumentContent, type ExecutionProgress, type ExecutionStatus, type FileInput, type Flow, type FlowConfigs, type FlowEdge, type FlowNode, type FlowNodeType, type NodeTranslationResult, type PhysicalDocument, type RunFlowInput, type RunFlowWithCallbackInput, type VirtualDocument };