@abyss-project/tools 2.11.0 → 2.12.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 (38) hide show
  1. package/dist/api/extraction.api.d.ts +1 -2
  2. package/dist/api/extraction.api.js +82 -43
  3. package/dist/api/extraction.api.js.map +1 -1
  4. package/dist/api/index.d.ts +0 -1
  5. package/dist/api/index.js +0 -1
  6. package/dist/api/index.js.map +1 -1
  7. package/dist/api/probe-scan.api.d.ts +2 -9
  8. package/dist/api/probe-scan.api.js +16 -26
  9. package/dist/api/probe-scan.api.js.map +1 -1
  10. package/dist/api/probe-scan.api.test.js +10 -0
  11. package/dist/api/probe-scan.api.test.js.map +1 -1
  12. package/dist/api/probe-scan.application.api.js +2 -2
  13. package/dist/api/probe-scan.application.api.js.map +1 -1
  14. package/dist/api/probe-scan.application.api.test.js +4 -0
  15. package/dist/api/probe-scan.application.api.test.js.map +1 -1
  16. package/dist/index.d.ts +0 -4
  17. package/dist/index.js +0 -4
  18. package/dist/index.js.map +1 -1
  19. package/dist/types/enum/document-type.enum.d.ts +0 -1
  20. package/dist/types/enum/document-type.enum.js +0 -1
  21. package/dist/types/enum/document-type.enum.js.map +1 -1
  22. package/dist/types/interface/models/extraction.dto.d.ts +0 -10
  23. package/dist/types/interface/models/extraction.dto.js.map +1 -1
  24. package/package.json +4 -4
  25. package/src/api/extraction.api.ts +84 -64
  26. package/src/api/index.ts +0 -1
  27. package/src/api/probe-scan.api.test.ts +26 -0
  28. package/src/api/probe-scan.api.ts +66 -54
  29. package/src/api/probe-scan.application.api.test.ts +14 -0
  30. package/src/api/probe-scan.application.api.ts +5 -5
  31. package/src/index.ts +0 -17
  32. package/src/types/enum/document-type.enum.ts +0 -1
  33. package/src/types/interface/api/requests/probe-scan.request.ts +5 -1
  34. package/src/types/interface/models/extraction.dto.ts +0 -17
  35. package/dist/api/extraction.application.api.d.ts +0 -4
  36. package/dist/api/extraction.application.api.js +0 -30
  37. package/dist/api/extraction.application.api.js.map +0 -1
  38. package/src/api/extraction.application.api.ts +0 -79
@@ -1,79 +0,0 @@
1
- // ──────────────────────────────────────────────
2
- // AbyssExtract APPLICATION extract API — POST
3
- // /extract/application/:applicationId/extract. Mirrors
4
- // apps/api/src/api/controllers/extraction-extract-application.controller.ts
5
- // EXACTLY — the application counterpart of extraction.api.ts's `extractSync`,
6
- // for inter-service callers (e.g. AbyssBanking) authenticating with a project
7
- // API key instead of a personal/org session.
8
- //
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
15
- // ApplicationMiddleware (round-trips to abyss-main).
16
- //
17
- // `authHeaderApplication` is kept LOCAL and unexported, same convention as the
18
- // personal client's own `authHeader` — it sends `API_KEY_APPLICATION_HEADER`
19
- // (`abyss-api-key-application`) instead of the personal `abyss-api-key`.
20
- //
21
- // The endpoint is SYNCHRONOUS (the machine caller gets the extraction inline —
22
- // no queue), so the return is always the `IExtractSyncResponse` shape.
23
- // ──────────────────────────────────────────────
24
-
25
- import { AbyssToolsCore, API_KEY_APPLICATION_HEADER } from '..';
26
- import type { IExtractBody } from '../types';
27
- import type { IExtractSyncResponse } from '../types';
28
- import { buildExtractMultipart, ExtractCallOptions } from './extraction.api';
29
-
30
- function authHeaderApplication(applicationApiKey?: string): Record<string, string> {
31
- return applicationApiKey ? { [API_KEY_APPLICATION_HEADER]: applicationApiKey } : {};
32
- }
33
-
34
- /**
35
- * `POST /extract/application/:applicationId/extract` — run one synchronous
36
- * extraction OWNED by `applicationId` and BILLED to its resolved owning
37
- * organization. The route accepts only a multipart PDF upload: send
38
- * `body.pdf`, with `body.mode` `auto` or `hint`; `body.plan` (inline, single
39
- * pass, no OCR, no template pass) and `body.improvementConsent` travel as
40
- * 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
46
- * `Idempotency-Key` header (24h replay window) when set.
47
- */
48
- export const runExtractionApplication = async (
49
- applicationId: string,
50
- body: IExtractBody,
51
- options: ExtractCallOptions = {},
52
- applicationApiKey?: string,
53
- ): Promise<IExtractSyncResponse> => {
54
- const extraHeaders: Record<string, string> = {};
55
- if (options.idempotencyKey) {
56
- extraHeaders['Idempotency-Key'] = options.idempotencyKey;
57
- }
58
- const url = `extract/application/${applicationId}/extract`;
59
-
60
- if (body.pdf) {
61
- const form = buildExtractMultipart(body);
62
- return (
63
- await AbyssToolsCore.axios.post<IExtractSyncResponse>(url, form, {
64
- headers: { ...authHeaderApplication(applicationApiKey), ...extraHeaders },
65
- maxBodyLength: Infinity,
66
- maxContentLength: Infinity,
67
- })
68
- ).data;
69
- }
70
-
71
- // Strip `pdf` from the JSON body (only used for the multipart upload above).
72
- const jsonBody: Omit<IExtractBody, 'pdf'> = { ...body };
73
- delete (jsonBody as { pdf?: unknown }).pdf;
74
- return (
75
- await AbyssToolsCore.axios.post<IExtractSyncResponse>(url, jsonBody, {
76
- headers: { ...authHeaderApplication(applicationApiKey), ...extraHeaders },
77
- })
78
- ).data;
79
- };