@abyss-project/tools 2.15.0 → 2.16.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.
@@ -1,4 +1,4 @@
1
- import type { IExtractBody } from '../types';
1
+ import type { IExtractApplicationBody } from '../types';
2
2
  import type { IExtractSyncResponse } from '../types';
3
3
  import { ExtractCallOptions } from './extraction.api';
4
- export declare const runExtractionApplication: (applicationId: string, body: IExtractBody, options?: ExtractCallOptions, applicationApiKey?: string) => Promise<IExtractSyncResponse>;
4
+ export declare const runExtractionApplication: (applicationId: string, body: IExtractApplicationBody, options?: ExtractCallOptions, applicationApiKey?: string) => Promise<IExtractSyncResponse>;
@@ -12,18 +12,11 @@ const runExtractionApplication = async (applicationId, body, options = {}, appli
12
12
  extraHeaders['Idempotency-Key'] = options.idempotencyKey;
13
13
  }
14
14
  const url = `extract/application/${applicationId}/extract`;
15
- if (body.pdf) {
16
- const form = (0, extraction_api_1.buildExtractMultipart)(body);
17
- return (await __1.AbyssToolsCore.axios.post(url, form, {
18
- headers: { ...authHeaderApplication(applicationApiKey), ...extraHeaders },
19
- maxBodyLength: Infinity,
20
- maxContentLength: Infinity,
21
- })).data;
22
- }
23
- const jsonBody = { ...body };
24
- delete jsonBody.pdf;
25
- return (await __1.AbyssToolsCore.axios.post(url, jsonBody, {
15
+ const form = (0, extraction_api_1.buildExtractMultipart)(body);
16
+ return (await __1.AbyssToolsCore.axios.post(url, form, {
26
17
  headers: { ...authHeaderApplication(applicationApiKey), ...extraHeaders },
18
+ maxBodyLength: Infinity,
19
+ maxContentLength: Infinity,
27
20
  })).data;
28
21
  };
29
22
  exports.runExtractionApplication = runExtractionApplication;
@@ -1 +1 @@
1
- {"version":3,"file":"extraction.application.api.js","sourceRoot":"","sources":["../../src/api/extraction.application.api.ts"],"names":[],"mappings":";;;AAwBA,0BAAgE;AAGhE,qDAA6E;AAE7E,SAAS,qBAAqB,CAAC,iBAA0B;IACvD,OAAO,iBAAiB,CAAC,CAAC,CAAC,EAAE,CAAC,8BAA0B,CAAC,EAAE,iBAAiB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AACtF,CAAC;AAkBM,MAAM,wBAAwB,GAAG,KAAK,EAC3C,aAAqB,EACrB,IAAkB,EAClB,UAA8B,EAAE,EAChC,iBAA0B,EACK,EAAE;IACjC,MAAM,YAAY,GAA2B,EAAE,CAAC;IAChD,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;QAC3B,YAAY,CAAC,iBAAiB,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC;IAC3D,CAAC;IACD,MAAM,GAAG,GAAG,uBAAuB,aAAa,UAAU,CAAC;IAE3D,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,GAAG,IAAA,sCAAqB,EAAC,IAAI,CAAC,CAAC;QACzC,OAAO,CACL,MAAM,kBAAc,CAAC,KAAK,CAAC,IAAI,CAAuB,GAAG,EAAE,IAAI,EAAE;YAC/D,OAAO,EAAE,EAAE,GAAG,qBAAqB,CAAC,iBAAiB,CAAC,EAAE,GAAG,YAAY,EAAE;YACzE,aAAa,EAAE,QAAQ;YACvB,gBAAgB,EAAE,QAAQ;SAC3B,CAAC,CACH,CAAC,IAAI,CAAC;IACT,CAAC;IAGD,MAAM,QAAQ,GAA8B,EAAE,GAAG,IAAI,EAAE,CAAC;IACxD,OAAQ,QAA8B,CAAC,GAAG,CAAC;IAC3C,OAAO,CACL,MAAM,kBAAc,CAAC,KAAK,CAAC,IAAI,CAAuB,GAAG,EAAE,QAAQ,EAAE;QACnE,OAAO,EAAE,EAAE,GAAG,qBAAqB,CAAC,iBAAiB,CAAC,EAAE,GAAG,YAAY,EAAE;KAC1E,CAAC,CACH,CAAC,IAAI,CAAC;AACT,CAAC,CAAC;AA/BW,QAAA,wBAAwB,4BA+BnC"}
1
+ {"version":3,"file":"extraction.application.api.js","sourceRoot":"","sources":["../../src/api/extraction.application.api.ts"],"names":[],"mappings":";;;AA0BA,0BAAgE;AAGhE,qDAA6E;AAE7E,SAAS,qBAAqB,CAAC,iBAA0B;IACvD,OAAO,iBAAiB,CAAC,CAAC,CAAC,EAAE,CAAC,8BAA0B,CAAC,EAAE,iBAAiB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AACtF,CAAC;AAgBM,MAAM,wBAAwB,GAAG,KAAK,EAC3C,aAAqB,EACrB,IAA6B,EAC7B,UAA8B,EAAE,EAChC,iBAA0B,EACK,EAAE;IACjC,MAAM,YAAY,GAA2B,EAAE,CAAC;IAChD,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;QAC3B,YAAY,CAAC,iBAAiB,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC;IAC3D,CAAC;IACD,MAAM,GAAG,GAAG,uBAAuB,aAAa,UAAU,CAAC;IAE3D,MAAM,IAAI,GAAG,IAAA,sCAAqB,EAAC,IAAI,CAAC,CAAC;IACzC,OAAO,CACL,MAAM,kBAAc,CAAC,KAAK,CAAC,IAAI,CAAuB,GAAG,EAAE,IAAI,EAAE;QAC/D,OAAO,EAAE,EAAE,GAAG,qBAAqB,CAAC,iBAAiB,CAAC,EAAE,GAAG,YAAY,EAAE;QACzE,aAAa,EAAE,QAAQ;QACvB,gBAAgB,EAAE,QAAQ;KAC3B,CAAC,CACH,CAAC,IAAI,CAAC;AACT,CAAC,CAAC;AApBW,QAAA,wBAAwB,4BAoBnC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const api = __importStar(require("./extraction.application.api"));
27
+ const _run = api.runExtractionApplication;
28
+ void _run;
29
+ const _minimal = { pdf, mode: 'auto' };
30
+ const _full = {
31
+ pdf,
32
+ mode: 'hint',
33
+ hint: { bank: 'bnp' },
34
+ pdf_filename: 'invoice.pdf',
35
+ user_external_id: 'u-1',
36
+ user_metadata: { a: 1 },
37
+ archive: true,
38
+ force: false,
39
+ improvementConsent: true,
40
+ };
41
+ const _named = _minimal;
42
+ void _minimal;
43
+ void _full;
44
+ void _named;
45
+ const _noPdf = { mode: 'auto' };
46
+ const _storage = { pdf, mode: 'auto', storage_file_id: 'f' };
47
+ const _templateId = { pdf, mode: 'auto', template_id: 't' };
48
+ const _template = { pdf, mode: 'auto', template: {} };
49
+ const _preset = { pdf, mode: 'auto', plan_preset_id: 'p' };
50
+ const _modeTemplate = { pdf, mode: 'template' };
51
+ const _processing = { pdf, mode: 'auto', processing: 'queue' };
52
+ void _noPdf;
53
+ void _storage;
54
+ void _templateId;
55
+ void _template;
56
+ void _preset;
57
+ void _modeTemplate;
58
+ void _processing;
59
+ //# sourceMappingURL=extraction.application.api.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extraction.application.api.test.js","sourceRoot":"","sources":["../../src/api/extraction.application.api.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAIA,kEAAoD;AAGpD,MAAM,IAA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AACjB,KAAK,SAAS,CAAC;AACf,KAAK,OAAO,CAAC;AACb,KAAK,aAAa,CAAC;AACnB,KAAK,WAAW,CAAC"}
@@ -26,6 +26,18 @@ export interface IExtractBody {
26
26
  plan?: IExtractionPlan;
27
27
  plan_preset_id?: string;
28
28
  }
29
+ export interface IExtractApplicationBody {
30
+ pdf: Buffer | Uint8Array;
31
+ mode: Exclude<ExtractionMode, 'template'>;
32
+ hint?: IExtractionBankHint;
33
+ pdf_filename?: string;
34
+ user_external_id?: string;
35
+ user_metadata?: Record<string, unknown>;
36
+ archive?: boolean;
37
+ force?: boolean;
38
+ improvementConsent?: boolean;
39
+ plan?: IExtractionPlan;
40
+ }
29
41
  export interface IExtractBulkBody {
30
42
  items: Array<{
31
43
  storage_file_id?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abyss-project/tools",
3
- "version": "2.15.0",
3
+ "version": "2.16.0",
4
4
  "description": "Core package to interact with Abyss-Project Tools",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -0,0 +1,55 @@
1
+ // Type-level compile test for the APPLICATION extract client (#581).
2
+ // No jest runner in this SDK package; compile guard only (mirrors
3
+ // probe-scan.application.api.test.ts). Run: npx tsc --noEmit, or `npm run build`.
4
+
5
+ import * as api from './extraction.application.api';
6
+ import type { IExtractApplicationBody } from '../types';
7
+
8
+ const _run: typeof api.runExtractionApplication = api.runExtractionApplication;
9
+ void _run;
10
+
11
+ type Body = Parameters<typeof api.runExtractionApplication>[1];
12
+ declare const pdf: Buffer;
13
+
14
+ // What the route accepts: a PDF, mode auto|hint, and the optional fields.
15
+ const _minimal: Body = { pdf, mode: 'auto' };
16
+ const _full: Body = {
17
+ pdf,
18
+ mode: 'hint',
19
+ hint: { bank: 'bnp' },
20
+ pdf_filename: 'invoice.pdf',
21
+ user_external_id: 'u-1',
22
+ user_metadata: { a: 1 },
23
+ archive: true,
24
+ force: false,
25
+ improvementConsent: true,
26
+ };
27
+ const _named: IExtractApplicationBody = _minimal;
28
+ void _minimal;
29
+ void _full;
30
+ void _named;
31
+
32
+ // What the route refuses with a 4xx must not compile.
33
+ // @ts-expect-error the route only accepts a multipart PDF
34
+ const _noPdf: Body = { mode: 'auto' };
35
+ // @ts-expect-error storage_file_id is refused by the application route
36
+ const _storage: Body = { pdf, mode: 'auto', storage_file_id: 'f' };
37
+ // @ts-expect-error template_id is refused by the application route
38
+ const _templateId: Body = { pdf, mode: 'auto', template_id: 't' };
39
+ // @ts-expect-error template is refused by the application route
40
+ const _template: Body = { pdf, mode: 'auto', template: {} };
41
+ // @ts-expect-error plan_preset_id is refused by the application route
42
+ const _preset: Body = { pdf, mode: 'auto', plan_preset_id: 'p' };
43
+ // @ts-expect-error mode template is refused by the application route
44
+ const _modeTemplate: Body = { pdf, mode: 'template' };
45
+ // @ts-expect-error the application route is synchronous only
46
+ const _processing: Body = { pdf, mode: 'auto', processing: 'queue' };
47
+ void _noPdf;
48
+ void _storage;
49
+ void _templateId;
50
+ void _template;
51
+ void _preset;
52
+ void _modeTemplate;
53
+ void _processing;
54
+
55
+ export {};
@@ -7,11 +7,13 @@
7
7
  // API key instead of a personal/org session.
8
8
  //
9
9
  // Reuses extraction.api.ts's `buildExtractMultipart` (the same global
10
- // `FormData` + `Blob` multipart body as the personal client) and every
11
- // request/response TYPE verbatim (`IExtractBody`, `IExtractSyncResponse`) —
12
- // never redefined here. There is NO scope query param: unlike the
13
- // personal/org route's `?organization_id=`, an application caller's scope is
14
- // entirely its `:applicationId` URL segment, resolved server-side by
10
+ // `FormData` + `Blob` multipart body as the personal client) and the
11
+ // response TYPE verbatim (`IExtractSyncResponse`) — never redefined here.
12
+ // The request body is `IExtractApplicationBody`, a narrower type than the
13
+ // personal client's `IExtractBody`: it types exactly what this route accepts
14
+ // (#581) — see extraction.request.ts. There is NO scope query param: unlike
15
+ // the personal/org route's `?organization_id=`, an application caller's scope
16
+ // is entirely its `:applicationId` URL segment, resolved server-side by
15
17
  // ApplicationMiddleware (round-trips to abyss-main).
16
18
  //
17
19
  // `authHeaderApplication` is kept LOCAL and unexported, same convention as the
@@ -23,7 +25,7 @@
23
25
  // ──────────────────────────────────────────────
24
26
 
25
27
  import { AbyssToolsCore, API_KEY_APPLICATION_HEADER } from '..';
26
- import type { IExtractBody } from '../types';
28
+ import type { IExtractApplicationBody } from '../types';
27
29
  import type { IExtractSyncResponse } from '../types';
28
30
  import { buildExtractMultipart, ExtractCallOptions } from './extraction.api';
29
31
 
@@ -38,18 +40,16 @@ function authHeaderApplication(applicationApiKey?: string): Record<string, strin
38
40
  * `body.pdf`, with `body.mode` `auto` or `hint`; `body.plan` (inline, single
39
41
  * pass, no OCR, no template pass) and `body.improvementConsent` travel as
40
42
  * multipart fields. The route refuses `storage_file_id`, `plan_preset_id`,
41
- * `template_id` and `template` with a 4xx. A body without `pdf` is sent as
42
- * JSON and never runs an extraction: the memory watchdog may answer 503 before
43
- * the route reads the body; past it, the route answers a 4xx — the
44
- * `storage_file_id` refusal when the body carries one, otherwise "Provide file
45
- * (multipart pdf)". `options` forwards a Stripe-style
43
+ * `template_id` and `template` with a 4xx, and any body without `pdf` answers
44
+ * "Provide file (multipart pdf)" — the memory watchdog may also answer 503
45
+ * before the route reads the body. `options` forwards a Stripe-style
46
46
  * `Idempotency-Key` header (24h replay window) when set — replayed only for
47
47
  * the IDENTICAL request; the same key sent with another document or another
48
48
  * body answers 422 `IDEMPOTENCY_KEY_REUSED` (see `ExtractCallOptions`).
49
49
  */
50
50
  export const runExtractionApplication = async (
51
51
  applicationId: string,
52
- body: IExtractBody,
52
+ body: IExtractApplicationBody,
53
53
  options: ExtractCallOptions = {},
54
54
  applicationApiKey?: string,
55
55
  ): Promise<IExtractSyncResponse> => {
@@ -59,23 +59,12 @@ export const runExtractionApplication = async (
59
59
  }
60
60
  const url = `extract/application/${applicationId}/extract`;
61
61
 
62
- if (body.pdf) {
63
- const form = buildExtractMultipart(body);
64
- return (
65
- await AbyssToolsCore.axios.post<IExtractSyncResponse>(url, form, {
66
- headers: { ...authHeaderApplication(applicationApiKey), ...extraHeaders },
67
- maxBodyLength: Infinity,
68
- maxContentLength: Infinity,
69
- })
70
- ).data;
71
- }
72
-
73
- // Strip `pdf` from the JSON body (only used for the multipart upload above).
74
- const jsonBody: Omit<IExtractBody, 'pdf'> = { ...body };
75
- delete (jsonBody as { pdf?: unknown }).pdf;
62
+ const form = buildExtractMultipart(body);
76
63
  return (
77
- await AbyssToolsCore.axios.post<IExtractSyncResponse>(url, jsonBody, {
64
+ await AbyssToolsCore.axios.post<IExtractSyncResponse>(url, form, {
78
65
  headers: { ...authHeaderApplication(applicationApiKey), ...extraHeaders },
66
+ maxBodyLength: Infinity,
67
+ maxContentLength: Infinity,
79
68
  })
80
69
  ).data;
81
70
  };
@@ -71,6 +71,28 @@ export interface IExtractBody {
71
71
  plan_preset_id?: string;
72
72
  }
73
73
 
74
+ /**
75
+ * Body of `POST /extract/application/:applicationId/extract` — exactly what
76
+ * that route accepts (extraction-extract-application.controller.ts): a
77
+ * multipart PDF, mode `auto` or `hint`, and the optional fields below. The
78
+ * route refuses storage_file_id, template_id, template, mode `template`,
79
+ * plan_preset_id and any body without a PDF (4xx), and is synchronous only,
80
+ * so none of those are expressible here (#581).
81
+ */
82
+ export interface IExtractApplicationBody {
83
+ pdf: Buffer | Uint8Array;
84
+ mode: Exclude<ExtractionMode, 'template'>;
85
+ hint?: IExtractionBankHint;
86
+ pdf_filename?: string;
87
+ user_external_id?: string;
88
+ user_metadata?: Record<string, unknown>;
89
+ archive?: boolean;
90
+ force?: boolean;
91
+ improvementConsent?: boolean;
92
+ /** Inline plan: single pass, no OCR provider, no template pass (checked server-side). */
93
+ plan?: IExtractionPlan;
94
+ }
95
+
74
96
  export interface IExtractBulkBody {
75
97
  items: Array<{
76
98
  storage_file_id?: string;