extractia-sdk 1.3.0 → 1.5.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 CHANGED
@@ -22,6 +22,7 @@ Works in Node.js ≥ 18 and modern browsers via the provided UMD build.
22
22
  - [AI Features](#ai-features)
23
23
  - [Exports](#exports)
24
24
  - [OCR Tools](#ocr-tools)
25
+ - [Execution History](#getocrtoolexecutionsoptions)
25
26
  - [Credits & Analytics](#credits--analytics)
26
27
  - [Sub-Users](#sub-users)
27
28
  6. [TypeScript](#typescript)
@@ -796,6 +797,74 @@ if (docType === "invoice") {
796
797
 
797
798
  ---
798
799
 
800
+ #### `getOcrToolExecutions(options?)`
801
+
802
+ Returns a paginated list of OCR tool execution history for the authenticated user.
803
+ Each record includes the original image (`imageBase64`), the AI answer, explanation, and run metadata.
804
+
805
+ > **Image data is included in every record.** Keep page sizes small when rendering thumbnails to avoid large payloads.
806
+
807
+ | Option | Type | Default | Description |
808
+ | -------- | -------- | ------- | -------------------------------------------------------- |
809
+ | `toolId` | `string` | — | Filter by tool ID. Omit to return executions for all tools |
810
+ | `page` | `number` | `0` | Zero-based page index |
811
+ | `size` | `number` | `20` | Page size — values above 50 are capped server-side |
812
+
813
+ ```js
814
+ // All executions (most recent first)
815
+ const history = await getOcrToolExecutions();
816
+ console.log(`${history.totalElements} total executions`);
817
+
818
+ for (const exec of history.content) {
819
+ console.log(exec.toolName, exec.answer, exec.status); // "Proof of Residence" "YES" "SUCCESS"
820
+ // exec.imageBase64 — the original image that was analyzed
821
+ // exec.createdAt — ISO 8601 UTC timestamp
822
+ }
823
+
824
+ // Filter by a specific tool
825
+ const residenceHistory = await getOcrToolExecutions({
826
+ toolId: "tool_residence_check",
827
+ page: 0,
828
+ size: 10,
829
+ });
830
+
831
+ // Check for failed executions
832
+ const failures = history.content.filter((e) => e.status === "FAILURE");
833
+ failures.forEach((e) => console.error(e.toolName, e.errorMessage));
834
+ ```
835
+
836
+ **Response shape:**
837
+
838
+ ```json
839
+ {
840
+ "content": [
841
+ {
842
+ "id": "exec_abc123",
843
+ "toolId": "tool_residence_check",
844
+ "toolName": "Proof of Residence",
845
+ "imageBase64": "...",
846
+ "mimeType": "image/jpeg",
847
+ "paramValues": null,
848
+ "answer": "YES",
849
+ "explanation": "Utility bill dated within 3 months.",
850
+ "booleanAnswer": true,
851
+ "status": "SUCCESS",
852
+ "processingTimeMs": 1240,
853
+ "createdAt": "2026-04-13T10:00:00Z"
854
+ }
855
+ ],
856
+ "totalElements": 42,
857
+ "totalPages": 3,
858
+ "size": 20,
859
+ "number": 0,
860
+ "first": true,
861
+ "last": false,
862
+ "empty": false
863
+ }
864
+ ```
865
+
866
+ ---
867
+
799
868
  ### Credits & Analytics
800
869
 
801
870
  #### `getCreditsBalance()`
@@ -833,8 +902,25 @@ history.content.forEach((entry) => {
833
902
 
834
903
  > Requires a **Pro or higher** plan. The plan determines the maximum number of sub-users allowed.
835
904
 
836
- Sub-users can log in to the web app and operate within the permissions you grant them.
837
- Available permissions: `"upload"` · `"view"` · `"template"` · `"settings"` · `"export"` · `"api"`
905
+ Sub-users can log in to the web app and operate within the permissions you grant them.
906
+
907
+ **Available permissions:**
908
+
909
+ | Permission | What it grants |
910
+ | -------------- | ---------------------------------------------------- |
911
+ | `"upload"` | Upload and process new documents |
912
+ | `"view"` | View all documents owned by the account |
913
+ | `"template"` | Create and edit form templates |
914
+ | `"settings"` | View and edit account settings |
915
+ | `"export"` | Export documents to CSV / Excel / JSON |
916
+ | `"api"` | Use the public API with their own API key |
917
+ | `"ocr_tools"` | Access the AI Agents / OCR Tools feature |
918
+ | `"gallery"` | Browse and clone templates from the public gallery |
919
+ | `"smart_scan"` | Use the Smart Scan camera capture flow |
920
+ | `"ia_agent"` | Use the IA Agent for intelligent document extraction |
921
+ | `"assistant"` | Use the built-in AI chatbot assistant |
922
+
923
+ **`allowedFormIds`** (optional): restrict which form templates the sub-user can access. Pass `null` or omit to grant access to all templates.
838
924
 
839
925
  ### Document History
840
926
 
@@ -862,13 +948,29 @@ const users = await getSubUsers();
862
948
  ```js
863
949
  import { createSubUser } from "extractia-sdk";
864
950
 
951
+ // Basic — access to all templates
865
952
  const sub = await createSubUser({
866
953
  username: "agent_carlos",
867
954
  password: "SecurePass1",
955
+ permissions: ["upload", "view", "ocr_tools"],
956
+ });
957
+
958
+ // Restricted to specific templates only
959
+ const restricted = await createSubUser({
960
+ username: "agent_maria",
961
+ password: "SecurePass2",
868
962
  permissions: ["upload", "view"],
963
+ allowedFormIds: ["tpl_invoices", "tpl_receipts"], // null = all templates
869
964
  });
870
965
  ```
871
966
 
967
+ | Parameter | Type | Required | Description |
968
+ | ---------------- | ---------- | -------- | --------------------------------------------------- |
969
+ | `username` | `string` | ✅ | Must not be an existing account email |
970
+ | `password` | `string` | ✅ | Must differ from the owner's password |
971
+ | `permissions` | `string[]` | ✅ | See permissions table above |
972
+ | `allowedFormIds` | `string[]` | — | Template IDs accessible to this sub-user (null = all) |
973
+
872
974
  **Error codes:**
873
975
  | Code | Reason |
874
976
  |------|--------|
@@ -876,16 +978,31 @@ const sub = await createSubUser({
876
978
  | `409` | Username already in use |
877
979
  | `400` | Missing fields or password matches the main account |
878
980
 
879
- ### Update Permissions or Password
981
+ ### Update Permissions, Template Access, or Password
880
982
 
881
- Only the fields you include are changed. Omit `password` to keep it unchanged.
983
+ Only the fields you include are changed. Omit any field to leave it unchanged.
882
984
 
883
985
  ```js
884
986
  import { updateSubUser } from "extractia-sdk";
885
987
 
988
+ // Change permissions
886
989
  await updateSubUser("agent_carlos", {
887
- permissions: ["upload", "view", "export"],
888
- // password: 'NewPass99', ← optional
990
+ permissions: ["upload", "view", "export", "ocr_tools"],
991
+ });
992
+
993
+ // Restrict to specific templates
994
+ await updateSubUser("agent_carlos", {
995
+ allowedFormIds: ["tpl_invoices"],
996
+ });
997
+
998
+ // Remove template restriction (grant access to all)
999
+ await updateSubUser("agent_carlos", {
1000
+ allowedFormIds: null,
1001
+ });
1002
+
1003
+ // Change password only
1004
+ await updateSubUser("agent_carlos", {
1005
+ password: "NewPass99",
889
1006
  });
890
1007
  ```
891
1008
 
@@ -914,15 +1031,36 @@ console.log(state.suspended); // true | false
914
1031
 
915
1032
  The SDK ships with a full `index.d.ts` declaration file — no `@types` package needed.
916
1033
 
1034
+ **Key exported types:**
1035
+
1036
+ | Type | Description |
1037
+ | --------------------- | -------------------------------------------------------- |
1038
+ | `FormTemplate` | A template with `id`, `label`, `fields`, `userId` |
1039
+ | `FormField` | A single field: `label`, `type`, `required`, `listLabel` |
1040
+ | `UserDocument` | A processed document with `rawJson`, `createdAt`, etc. |
1041
+ | `OcrToolConfig` | An OCR agent configuration |
1042
+ | `OcrRunResult` | Result of `runOcrTool`: `answer` + `explanation` |
1043
+ | `OcrToolExecution` | A single execution record from `getOcrToolExecutions` |
1044
+ | `OcrExecutionPage` | Paginated response of `OcrToolExecution` records |
1045
+ | `SubUser` | Sub-user with `username`, `permissions`, `allowedFormIds`, `suspended` |
1046
+ | `AppUserProfile` | User profile with quota, plan, and settings fields |
1047
+ | `DocumentAuditEntry` | An entry from `getDocumentHistory` |
1048
+ | `ExtractiaError` | Base error class with `status`, `code`, `userMessage` |
1049
+
917
1050
  ```ts
918
1051
  import {
919
1052
  setToken,
920
1053
  processImage,
921
1054
  runOcrTool,
1055
+ getOcrToolExecutions,
1056
+ createSubUser,
922
1057
  suggestFields,
923
1058
  exportDocumentsJson,
924
1059
  UserDocument,
925
1060
  OcrRunResult,
1061
+ OcrToolExecution,
1062
+ OcrExecutionPage,
1063
+ SubUser,
926
1064
  FormField,
927
1065
  TierError,
928
1066
  RateLimitError,
@@ -948,6 +1086,18 @@ async function classifyAndExtract(
948
1086
  // Extract with template
949
1087
  return processImage(templateId, base64);
950
1088
  }
1089
+
1090
+ // Typed execution history
1091
+ const page: OcrExecutionPage = await getOcrToolExecutions({ size: 5 });
1092
+ const recent: OcrToolExecution[] = page.content;
1093
+
1094
+ // Typed sub-user with allowedFormIds
1095
+ const sub: SubUser = await createSubUser({
1096
+ username: "agent_ts",
1097
+ password: "Secure1!",
1098
+ permissions: ["upload", "view", "ocr_tools"],
1099
+ allowedFormIds: ["tpl_invoices"],
1100
+ });
951
1101
  ```
952
1102
 
953
1103
  ---
@@ -968,6 +1118,13 @@ Purchase extra document packs or upgrade your plan from the dashboard to continu
968
1118
 
969
1119
  ## Changelog
970
1120
 
1121
+ ### v1.5.0
1122
+
1123
+ - **New:** `getOcrToolExecutions(opts?)` — paginated execution history for AI Agent runs, including the original image, answer, explanation, status, and processing time. Filterable by `toolId`.
1124
+ - **New:** `createSubUser` and `updateSubUser` now support `allowedFormIds` — restrict which form templates a sub-user can access (`null` = all templates).
1125
+ - **Expanded:** Sub-user permissions updated from 6 to 11: added `"ocr_tools"`, `"gallery"`, `"smart_scan"`, `"ia_agent"`, `"assistant"`.
1126
+ - **New TypeScript types:** `OcrToolExecution`, `OcrExecutionPage` interfaces; `SubUser` updated with `allowedFormIds` and all 11 permissions.
1127
+
971
1128
  ### v1.2.0
972
1129
 
973
1130
  - **New:** `getDocumentHistory(opts?)` — paginated log of all document processing events (successes and failures)