@docmana/sdk 0.3.5 → 0.4.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/README.md +115 -247
- package/dist/api/execution-result.d.ts +3 -0
- package/dist/api/execution-status.d.ts +6 -0
- package/dist/api/run-flow.d.ts +6 -0
- package/dist/cli.mjs +217 -257
- package/dist/cli.mjs.map +1 -1
- package/dist/client.d.ts +21 -0
- package/dist/config.d.ts +21 -0
- package/dist/errors.d.ts +55 -0
- package/dist/files/resolve-input.d.ts +11 -0
- package/dist/http/http-client.d.ts +26 -0
- package/dist/index.d.ts +4 -349
- package/dist/index.js +159 -298
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +159 -298
- package/dist/index.mjs.map +1 -1
- package/dist/models/docmana-api-document-execution-result.model.d.ts +9 -0
- package/dist/models/docmana-api-document-request.model.d.ts +15 -0
- package/dist/models/docmana-api-execution-result.model.d.ts +24 -0
- package/dist/models/docmana-api-node-result.model.d.ts +28 -0
- package/dist/models/docmana-classification-result.model.d.ts +3 -0
- package/dist/models/docmana-conclusion-result.model.d.ts +3 -0
- package/dist/models/docmana-cross-validation-result.model.d.ts +3 -0
- package/dist/models/docmana-document-mapping.model.d.ts +4 -0
- package/dist/models/docmana-document-result.model.d.ts +11 -0
- package/dist/models/docmana-execution-result.model.d.ts +15 -0
- package/dist/models/docmana-extraction-result.model.d.ts +3 -0
- package/dist/models/docmana-metadata-extraction-result.model.d.ts +3 -0
- package/dist/models/docmana-node-result.model.d.ts +7 -0
- package/dist/models/docmana-score-node-result.model.d.ts +5 -0
- package/dist/models/docmana-validation-result.model.d.ts +3 -0
- package/dist/models/document-content.model.d.ts +4 -0
- package/dist/models/execution-progress.model.d.ts +4 -0
- package/dist/models/execution-status.enum.d.ts +1 -0
- package/dist/models/flow-configs.model.d.ts +16 -0
- package/dist/models/flow-edge.model.d.ts +4 -0
- package/dist/models/flow-node-type.enum.d.ts +1 -0
- package/dist/models/flow-node.model.d.ts +33 -0
- package/dist/models/flow.model.d.ts +11 -0
- package/dist/models/index.d.ts +26 -0
- package/dist/models/node-translation-result.model.d.ts +7 -0
- package/dist/models/physical-document.model.d.ts +9 -0
- package/dist/models/virtual-document.model.d.ts +10 -0
- package/dist/polling/poll.d.ts +15 -0
- package/dist/types.d.ts +76 -0
- package/package.json +17 -14
- package/dist/index.d.cts +0 -349
package/README.md
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
# @docmana/sdk
|
|
2
2
|
|
|
3
|
-
Official Docmana SDK
|
|
3
|
+
Official Docmana SDK for calling `docmana-consumer-edge-api`.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
const result = await docmana.runFlow("<flow-id>", { file: "./contract.pdf" });
|
|
9
|
-
```
|
|
5
|
+
The SDK sends documents to Consumer, starts an async flow, polls Consumer for
|
|
6
|
+
status, and returns the mapped Consumer execution DTO.
|
|
10
7
|
|
|
11
8
|
## Installation
|
|
12
9
|
|
|
@@ -22,103 +19,92 @@ Requires Node.js 20+.
|
|
|
22
19
|
import { Docmana } from "@docmana/sdk";
|
|
23
20
|
|
|
24
21
|
const docmana = new Docmana({
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
apiBaseUrl: process.env.DOCMANA_API_URL!,
|
|
23
|
+
accessToken: process.env.DOCMANA_ACCESS_TOKEN!,
|
|
27
24
|
});
|
|
28
25
|
|
|
29
|
-
const result = await docmana.runFlow("<flow-id>", {
|
|
26
|
+
const result = await docmana.runFlow("<flow-id>", {
|
|
27
|
+
file: "./contract.pdf",
|
|
28
|
+
context: { contract: { destination: "Canada" } },
|
|
29
|
+
useDraftVersion: true,
|
|
30
|
+
});
|
|
30
31
|
|
|
31
|
-
console.log(result.status, result.
|
|
32
|
+
console.log(result.status, result.executionId);
|
|
32
33
|
```
|
|
33
34
|
|
|
34
|
-
|
|
35
|
+
## Authentication
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
The public SDK is Bearer-only. It does not acquire OAuth tokens and it never
|
|
38
|
+
calls `docmana-api` directly. Provide either a static `accessToken` or a
|
|
39
|
+
`getAccessToken` provider:
|
|
38
40
|
|
|
41
|
+
```ts
|
|
39
42
|
const docmana = new Docmana({
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
apiBaseUrl: "https://consumer.example.com/v1",
|
|
44
|
+
getAccessToken: async ({ forceRefresh } = {}) => {
|
|
45
|
+
return forceRefresh ? refreshTokenSomehow() : currentToken();
|
|
46
|
+
},
|
|
42
47
|
});
|
|
43
|
-
|
|
44
|
-
const result = await docmana.runFlow("<flow-id>", { file: "./contract.pdf" });
|
|
45
48
|
```
|
|
46
49
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
If Consumer returns `401` and `getAccessToken` is configured, the SDK calls
|
|
51
|
+
`getAccessToken({ forceRefresh: true })` once and retries the request. With a
|
|
52
|
+
static `accessToken`, `401` is returned as an auth error without retry.
|
|
50
53
|
|
|
51
54
|
## Configuration
|
|
52
55
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
|
56
|
-
|
|
|
57
|
-
| `
|
|
58
|
-
| `
|
|
59
|
-
| `
|
|
60
|
-
| `
|
|
61
|
-
| `
|
|
62
|
-
| `
|
|
63
|
-
| `pollIntervalMs` | `number` | No | `2000` (2 s) | Delay between status polls in `runFlow`. |
|
|
64
|
-
| `fetch` | `typeof fetch` | No | global `fetch` | Custom `fetch` implementation (e.g. for proxies or testing). |
|
|
56
|
+
| Field | Type | Required | Description |
|
|
57
|
+
| ------------------- | --------------------------------------------------------------------- | -------- | ------------------------------------------------------------ |
|
|
58
|
+
| `apiBaseUrl` | `string` | Yes | Base URL of Consumer API, including version when applicable. |
|
|
59
|
+
| `accessToken` | `string` | One of | Static Bearer token sent to Consumer. |
|
|
60
|
+
| `getAccessToken` | `(options?: { forceRefresh?: boolean }) => string \| Promise<string>` | One of | Token provider for renewable Bearer tokens. |
|
|
61
|
+
| `timeoutMs` | `number` | No | Maximum polling time for `runFlow`. Default: 5 minutes. |
|
|
62
|
+
| `pollIntervalMs` | `number` | No | Fallback minimum delay between status polls. Default: 2s. |
|
|
63
|
+
| `pollMaxIntervalMs` | `number` | No | Fallback maximum polling delay. Default: 10s. |
|
|
64
|
+
| `fetch` | `typeof fetch` | No | Custom fetch implementation. |
|
|
65
|
+
| `headers` | `Record<string, string>` | No | Extra headers sent on every Consumer request. |
|
|
65
66
|
|
|
66
|
-
|
|
67
|
+
`apiBaseUrl` is required so a migrated SDK cannot accidentally call
|
|
68
|
+
`https://api.docmana.ai`.
|
|
67
69
|
|
|
68
70
|
## Inputs
|
|
69
71
|
|
|
70
|
-
`runFlow(flowId, input)`
|
|
71
|
-
|
|
72
|
-
| Field
|
|
73
|
-
|
|
|
74
|
-
| `file`
|
|
75
|
-
| `files`
|
|
76
|
-
| `fileName`
|
|
77
|
-
| `
|
|
78
|
-
| `
|
|
79
|
-
| `
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
Path objects are also supported, which is useful when your caller already models uploads as
|
|
107
|
-
objects:
|
|
108
|
-
|
|
109
|
-
```ts
|
|
110
|
-
await docmana.runFlow("<flow-id>", {
|
|
111
|
-
files: [{ path: "./contract.pdf" }],
|
|
112
|
-
});
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
## Lower-level methods
|
|
116
|
-
|
|
117
|
-
`runFlow` is the recommended entry point. If you need to manage polling yourself — for example to surface progress in your own job queue — the underlying steps are exposed:
|
|
118
|
-
|
|
119
|
-
- `runFlowAsync(flowId, input)` → `{ executionResultId, fileIds }` — uploads the file(s) and starts the flow without waiting; `fileIds` are the uploaded document UUIDs.
|
|
120
|
-
- `getStatus(executionResultId)` → `{ status }` — current execution status (`"Pending" | "Running" | "Completed" | "Failed"`).
|
|
121
|
-
- `getResult(executionResultId)` → `ExecutionResult` — the result payload once the flow has finished.
|
|
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`. |
|
|
88
|
+
|
|
89
|
+
`once` was removed. Use `useDraftVersion`.
|
|
90
|
+
|
|
91
|
+
## Methods
|
|
92
|
+
|
|
93
|
+
- `runFlowAsync(flowId, input)` posts multipart files to
|
|
94
|
+
`POST /v1/flows/:flowId/execute-async` and returns
|
|
95
|
+
`{ executionResultId, fileIds }`.
|
|
96
|
+
- `getStatus(executionResultId)` calls
|
|
97
|
+
`GET /v1/executions/:executionResultId/status`.
|
|
98
|
+
- `getResult(executionResultId, signal?, language?)` calls
|
|
99
|
+
`GET /v1/executions/:executionResultId/result`.
|
|
100
|
+
- `runFlow(flowId, input)` starts async execution, polls status, fetches the
|
|
101
|
+
result, respects `X-Poll-After` and `429 Retry-After` while polling, and throws
|
|
102
|
+
`DocmanaExecutionError` if the result status is `Failed`.
|
|
103
|
+
|
|
104
|
+
Consumer is the polling authority. When `GET /status` returns `X-Poll-After`,
|
|
105
|
+
the SDK waits that many milliseconds before the next status call. If the header
|
|
106
|
+
is absent, the SDK falls back to capped exponential full jitter between
|
|
107
|
+
`pollIntervalMs` and `pollMaxIntervalMs`. `Retry-After` on `429` always wins.
|
|
122
108
|
|
|
123
109
|
```ts
|
|
124
110
|
const { executionResultId } = await docmana.runFlowAsync("<flow-id>", {
|
|
@@ -131,221 +117,103 @@ while (status !== "Completed" && status !== "Failed") {
|
|
|
131
117
|
({ status } = await docmana.getStatus(executionResultId));
|
|
132
118
|
}
|
|
133
119
|
|
|
134
|
-
const result = await docmana.getResult(executionResultId);
|
|
135
|
-
console.log(result.status, result.results);
|
|
120
|
+
const result = await docmana.getResult(executionResultId, undefined, "fr");
|
|
136
121
|
```
|
|
137
122
|
|
|
138
|
-
Unlike `runFlow`, `getResult` does not throw on a failed execution — inspect `result.status` and `result.errors` yourself.
|
|
139
|
-
|
|
140
123
|
## Webhook callbacks
|
|
141
124
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
- `runFlowWithCallback(flowId, input)` → `{ executionResultId, fileIds }` — uploads the file(s) and starts the flow with the callback registered. It does **not** poll and does **not** fetch the result.
|
|
145
|
-
|
|
146
|
-
`input` is a `RunFlowWithCallbackInput`:
|
|
147
|
-
|
|
148
|
-
| Field | Type | Required | Description |
|
|
149
|
-
| ------------- | ------------------------------------------------------------------- | -------- | ---------------------------------------------------------------------------- |
|
|
150
|
-
| `callbackUrl` | `string` | Yes | URL docmana-api POSTs the completion notification to (wire: `callback_url`). |
|
|
151
|
-
| `file` | `string \| { path: string } \| Buffer \| NodeJS.ReadableStream` | — | A single document. |
|
|
152
|
-
| `files` | `(string \| { path: string } \| Buffer \| NodeJS.ReadableStream)[]` | — | Multiple documents for a multi-document flow. |
|
|
153
|
-
| `fileName` | `string` | — | Required when passing a `Buffer`/stream with no derivable name. |
|
|
154
|
-
| `once` | `boolean` | — | Use the ad-hoc `run_once_flow` endpoint instead of `run_flow`. |
|
|
155
|
-
| `context` | `Record<string, unknown>` | — | Business `json_context` passed through to the flow. |
|
|
156
|
-
| `signal` | `AbortSignal` | — | Cancels the upload/start. |
|
|
157
|
-
|
|
158
|
-
`callbackUrl` lives only on this input — `RunFlowInput` (used by `runFlow`/`runFlowAsync`) has no callback field, so a polling run never registers one.
|
|
159
|
-
|
|
160
|
-
The notification payload docmana-api sends is a small JSON object, e.g.:
|
|
161
|
-
|
|
162
|
-
```json
|
|
163
|
-
{
|
|
164
|
-
"execution_id": "faad872c-…",
|
|
165
|
-
"status": "Success",
|
|
166
|
-
"timestamp": "2026-06-08T21:45:28.415402+00:00",
|
|
167
|
-
"flow_id": "f87bb991-…"
|
|
168
|
-
}
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
It is a notification only — it does not carry the result. On receipt, fetch and map the full result with `getResult`:
|
|
125
|
+
`runFlowWithCallback` uses the same Consumer async endpoint with `callback_url`.
|
|
126
|
+
It returns immediately and does not poll.
|
|
172
127
|
|
|
173
128
|
```ts
|
|
174
129
|
const { executionResultId } = await docmana.runFlowWithCallback("<flow-id>", {
|
|
175
130
|
file: "./contract.pdf",
|
|
176
131
|
callbackUrl: "https://your-service.example.com/webhooks/docmana/executions",
|
|
132
|
+
language: "fr",
|
|
177
133
|
});
|
|
178
|
-
|
|
179
|
-
// …later, in your webhook handler, keyed by the notification's execution_id:
|
|
180
|
-
const result = await docmana.getResult(execution_id);
|
|
181
|
-
console.log(result.status, result.results);
|
|
182
134
|
```
|
|
183
135
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
The package also installs a `docmana` command for simple terminal usage:
|
|
136
|
+
Consumer posts the mapped result DTO to your callback URL when the execution is
|
|
137
|
+
finished. Keep `executionResultId` if you also want to poll as a fallback.
|
|
187
138
|
|
|
188
|
-
|
|
189
|
-
docmana flow run "<flow-id>" --files "./contract.pdf" --organisation "<organisation-id>"
|
|
190
|
-
```
|
|
139
|
+
## CLI
|
|
191
140
|
|
|
192
|
-
|
|
141
|
+
The CLI can still acquire and cache a token through OAuth:
|
|
193
142
|
|
|
194
143
|
```bash
|
|
195
144
|
docmana config init
|
|
145
|
+
docmana login
|
|
196
146
|
```
|
|
197
147
|
|
|
198
|
-
|
|
199
|
-
|
|
148
|
+
`docmana login` reads `clientId`, `clientSecret`, `tokenEndpoint`, and `scope`
|
|
149
|
+
from flags, environment variables, or `docmana.config.json`, then stores the
|
|
150
|
+
access token in `docmana.token.json`.
|
|
200
151
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
```bash
|
|
204
|
-
docmana config init --config ./docmana.dev.config.json
|
|
205
|
-
docmana flow run "<flow-id>" --files "./contract.pdf" --config ./docmana.dev.config.json
|
|
206
|
-
```
|
|
152
|
+
`docmana flow run` always passes a Bearer token to the SDK. It resolves the token
|
|
153
|
+
in this order:
|
|
207
154
|
|
|
208
|
-
|
|
209
|
-
|
|
155
|
+
1. `--access-token`
|
|
156
|
+
2. `DOCMANA_ACCESS_TOKEN`
|
|
157
|
+
3. valid `docmana.token.json`
|
|
158
|
+
4. OAuth refresh using CLI/config credentials
|
|
210
159
|
|
|
211
160
|
```bash
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
DOCMANA_ORGANISATION="<organisation-id>"
|
|
215
|
-
DOCMANA_API_URL="https://api.docmana.ai"
|
|
216
|
-
DOCMANA_TOKEN_URL="<token-endpoint>"
|
|
217
|
-
DOCMANA_SCOPE="<oauth-scope>"
|
|
218
|
-
|
|
219
|
-
docmana flow run "<flow-id>" --files "./contract.pdf,./annexe.pdf"
|
|
161
|
+
DOCMANA_API_URL="https://consumer.example.com/v1"
|
|
162
|
+
docmana flow run "<flow-id>" --files "./contract.pdf"
|
|
220
163
|
```
|
|
221
164
|
|
|
222
|
-
You can
|
|
165
|
+
You can also run without the cache:
|
|
223
166
|
|
|
224
167
|
```bash
|
|
225
168
|
docmana flow run "<flow-id>" \
|
|
226
|
-
--
|
|
227
|
-
--
|
|
228
|
-
--
|
|
229
|
-
--
|
|
230
|
-
--
|
|
231
|
-
--token-url "<token-endpoint>" \
|
|
232
|
-
--scope "<oauth-scope>"
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
The CLI caches OAuth2 access tokens in `docmana.token.json` by default, so repeated commands do
|
|
236
|
-
not request a new token until the cached token expires. The cache file is ignored by Git. Use a
|
|
237
|
-
custom token cache path when needed:
|
|
238
|
-
|
|
239
|
-
```bash
|
|
240
|
-
docmana login
|
|
241
|
-
docmana flow run "<flow-id>" --files "./contract.pdf" --token-cache ./docmana.dev.token.json
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
`docmana login` loads the same config, environment variables, and auth flags as `flow run`, then
|
|
245
|
-
ensures a valid token is cached. It does not print the token.
|
|
246
|
-
|
|
247
|
-
By default, the CLI prints a human-readable summary with a preview of the results. Use `--json`
|
|
248
|
-
to print the complete result payload to stdout:
|
|
249
|
-
|
|
250
|
-
```bash
|
|
251
|
-
docmana flow run "<flow-id>" --files "./contract.pdf" --organisation "<organisation-id>" --json
|
|
169
|
+
--api-url "https://consumer.example.com/v1" \
|
|
170
|
+
--access-token "$DOCMANA_ACCESS_TOKEN" \
|
|
171
|
+
--files "./contract.pdf,./annexe.pdf" \
|
|
172
|
+
--draft \
|
|
173
|
+
--json
|
|
252
174
|
```
|
|
253
175
|
|
|
254
|
-
`--
|
|
176
|
+
Use `--draft` to run the current draft flow version.
|
|
255
177
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
```bash
|
|
259
|
-
npm run cli:link
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
Then run:
|
|
263
|
-
|
|
264
|
-
```bash
|
|
265
|
-
docmana flow run "<flow-id>" --files "./contract.pdf" --organisation "<organisation-id>"
|
|
266
|
-
```
|
|
178
|
+
The CLI no longer sends `X-Selected-Organization`; Consumer derives identity
|
|
179
|
+
from the Bearer token.
|
|
267
180
|
|
|
268
181
|
## Error handling
|
|
269
182
|
|
|
270
|
-
Every error
|
|
271
|
-
|
|
272
|
-
| Error | Thrown when |
|
|
273
|
-
| ------------------------ | ------------------------------------------------------------------------------- |
|
|
274
|
-
| `DocmanaRequestError` | `400` — bad request (e.g. calling for a result before the flow has finished). |
|
|
275
|
-
| `DocmanaAuthError` | `401` — bad credentials, wrong scope, or an expired/rejected token. |
|
|
276
|
-
| `DocmanaPermissionError` | `403` — the client is missing the `access_m2m_apps` role. |
|
|
277
|
-
| `DocmanaNotFoundError` | `404` — the flow or endpoint was not found. |
|
|
278
|
-
| `DocmanaExecutionError` | The flow finished with status `"Failed"`. Carries the flow errors in `.errors`. |
|
|
279
|
-
| `DocmanaTimeoutError` | Polling exceeded `timeoutMs` before the flow reached a terminal state. |
|
|
280
|
-
| `DocmanaAbortError` | The provided `AbortSignal` fired. |
|
|
183
|
+
Every SDK error extends `DocmanaError`, which carries `.status`, `.code`, and an
|
|
184
|
+
optional `.requestId` when available.
|
|
281
185
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
const result = await docmana.runFlow("<flow-id>", { file: "./contract.pdf" });
|
|
292
|
-
console.log(result.results);
|
|
293
|
-
} catch (err) {
|
|
294
|
-
if (err instanceof DocmanaAuthError) {
|
|
295
|
-
// Check client_id / client_secret / scope.
|
|
296
|
-
} else if (err instanceof DocmanaExecutionError) {
|
|
297
|
-
console.error("Flow failed:", err.errors);
|
|
298
|
-
} else if (err instanceof DocmanaTimeoutError) {
|
|
299
|
-
// Retry, or raise timeoutMs.
|
|
300
|
-
} else {
|
|
301
|
-
throw err;
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
```
|
|
305
|
-
|
|
306
|
-
## Security
|
|
307
|
-
|
|
308
|
-
Treat `clientSecret` as a credential with full access to your Docmana account.
|
|
309
|
-
|
|
310
|
-
- Store `clientId` and `clientSecret` in a secrets manager (Azure Key Vault, AWS Secrets Manager, etc.).
|
|
311
|
-
- Never commit them to source control, and never expose them in a browser or frontend bundle — this SDK is server-side only.
|
|
312
|
-
- Never log them.
|
|
313
|
-
|
|
314
|
-
The SDK keeps the bearer token in memory only. It is never written to disk.
|
|
315
|
-
|
|
316
|
-
## Requirements
|
|
317
|
-
|
|
318
|
-
- Node.js 20 or later.
|
|
319
|
-
- ESM and CommonJS are both supported.
|
|
186
|
+
| Error | Thrown when |
|
|
187
|
+
| ------------------------ | -------------------------------------------------------------------------- |
|
|
188
|
+
| `DocmanaRequestError` | `400` bad request. |
|
|
189
|
+
| `DocmanaAuthError` | `401` rejected or expired Bearer token. |
|
|
190
|
+
| `DocmanaPermissionError` | `403` missing permission. |
|
|
191
|
+
| `DocmanaNotFoundError` | `404` flow or execution not found. |
|
|
192
|
+
| `DocmanaExecutionError` | The flow finished with status `"Failed"`. Carries `.errors` and `.result`. |
|
|
193
|
+
| `DocmanaTimeoutError` | Polling exceeded `timeoutMs`. |
|
|
194
|
+
| `DocmanaAbortError` | The provided `AbortSignal` fired. |
|
|
320
195
|
|
|
321
196
|
## Local development with yalc
|
|
322
197
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
In **this library**:
|
|
198
|
+
In this library:
|
|
326
199
|
|
|
327
200
|
```bash
|
|
328
201
|
npm run dev
|
|
329
202
|
```
|
|
330
203
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
In the **consuming project** (once):
|
|
204
|
+
In the consuming project:
|
|
334
205
|
|
|
335
206
|
```bash
|
|
336
207
|
yalc add @docmana/sdk
|
|
337
208
|
npm install
|
|
338
209
|
```
|
|
339
210
|
|
|
340
|
-
|
|
211
|
+
For a one-shot publish to the local yalc store:
|
|
341
212
|
|
|
342
213
|
```bash
|
|
343
|
-
|
|
344
|
-
npm install
|
|
214
|
+
npm run yalc:publish
|
|
345
215
|
```
|
|
346
216
|
|
|
347
|
-
For a single one-shot publish to the local yalc store (no watch), use `npm run yalc:publish`.
|
|
348
|
-
|
|
349
217
|
## License
|
|
350
218
|
|
|
351
219
|
MIT
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { HttpClient } from "../http/http-client.js";
|
|
2
|
+
import type { ExecutionStatus } from "../types.js";
|
|
3
|
+
export declare function getStatus(http: HttpClient, executionResultId: string, signal?: AbortSignal): Promise<{
|
|
4
|
+
status: ExecutionStatus | string;
|
|
5
|
+
pollAfterMs?: number;
|
|
6
|
+
}>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ResolvedPart } from "../files/resolve-input.js";
|
|
2
|
+
import type { HttpClient } from "../http/http-client.js";
|
|
3
|
+
export declare function runFlow(http: HttpClient, flowId: string, parts: ResolvedPart[], signal?: AbortSignal, useDraftVersion?: boolean, context?: Record<string, unknown>, callbackUrl?: string, language?: string): Promise<{
|
|
4
|
+
executionResultId: string;
|
|
5
|
+
fileIds: string[];
|
|
6
|
+
}>;
|