@docmana/sdk 0.4.0 → 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.
package/CHANGELOG.md CHANGED
@@ -1,11 +1,40 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.8.0
4
+ - Add organization document depot methods and CLI commands:
5
+ `listOrganizationDocuments()`, `downloadOrganizationDocument()`, and
6
+ `downloadOrganizationDocuments()`.
7
+ - Add `docmana organization document list/download`.
8
+ - Make `docmana organization document download --output` optional; default output
9
+ is `./{path}`.
10
+
11
+ ## 0.7.0
12
+ - Add `getFlowMetadata()` / `docmana flow metadata` for projected flow runtime
13
+ metadata from `docmana-consumer-edge-api`.
14
+ - Add `getFlowDefinition()` / `docmana flow definition` for normalized flow
15
+ graph definitions without exposing the Docmana ZIP export.
16
+
17
+ ## 0.6.0
18
+ - Add `listOrganizations()` and `docmana organization list` to list organizations
19
+ available through `docmana-consumer-edge-api`.
20
+
21
+ ## 0.5.0
22
+ - Add `listFlows()` to list flows available through `docmana-consumer-edge-api`,
23
+ returning `{ id, name, state }[]` with `state: "unknown"` when Docmana omits it.
24
+ - Add `docmana flow list` CLI command, with the same API URL and Bearer token resolution as `docmana flow run`.
25
+ - Rename `RunFlowInput` to `RunFlowParams` and move polling controls to
26
+ `RunFlowOptions`.
27
+ - Remove the single-file `file` shortcut from flow params; callers now pass
28
+ `files`.
29
+ - Remove `fileName` from flow params; byte and stream inputs now use
30
+ `{ data, filename, contentType? }`.
31
+ - Replace `runFlowWithCallback` with `runFlowAsync(..., { callbackUrl })`.
32
+
3
33
  ## 0.3.5
4
- - Add `runFlowWithCallback(flowId, input)`: starts a flow and returns `{ executionResultId, fileIds }` **without polling**, registering a `callback_url` so docmana-api POSTs a completion notification when the run finishes. Call `getResult(executionResultId)` on receipt to fetch the mapped result. Works with both `run_flow` and `run_once_flow` (via `input.once`).
5
- - New `RunFlowWithCallbackInput` type carries the required `callbackUrl` (wire: `callback_url`). It is intentionally separate from `RunFlowInput`: the polling `runFlow`/`runFlowAsync` remain callback-free, so a callback run never polls or fetches the result inline.
34
+ - Add callback execution support: starts a flow and returns `{ executionResultId, fileIds }` **without polling**, registering a `callback_url` so docmana-api POSTs a completion notification when the run finishes. Call `getResult(executionResultId)` on receipt to fetch the mapped result.
6
35
 
7
36
  ## 0.3.3
8
- - Add `RunFlowInput.context` (business `json_context`): when provided, `runFlow`/`runFlowAsync` include `json_context` in the request body for both `run_flow` and `run_once_flow`. The context is passed through as-is — filtering against the flow's *Start* node properties is performed server-side by docmana-api.
37
+ - Add `RunFlowParams.context` (business `json_context`): when provided, `runFlow`/`runFlowAsync` include `json_context` in the request body for both `run_flow` and `run_once_flow`. The context is passed through as-is — filtering against the flow's *Start* node properties is performed server-side by docmana-api.
9
38
 
10
39
  ## 0.3.2
11
40
  - Add `scoreDescription` to score-node results (Validation, Classification, CrossValidation, Conclusion).
@@ -29,7 +58,7 @@
29
58
  - 400 responses now throw `DocmanaRequestError` (was `DocmanaAuthError`); add `Incompleted` to `ExecutionStatus`.
30
59
 
31
60
  ## 0.2.0
32
- - `RunFlowInput.once` selects the ad-hoc `run_once_flow` endpoint (current/draft flow) instead of the published `run_flow`.
61
+ - `RunFlowParams.once` selects the ad-hoc `run_once_flow` endpoint (current/draft flow) instead of the published `run_flow`.
33
62
  - `DocmanaConfig.headers` are sent on every API request (e.g. `X-Selected-Organization`), without overriding the bearer token or per-request headers.
34
63
  - `FileInput` now accepts a plain `Uint8Array` (e.g. pdf-lib output) in addition to path, `Buffer`, and `Stream`.
35
64
  - Uploads send a `Content-Type` inferred from the filename extension instead of always `application/octet-stream`.
package/README.md CHANGED
@@ -24,7 +24,7 @@ const docmana = new Docmana({
24
24
  });
25
25
 
26
26
  const result = await docmana.runFlow("<flow-id>", {
27
- file: "./contract.pdf",
27
+ files: ["./contract.pdf"],
28
28
  context: { contract: { destination: "Canada" } },
29
29
  useDraftVersion: true,
30
30
  });
@@ -67,37 +67,59 @@ static `accessToken`, `401` is returned as an auth error without retry.
67
67
  `apiBaseUrl` is required so a migrated SDK cannot accidentally call
68
68
  `https://api.docmana.ai`.
69
69
 
70
- ## Inputs
71
-
72
- `runFlow(flowId, input)` and `runFlowAsync(flowId, input)` accept:
73
-
74
- | Field | Type | Description |
75
- | ------------------- | ------------------------------------------------------------------- | -------------------------------------------------------------------- |
76
- | `file` | `string \| { path: string } \| Buffer \| NodeJS.ReadableStream` | A single document. A string or `{ path }` is treated as a file path. |
77
- | `files` | `(string \| { path: string } \| Buffer \| NodeJS.ReadableStream)[]` | Multiple documents for a multi-document flow. |
78
- | `fileName` | `string` | Required when passing a `Buffer` or stream with no derivable name. |
79
- | `context` | `Record<string, unknown>` | Business context serialized as multipart `json_context`. |
80
- | `language` | `string` | Optional result language passed to Consumer. |
81
- | `useDraftVersion` | `boolean` | Runs the current draft flow version. |
82
- | `signal` | `AbortSignal` | Cancels the in-flight request/polling. |
83
- | `timeoutMs` | `number` | Overrides configured polling timeout for this call. |
84
- | `pollIntervalMs` | `number` | Overrides configured fallback minimum polling interval. |
85
- | `pollMaxIntervalMs` | `number` | Overrides configured fallback maximum polling interval. |
86
- | `onPoll` | `(event) => void` | Called after each status poll. |
87
- | `onRateLimit` | `(event) => void` | Called when polling receives `429`; includes `retryAfterMs`. |
70
+ ## Run flow params
71
+
72
+ `runFlow(flowId, params, options)` and `runFlowAsync(flowId, params, options)`
73
+ use `RunFlowParams` for request data:
74
+
75
+ | Field | Type | Description |
76
+ | ----------------- | -------------------------------------------------------------------- | ---------------------------------------------------------------------- |
77
+ | `files` | `(string \| { path: string } \| { data, filename, contentType? })[]` | Documents to upload. A string or `{ path }` is treated as a file path. |
78
+ | `context` | `Record<string, unknown>` | Business context serialized as multipart `json_context`. |
79
+ | `language` | `string` | Optional result language passed to Consumer. |
80
+ | `useDraftVersion` | `boolean` | Runs the current draft flow version. |
81
+ | `callbackUrl` | `string` | Async-only callback URL, serialized as `callback_url`. |
82
+
83
+ `runFlow` uses `RunFlowOptions` for local execution controls:
84
+
85
+ | Field | Type | Description |
86
+ | ------------------- | ----------------- | ------------------------------------------------------------ |
87
+ | `signal` | `AbortSignal` | Cancels the in-flight request/polling. |
88
+ | `timeoutMs` | `number` | Overrides configured polling timeout for this call. |
89
+ | `pollIntervalMs` | `number` | Overrides configured fallback minimum polling interval. |
90
+ | `pollMaxIntervalMs` | `number` | Overrides configured fallback maximum polling interval. |
91
+ | `onPoll` | `(event) => void` | Called after each status poll. |
92
+ | `onRateLimit` | `(event) => void` | Called when polling receives `429`; includes `retryAfterMs`. |
93
+
94
+ `runFlowAsync` accepts `RunFlowAsyncOptions` with `signal`.
88
95
 
89
96
  `once` was removed. Use `useDraftVersion`.
90
97
 
91
98
  ## Methods
92
99
 
93
- - `runFlowAsync(flowId, input)` posts multipart files to
100
+ - `listFlows()` calls `GET /v1/flows` and returns `{ id, name, state }[]` for
101
+ the flows available to the Bearer token. Missing flow states are returned as
102
+ `"unknown"`.
103
+ - `listOrganizations()` calls `GET /v1/organizations` and returns
104
+ `{ id, name }[]` for the organizations available to the Bearer token.
105
+ - `getFlowMetadata(flowId)` calls `GET /v1/flows/:flowId/metadata` and returns
106
+ `{ flowId, name?, contextSchema, languages, minScore?, documents }`.
107
+ - `getFlowDefinition(flowId)` calls `GET /v1/flows/:flowId/definition` and
108
+ returns the normalized flow definition `{ flowId, name?, languages, minScore?, nodes }`.
109
+ - `listOrganizationDocuments({ prefix? })` calls
110
+ `GET /v1/organization-documents` and returns `{ configured, documents }`.
111
+ - `downloadOrganizationDocument(path)` calls
112
+ `GET /v1/organization-documents/download?path=...` and returns
113
+ `{ bytes, filename, contentType? }`.
114
+ - `downloadOrganizationDocuments(paths)` downloads each requested path.
115
+ - `runFlowAsync(flowId, params, options?)` posts multipart files to
94
116
  `POST /v1/flows/:flowId/execute-async` and returns
95
117
  `{ executionResultId, fileIds }`.
96
118
  - `getStatus(executionResultId)` calls
97
119
  `GET /v1/executions/:executionResultId/status`.
98
120
  - `getResult(executionResultId, signal?, language?)` calls
99
121
  `GET /v1/executions/:executionResultId/result`.
100
- - `runFlow(flowId, input)` starts async execution, polls status, fetches the
122
+ - `runFlow(flowId, params, options?)` starts async execution, polls status, fetches the
101
123
  result, respects `X-Poll-After` and `429 Retry-After` while polling, and throws
102
124
  `DocmanaExecutionError` if the result status is `Failed`.
103
125
 
@@ -106,9 +128,35 @@ the SDK waits that many milliseconds before the next status call. If the header
106
128
  is absent, the SDK falls back to capped exponential full jitter between
107
129
  `pollIntervalMs` and `pollMaxIntervalMs`. `Retry-After` on `429` always wins.
108
130
 
131
+ ```ts
132
+ const flows = await docmana.listFlows();
133
+ console.log(flows.map((flow) => `${flow.id}: ${flow.name} (${flow.state})`).join("\n"));
134
+ ```
135
+
136
+ ```ts
137
+ const organizations = await docmana.listOrganizations();
138
+ console.log(organizations.map((org) => `${org.id}: ${org.name}`).join("\n"));
139
+ ```
140
+
141
+ ```ts
142
+ const metadata = await docmana.getFlowMetadata("<flow-id>");
143
+ console.log(metadata.contextSchema);
144
+
145
+ const definition = await docmana.getFlowDefinition("<flow-id>");
146
+ console.log(definition.nodes.map((node) => node.label).join("\n"));
147
+ ```
148
+
149
+ ```ts
150
+ const depot = await docmana.listOrganizationDocuments({ prefix: "dossier/" });
151
+ if (depot.configured) {
152
+ const file = await docmana.downloadOrganizationDocument(depot.documents[0].path);
153
+ console.log(file.filename, file.bytes.byteLength);
154
+ }
155
+ ```
156
+
109
157
  ```ts
110
158
  const { executionResultId } = await docmana.runFlowAsync("<flow-id>", {
111
- file: "./contract.pdf",
159
+ files: ["./contract.pdf"],
112
160
  });
113
161
 
114
162
  let status = "Pending";
@@ -122,12 +170,12 @@ const result = await docmana.getResult(executionResultId, undefined, "fr");
122
170
 
123
171
  ## Webhook callbacks
124
172
 
125
- `runFlowWithCallback` uses the same Consumer async endpoint with `callback_url`.
126
- It returns immediately and does not poll.
173
+ `runFlowAsync(flowId, params, options?)` accepts `callbackUrl` and sends it as
174
+ `callback_url`. It returns immediately and does not poll.
127
175
 
128
176
  ```ts
129
- const { executionResultId } = await docmana.runFlowWithCallback("<flow-id>", {
130
- file: "./contract.pdf",
177
+ const { executionResultId } = await docmana.runFlowAsync("<flow-id>", {
178
+ files: ["./contract.pdf"],
131
179
  callbackUrl: "https://your-service.example.com/webhooks/docmana/executions",
132
180
  language: "fr",
133
181
  });
@@ -157,6 +205,29 @@ in this order:
157
205
  3. valid `docmana.token.json`
158
206
  4. OAuth refresh using CLI/config credentials
159
207
 
208
+ ```bash
209
+ DOCMANA_API_URL="https://consumer.example.com/v1"
210
+ docmana flow list
211
+ ```
212
+
213
+ ```bash
214
+ DOCMANA_API_URL="https://consumer.example.com/v1"
215
+ docmana organization list
216
+ ```
217
+
218
+ ```bash
219
+ DOCMANA_API_URL="https://consumer.example.com/v1"
220
+ docmana organization document list --prefix "dossier/"
221
+ docmana organization document download "dossier/facture.pdf"
222
+ docmana organization document download "dossier/facture.pdf" --output "./facture.pdf"
223
+ ```
224
+
225
+ ```bash
226
+ DOCMANA_API_URL="https://consumer.example.com/v1"
227
+ docmana flow metadata "<flow-id>"
228
+ docmana flow definition "<flow-id>"
229
+ ```
230
+
160
231
  ```bash
161
232
  DOCMANA_API_URL="https://consumer.example.com/v1"
162
233
  docmana flow run "<flow-id>" --files "./contract.pdf"
@@ -174,6 +245,10 @@ docmana flow run "<flow-id>" \
174
245
  ```
175
246
 
176
247
  Use `--draft` to run the current draft flow version.
248
+ Use `docmana flow list --json` to print the raw flow list returned by Consumer.
249
+ Use `docmana organization list --json` to print the organization list as JSON.
250
+ Use `docmana organization document list --json` for raw organization document JSON.
251
+ `docmana flow metadata` and `docmana flow definition` print JSON by default.
177
252
 
178
253
  The CLI no longer sends `X-Selected-Organization`; Consumer derives identity
179
254
  from the Bearer token.
@@ -0,0 +1,3 @@
1
+ import type { HttpClient } from "../http/http-client.js";
2
+ import type { FlowDefinition } from "../types.js";
3
+ export declare function getFlowDefinition(http: HttpClient, flowId: string): Promise<FlowDefinition>;
@@ -0,0 +1,3 @@
1
+ import type { HttpClient } from "../http/http-client.js";
2
+ import type { FlowMetadata } from "../types.js";
3
+ export declare function getFlowMetadata(http: HttpClient, flowId: string): Promise<FlowMetadata>;
@@ -0,0 +1,3 @@
1
+ import type { HttpClient } from "../http/http-client.js";
2
+ import type { FlowListItem } from "../types.js";
3
+ export declare function listFlows(http: HttpClient): Promise<FlowListItem[]>;
@@ -0,0 +1,3 @@
1
+ import type { HttpClient } from "../http/http-client.js";
2
+ import type { AccessibleOrganization } from "../types.js";
3
+ export declare function listOrganizations(http: HttpClient): Promise<AccessibleOrganization[]>;
@@ -0,0 +1,7 @@
1
+ import type { HttpClient } from "../http/http-client.js";
2
+ import type { DownloadedOrganizationDocument, OrganizationDocumentsPayload } from "../types.js";
3
+ export declare function listOrganizationDocuments(http: HttpClient, options?: {
4
+ prefix?: string;
5
+ }): Promise<OrganizationDocumentsPayload>;
6
+ export declare function downloadOrganizationDocument(http: HttpClient, path: string): Promise<DownloadedOrganizationDocument>;
7
+ export declare function downloadOrganizationDocuments(http: HttpClient, paths: string[]): Promise<DownloadedOrganizationDocument[]>;