@docmana/sdk 0.20.0 → 0.22.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,5 +1,24 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.22.0 - 2026-08-06
4
+
5
+ - Expose the complete Consumer Edge fraud-analysis telemetry: global totals,
6
+ preprocessing, verdict, and per-layer duration, token usage, LLM calls, model
7
+ usage, cost, and errors.
8
+ - Keep model usage Mongo-safe as `modelUsage[]` and continue excluding the
9
+ sensitive Fraud `document` payload.
10
+
11
+ ## 0.21.0 - 2026-08-05
12
+
13
+ - Relay the native Fraud job identifier through Consumer Edge while preserving
14
+ the existing high-level polling workflow.
15
+ - Add local file, named byte, and readable stream inputs to `detectFraud` and
16
+ `detectFraudAsync` through the existing `FileInput` contract.
17
+ - Stop sending organization correlation on Fraud requests. The deprecated
18
+ organization arguments remain accepted and ignored for source compatibility.
19
+ - Expose Consumer Edge's BI-friendly Fraud result contract: aggregate `summary`,
20
+ referenced `findings`, and detection `layers` keyed by their unique names.
21
+
3
22
  ## 0.20.0 - 2026-08-04
4
23
 
5
24
  - Add `detectFraud` to start a Consumer Edge fraud-detection job, poll its
package/README.md CHANGED
@@ -38,13 +38,12 @@ result:
38
38
 
39
39
  ```ts
40
40
  const fraud = await docmana.detectFraud({
41
- documentUrl: "https://downloads.example.com/claim.pdf?token=...",
42
- filename: "claim.pdf",
41
+ file: "./claim.pdf",
43
42
  analystContext: "Travel claim; verify the invoice total.",
44
- organization: "acme",
45
43
  });
46
44
 
47
- console.log(fraud.verdict, fraud.confidence, fraud.findings);
45
+ console.log(fraud.verdict, fraud.summary.highestSeverity);
46
+ console.log(fraud.layers.pixel?.findingReferences, fraud.findings);
48
47
  ```
49
48
 
50
49
  ## Authentication
@@ -143,21 +142,41 @@ use `RunFlowParams` for request data:
143
142
  - `runFlow(flowId, params, options?)` starts async execution, polls status, fetches the
144
143
  result, respects `X-Poll-After` and `429 Retry-After` while polling, and throws
145
144
  `DocmanaExecutionError` if the result status is `FAILED`.
146
- - `detectFraud(params, options?)` starts fraud detection from `documentUrl`, polls
147
- Consumer until `COMPLETED` or `FAILED`, and returns the normalized verdict and findings.
145
+ - `detectFraud(params, options?)` starts fraud detection from either `documentUrl`
146
+ plus `filename`, or a local `file` using the standard `FileInput` contract. It polls
147
+ Consumer until `COMPLETED` or `FAILED` and returns the normalized verdict, aggregate
148
+ `summary`, `findings` with job-local references, and detection `layers` keyed by name.
149
+ The completed result also exposes global, preprocessing, verdict, and per-layer
150
+ telemetry (`durationMs`, token counts, LLM calls, `modelUsage`, and `cost`). The
151
+ sensitive Fraud `document` payload is intentionally never exposed by Consumer or SDK.
148
152
  - `detectFraudAsync(params, options?)` starts fraud detection and immediately returns
149
153
  `{ jobId, status }` without polling.
150
- - `getFraudDetectionStatus(jobId, signal?, organization?)` and
151
- `getFraudDetectionResult(jobId, signal?, organization?)` provide the lower-level
152
- polling workflow.
154
+ - `getFraudDetectionStatus(jobId, signal?)` and
155
+ `getFraudDetectionResult(jobId, signal?)` provide the lower-level polling workflow.
153
156
 
154
157
  Consumer is the polling authority. When `GET /status` returns `X-Poll-After`,
155
158
  the SDK waits that many milliseconds before the next status call. If the header
156
159
  is absent, the SDK falls back to capped exponential full jitter between
157
160
  `pollIntervalMs` and `pollMaxIntervalMs`. `Retry-After` on `429` always wins.
158
161
 
159
- The SDK does not log or return `documentUrl`. Signed query parameters are sent
160
- only in the JSON request body to Consumer Edge.
162
+ The SDK does not log or return `documentUrl` or uploaded file contents. Signed
163
+ query parameters are sent only in the JSON request body to Consumer Edge. Fraud
164
+ jobs are not organization-scoped; the legacy `organization` inputs are accepted
165
+ but ignored for compatibility with SDK 0.20 callers.
166
+
167
+ URL and local-file inputs use the same methods:
168
+
169
+ ```ts
170
+ const fromUrl = await docmana.detectFraudAsync({
171
+ documentUrl: "https://downloads.example.com/claim.pdf?token=...",
172
+ filename: "claim.pdf",
173
+ });
174
+
175
+ const fromFile = await docmana.detectFraudAsync({
176
+ file: { path: "./claim.pdf" },
177
+ analystContext: "Check the invoice total.",
178
+ });
179
+ ```
161
180
 
162
181
  ```ts
163
182
  const partial = await docmana.runPartialFlow("<flow-id>", {
package/dist/cli.mjs CHANGED
@@ -379,8 +379,19 @@ async function getResult(http, executionResultId, signal, language, organization
379
379
 
380
380
  // src/sdk/api/fraud-detection.ts
381
381
  async function startFraudDetection(http, params, signal) {
382
+ if (params.file !== void 0) {
383
+ const [part] = await resolveInputs({ files: [params.file] });
384
+ const form = new FormData();
385
+ form.append("file", new File([part.data], part.filename, { type: part.contentType }));
386
+ if (params.analystContext !== void 0) {
387
+ form.append("analystContext", params.analystContext);
388
+ }
389
+ return http.requestJson("POST", "/fraud-detections", {
390
+ body: form,
391
+ signal
392
+ });
393
+ }
382
394
  return http.requestJson("POST", "/fraud-detections", {
383
- query: organizationQuery(params.organization),
384
395
  headers: { "content-type": "application/json" },
385
396
  body: JSON.stringify({
386
397
  documentUrl: params.documentUrl,
@@ -391,11 +402,11 @@ async function startFraudDetection(http, params, signal) {
391
402
  });
392
403
  }
393
404
  async function getFraudDetectionStatus(http, jobId, signal, organization) {
405
+ void organization;
394
406
  const res = await http.requestRaw(
395
407
  "GET",
396
408
  `/fraud-detections/${encodeURIComponent(jobId)}/status`,
397
409
  {
398
- query: organizationQuery(organization),
399
410
  signal
400
411
  }
401
412
  );
@@ -409,14 +420,11 @@ async function getFraudDetectionStatus(http, jobId, signal, organization) {
409
420
  return pollAfterMs === void 0 ? normalized : { ...normalized, pollAfterMs };
410
421
  }
411
422
  async function getFraudDetectionResult(http, jobId, signal, organization) {
423
+ void organization;
412
424
  return http.requestJson("GET", `/fraud-detections/${encodeURIComponent(jobId)}/result`, {
413
- query: organizationQuery(organization),
414
425
  signal
415
426
  });
416
427
  }
417
- function organizationQuery(organization) {
418
- return organization ? { organization } : void 0;
419
- }
420
428
  function parsePositiveInt2(value) {
421
429
  if (!value) return void 0;
422
430
  const parsed = Number(value);
@@ -644,11 +652,7 @@ var Docmana = class {
644
652
  check: async () => {
645
653
  attempt += 1;
646
654
  try {
647
- const statusResult = await this.getFraudDetectionStatus(
648
- jobId,
649
- options.signal,
650
- params.organization
651
- );
655
+ const statusResult = await this.getFraudDetectionStatus(jobId, options.signal);
652
656
  const nextPollAfterMs = isTerminalStatus(statusResult.status) ? void 0 : statusResult.pollAfterMs;
653
657
  options.onPoll?.({
654
658
  jobId,
@@ -676,7 +680,7 @@ var Docmana = class {
676
680
  signal: options.signal,
677
681
  shouldRetryError: isTransientPollingError
678
682
  });
679
- const result = await this.getFraudDetectionResult(jobId, options.signal, params.organization);
683
+ const result = await this.getFraudDetectionResult(jobId, options.signal);
680
684
  if (isFailedStatus(result.status)) {
681
685
  throw new DocmanaFraudDetectionError(
682
686
  result.error?.message ?? `Fraud detection ${jobId} failed`,