extractia-sdk 1.1.0 → 1.2.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 +257 -58
- package/dist/extractia-sdk.browser.js +29 -9
- package/dist/extractia-sdk.browser.js.map +2 -2
- package/dist/extractia-sdk.cjs.js +66 -10
- package/dist/extractia-sdk.cjs.js.map +3 -3
- package/dist/extractia-sdk.esm.js +66 -10
- package/dist/extractia-sdk.esm.js.map +3 -3
- package/dist/index.d.ts +167 -3
- package/package.json +2 -1
- package/src/analytics.js +19 -0
- package/src/apiClient.js +46 -46
- package/src/browser-entry.js +5 -5
- package/src/documents.js +14 -6
- package/src/index.d.ts +167 -3
- package/src/index.js +3 -0
- package/src/ocrTools.js +26 -7
- package/src/subusers.js +85 -0
package/dist/index.d.ts
CHANGED
|
@@ -81,12 +81,45 @@ export interface AppUserProfile {
|
|
|
81
81
|
webhook?: string | null;
|
|
82
82
|
/** Number of form templates owned. */
|
|
83
83
|
formTemplatesCount?: number;
|
|
84
|
-
/** Total documents processed. */
|
|
84
|
+
/** Total documents processed (lifetime). */
|
|
85
85
|
documentsCount?: number;
|
|
86
|
+
/** Documents remaining in the current billing cycle (plan quota). */
|
|
87
|
+
documentsAvailableThisMonth?: number;
|
|
88
|
+
/** Extra/add-on documents available (purchased separately). */
|
|
89
|
+
extraDocsAvailable?: number;
|
|
86
90
|
tier?: object;
|
|
87
91
|
subscription?: object;
|
|
88
92
|
}
|
|
89
93
|
|
|
94
|
+
/** A single document processing audit entry (upload history). */
|
|
95
|
+
export interface DocumentAuditEntry {
|
|
96
|
+
id?: string;
|
|
97
|
+
userId: string;
|
|
98
|
+
templateId?: string | null;
|
|
99
|
+
templateName?: string | null;
|
|
100
|
+
/** "SUCCESS" or "FAILURE". */
|
|
101
|
+
status: string;
|
|
102
|
+
uploadDate: string;
|
|
103
|
+
processingTimeMs?: number;
|
|
104
|
+
/** Number of pages processed. */
|
|
105
|
+
pages?: number;
|
|
106
|
+
/** Number of template fields. */
|
|
107
|
+
fields?: number;
|
|
108
|
+
errorMessage?: string | null;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** A sub-user belonging to an account. */
|
|
112
|
+
export interface SubUser {
|
|
113
|
+
username: string;
|
|
114
|
+
/** Granted permission strings (e.g. "upload", "view", "template", "settings", "export", "api"). */
|
|
115
|
+
permissions: string[];
|
|
116
|
+
/** Whether the sub-user is currently suspended. */
|
|
117
|
+
suspended: boolean;
|
|
118
|
+
/** Last known geographic location ("lat,lng" format). */
|
|
119
|
+
lastKnownLocation?: string | null;
|
|
120
|
+
lastLocationAt?: string | null;
|
|
121
|
+
}
|
|
122
|
+
|
|
90
123
|
/** AI credit balance. */
|
|
91
124
|
export interface CreditsBalance {
|
|
92
125
|
monthlyBalance: number;
|
|
@@ -117,7 +150,10 @@ export interface OcrToolConfig {
|
|
|
117
150
|
id?: string;
|
|
118
151
|
/** Human-friendly display name (e.g. "Proof of Residence Check"). */
|
|
119
152
|
name: string;
|
|
120
|
-
/**
|
|
153
|
+
/**
|
|
154
|
+
* Natural-language instruction evaluated against the document image. Max 3 000 characters
|
|
155
|
+
* (after parameter substitution). May contain {{?1}}, {{?2}}, … placeholders.
|
|
156
|
+
*/
|
|
121
157
|
prompt: string;
|
|
122
158
|
/** Expected output shape. */
|
|
123
159
|
outputType: OcrOutputType;
|
|
@@ -126,9 +162,38 @@ export interface OcrToolConfig {
|
|
|
126
162
|
* List of possible labels the AI must pick from.
|
|
127
163
|
*/
|
|
128
164
|
labels?: string[];
|
|
165
|
+
/**
|
|
166
|
+
* Dynamic parameter definitions for {{?N}} placeholders in `prompt`.
|
|
167
|
+
* At run time the caller supplies a value for each placeholder via `runOcrTool` `options.params`.
|
|
168
|
+
*/
|
|
169
|
+
parameterDefinitions?: OcrParameterDefinition[];
|
|
129
170
|
createdAt?: string;
|
|
130
171
|
}
|
|
131
172
|
|
|
173
|
+
/** Configuration for a single dynamic {{?N}} placeholder in an OCR tool prompt. */
|
|
174
|
+
export interface OcrParameterDefinition {
|
|
175
|
+
/** 1-based index matching the {{?N}} placeholder in the prompt. */
|
|
176
|
+
key: number;
|
|
177
|
+
/** Human-readable label shown in the UI and used in validation error messages. */
|
|
178
|
+
label: string;
|
|
179
|
+
/** Optional hint text displayed to the user when filling in this parameter. */
|
|
180
|
+
description?: string;
|
|
181
|
+
/**
|
|
182
|
+
* Maximum character count for this parameter's value (1–500, default 200).
|
|
183
|
+
* Affects the total substituted prompt length limit of 3 000 characters.
|
|
184
|
+
*/
|
|
185
|
+
maxChars?: number;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** Options accepted by {@link runOcrTool}. */
|
|
189
|
+
export interface OcrRunOptions {
|
|
190
|
+
/**
|
|
191
|
+
* Values for {{?N}} placeholders, keyed by the string form of the placeholder index (e.g. `"1"`, `"2"`).
|
|
192
|
+
* Each value must not exceed the parameter's `maxChars` limit.
|
|
193
|
+
*/
|
|
194
|
+
params?: Record<string, string>;
|
|
195
|
+
}
|
|
196
|
+
|
|
132
197
|
/** Result returned after running an OCR tool. */
|
|
133
198
|
export interface OcrRunResult {
|
|
134
199
|
/** The AI's answer (e.g. "YES", "invoice", or free-form text). */
|
|
@@ -484,6 +549,27 @@ export function getCreditsHistory(options?: {
|
|
|
484
549
|
totalElements: number;
|
|
485
550
|
}>;
|
|
486
551
|
|
|
552
|
+
/**
|
|
553
|
+
* Returns a paginated history of document processing events
|
|
554
|
+
* (uploads, OCR tool runs, both successes and failures).
|
|
555
|
+
*
|
|
556
|
+
* @param options
|
|
557
|
+
* @param [options.page=0] Zero-based page index.
|
|
558
|
+
* @param [options.size=20] Page size (max 100).
|
|
559
|
+
*
|
|
560
|
+
* @example
|
|
561
|
+
* const history = await getDocumentHistory({ size: 50 });
|
|
562
|
+
* history.content.forEach(e => console.log(e.templateName, e.status, e.uploadDate));
|
|
563
|
+
*/
|
|
564
|
+
export function getDocumentHistory(options?: {
|
|
565
|
+
page?: number;
|
|
566
|
+
size?: number;
|
|
567
|
+
}): Promise<{
|
|
568
|
+
content: DocumentAuditEntry[];
|
|
569
|
+
totalPages: number;
|
|
570
|
+
totalElements: number;
|
|
571
|
+
}>;
|
|
572
|
+
|
|
487
573
|
// ─── OCR Tools ────────────────────────────────────────────────────────────────
|
|
488
574
|
|
|
489
575
|
/**
|
|
@@ -526,14 +612,85 @@ export function deleteOcrTool(id: string): Promise<void>;
|
|
|
526
612
|
* The image may include a data-URL prefix (e.g. `data:image/jpeg;base64,...`)
|
|
527
613
|
* or be a plain base64 string. Max image size is 5 MB.
|
|
528
614
|
*
|
|
615
|
+
* Each run deducts **1 document credit** from the user's quota plus AI credits
|
|
616
|
+
* based on token usage (`ceil(totalTokens / 1000)` credits).
|
|
617
|
+
* The AI responds in the same language as the prompt / parameter values.
|
|
618
|
+
*
|
|
529
619
|
* @param id OCR tool ID.
|
|
530
620
|
* @param base64Image Base64-encoded image.
|
|
621
|
+
* @param options Optional run options, including dynamic parameter values.
|
|
622
|
+
*
|
|
623
|
+
* @throws {ExtractiaError} 400 — missing/invalid parameter or prompt too long after substitution.
|
|
624
|
+
* @throws {TierError} 402 — document quota or AI credits exhausted.
|
|
531
625
|
*
|
|
532
626
|
* @example
|
|
533
627
|
* const result = await runOcrTool('tool_789', base64String);
|
|
534
628
|
* if (result.answer === 'YES') console.log('Proof of residence confirmed');
|
|
629
|
+
*
|
|
630
|
+
* // With dynamic parameters:
|
|
631
|
+
* const result = await runOcrTool('ownership_tool', base64String, {
|
|
632
|
+
* params: { "1": "123 Main St", "2": "Jane Doe" }
|
|
633
|
+
* });
|
|
634
|
+
*/
|
|
635
|
+
export function runOcrTool(id: string, base64Image: string, options?: OcrRunOptions): Promise<OcrRunResult>;
|
|
636
|
+
|
|
637
|
+
// ─── Sub-Users ────────────────────────────────────────────────────────────────
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* Returns all sub-users for the authenticated account.
|
|
641
|
+
* Only available on plans that support sub-users (Pro and above).
|
|
642
|
+
*/
|
|
643
|
+
export function getSubUsers(): Promise<SubUser[]>;
|
|
644
|
+
|
|
645
|
+
/**
|
|
646
|
+
* Creates a new sub-user.
|
|
647
|
+
*
|
|
648
|
+
* Available permissions: `"upload"`, `"view"`, `"template"`, `"settings"`, `"export"`, `"api"`.
|
|
649
|
+
*
|
|
650
|
+
* @throws {ForbiddenError} 403 if the plan does not support sub-users or the limit is reached.
|
|
651
|
+
* @throws {ExtractiaError} 409 if the username is already taken.
|
|
652
|
+
*
|
|
653
|
+
* @example
|
|
654
|
+
* await createSubUser({
|
|
655
|
+
* username: 'agent_bob',
|
|
656
|
+
* password: 'SecurePass1',
|
|
657
|
+
* permissions: ['upload', 'view'],
|
|
658
|
+
* });
|
|
659
|
+
*/
|
|
660
|
+
export function createSubUser(subUser: {
|
|
661
|
+
username: string;
|
|
662
|
+
password: string;
|
|
663
|
+
permissions: string[];
|
|
664
|
+
}): Promise<{ username: string; permissions: string[] }>;
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* Deletes a sub-user by username.
|
|
668
|
+
* @param username The sub-user's username.
|
|
669
|
+
* @throws {NotFoundError} 404 if the sub-user does not exist.
|
|
670
|
+
*/
|
|
671
|
+
export function deleteSubUser(username: string): Promise<{ deleted: string }>;
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
* Updates the permissions and/or password of a sub-user.
|
|
675
|
+
* Only the provided fields are changed.
|
|
676
|
+
*
|
|
677
|
+
* @param username The sub-user's username.
|
|
678
|
+
* @param updates Fields to update.
|
|
679
|
+
* @throws {NotFoundError} 404 if the sub-user does not exist.
|
|
680
|
+
*/
|
|
681
|
+
export function updateSubUser(
|
|
682
|
+
username: string,
|
|
683
|
+
updates: { permissions?: string[]; password?: string }
|
|
684
|
+
): Promise<{ username: string; updated: boolean }>;
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* Toggles the suspended state of a sub-user.
|
|
688
|
+
* A suspended sub-user cannot log in until unsuspended.
|
|
689
|
+
*
|
|
690
|
+
* @param username The sub-user's username.
|
|
691
|
+
* @throws {NotFoundError} 404 if the sub-user does not exist.
|
|
535
692
|
*/
|
|
536
|
-
export function
|
|
693
|
+
export function toggleSuspendSubUser(username: string): Promise<{ username: string; suspended: boolean }>;
|
|
537
694
|
|
|
538
695
|
// ─── Default export ───────────────────────────────────────────────────────────
|
|
539
696
|
|
|
@@ -571,12 +728,19 @@ declare const extractia: {
|
|
|
571
728
|
// Analytics
|
|
572
729
|
getCreditsBalance: typeof getCreditsBalance;
|
|
573
730
|
getCreditsHistory: typeof getCreditsHistory;
|
|
731
|
+
getDocumentHistory: typeof getDocumentHistory;
|
|
574
732
|
// OCR Tools
|
|
575
733
|
getOcrTools: typeof getOcrTools;
|
|
576
734
|
createOcrTool: typeof createOcrTool;
|
|
577
735
|
updateOcrTool: typeof updateOcrTool;
|
|
578
736
|
deleteOcrTool: typeof deleteOcrTool;
|
|
579
737
|
runOcrTool: typeof runOcrTool;
|
|
738
|
+
// Sub-users
|
|
739
|
+
getSubUsers: typeof getSubUsers;
|
|
740
|
+
createSubUser: typeof createSubUser;
|
|
741
|
+
deleteSubUser: typeof deleteSubUser;
|
|
742
|
+
updateSubUser: typeof updateSubUser;
|
|
743
|
+
toggleSuspendSubUser: typeof toggleSuspendSubUser;
|
|
580
744
|
};
|
|
581
745
|
|
|
582
746
|
export default extractia;
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "extractia-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "JavaScript SDK for the ExtractIA API — document extraction, OCR tools, AI summaries, templates & more",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"author": "ExtractIA Team",
|
|
6
7
|
"license": "MIT",
|
|
7
8
|
"keywords": [
|
package/src/analytics.js
CHANGED
|
@@ -25,3 +25,22 @@ export async function getCreditsHistory({ page = 0, size = 20 } = {}) {
|
|
|
25
25
|
});
|
|
26
26
|
return res.data;
|
|
27
27
|
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Returns a paginated history of document processing events (uploads, OCR tool runs, etc.)
|
|
31
|
+
* for the authenticated user.
|
|
32
|
+
*
|
|
33
|
+
* Each entry includes: templateId, templateName, status (SUCCESS | FAILURE),
|
|
34
|
+
* uploadDate, processingTimeMs, pages, fields, and an optional errorMessage.
|
|
35
|
+
*
|
|
36
|
+
* @param {Object} [options]
|
|
37
|
+
* @param {number} [options.page=0] - Zero-based page index.
|
|
38
|
+
* @param {number} [options.size=20] - Page size (max 100).
|
|
39
|
+
* @returns {Promise<Object>} Spring Page object with `content` array and pagination info.
|
|
40
|
+
*/
|
|
41
|
+
export async function getDocumentHistory({ page = 0, size = 20 } = {}) {
|
|
42
|
+
const res = await api.get("/me/documents/history", {
|
|
43
|
+
params: { page, size: Math.min(size, 100) },
|
|
44
|
+
});
|
|
45
|
+
return res.data;
|
|
46
|
+
}
|
package/src/apiClient.js
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
import { mapAxiosError } from "./errors.js";
|
|
3
|
-
|
|
4
|
-
let token = null;
|
|
5
|
-
|
|
6
|
-
const DEFAULT_BASE_URL = "https://
|
|
7
|
-
|
|
8
|
-
const api = axios.create({
|
|
9
|
-
baseURL: DEFAULT_BASE_URL,
|
|
10
|
-
timeout: 60000, // 60s — AI processing can take 10–30s
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
api.interceptors.request.use((config) => {
|
|
14
|
-
if (!token) {
|
|
15
|
-
throw new Error(
|
|
16
|
-
"API token is required. Call setToken(yourApiToken) before making requests.",
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
config.headers.Authorization = `Bearer ${token}`;
|
|
20
|
-
return config;
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
api.interceptors.response.use(
|
|
24
|
-
(response) => response,
|
|
25
|
-
(err) => Promise.reject(mapAxiosError(err)),
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Sets the API token used for all subsequent requests.
|
|
30
|
-
* Must be called before any SDK method.
|
|
31
|
-
* @param {string} newToken - Your Extractia API token.
|
|
32
|
-
*/
|
|
33
|
-
export function setToken(newToken) {
|
|
34
|
-
token = newToken;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Configures SDK options.
|
|
39
|
-
* @param {object} opts
|
|
40
|
-
* @param {string} [opts.baseURL] - Override the default API base URL.
|
|
41
|
-
*/
|
|
42
|
-
export function configure({ baseURL } = {}) {
|
|
43
|
-
if (baseURL) api.defaults.baseURL = baseURL;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export default api;
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { mapAxiosError } from "./errors.js";
|
|
3
|
+
|
|
4
|
+
let token = null;
|
|
5
|
+
|
|
6
|
+
const DEFAULT_BASE_URL = "https://api.extractia.info/api/public";
|
|
7
|
+
|
|
8
|
+
const api = axios.create({
|
|
9
|
+
baseURL: DEFAULT_BASE_URL,
|
|
10
|
+
timeout: 60000, // 60s — AI processing can take 10–30s
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
api.interceptors.request.use((config) => {
|
|
14
|
+
if (!token) {
|
|
15
|
+
throw new Error(
|
|
16
|
+
"API token is required. Call setToken(yourApiToken) before making requests.",
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
config.headers.Authorization = `Bearer ${token}`;
|
|
20
|
+
return config;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
api.interceptors.response.use(
|
|
24
|
+
(response) => response,
|
|
25
|
+
(err) => Promise.reject(mapAxiosError(err)),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Sets the API token used for all subsequent requests.
|
|
30
|
+
* Must be called before any SDK method.
|
|
31
|
+
* @param {string} newToken - Your Extractia API token.
|
|
32
|
+
*/
|
|
33
|
+
export function setToken(newToken) {
|
|
34
|
+
token = newToken;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Configures SDK options.
|
|
39
|
+
* @param {object} opts
|
|
40
|
+
* @param {string} [opts.baseURL] - Override the default API base URL.
|
|
41
|
+
*/
|
|
42
|
+
export function configure({ baseURL } = {}) {
|
|
43
|
+
if (baseURL) api.defaults.baseURL = baseURL;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default api;
|
package/src/browser-entry.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as auth from
|
|
2
|
-
import * as templates from
|
|
3
|
-
import * as documents from
|
|
4
|
-
import * as analytics from
|
|
5
|
-
import * as ocrTools from
|
|
1
|
+
import * as auth from "./auth.js";
|
|
2
|
+
import * as templates from "./templates.js";
|
|
3
|
+
import * as documents from "./documents.js";
|
|
4
|
+
import * as analytics from "./analytics.js";
|
|
5
|
+
import * as ocrTools from "./ocrTools.js";
|
|
6
6
|
|
|
7
7
|
const extractia = {
|
|
8
8
|
...auth,
|
package/src/documents.js
CHANGED
|
@@ -33,7 +33,9 @@ export async function getDocumentsByTemplateId(templateId, options = {}) {
|
|
|
33
33
|
*/
|
|
34
34
|
export async function getDocumentById(templateId, docId, options = {}) {
|
|
35
35
|
const params = { includeImage: options.includeImage ? 1 : 0 };
|
|
36
|
-
const res = await api.get(`/templates/${templateId}/documents/${docId}`, {
|
|
36
|
+
const res = await api.get(`/templates/${templateId}/documents/${docId}`, {
|
|
37
|
+
params,
|
|
38
|
+
});
|
|
37
39
|
return res.data;
|
|
38
40
|
}
|
|
39
41
|
|
|
@@ -44,7 +46,9 @@ export async function getDocumentById(templateId, docId, options = {}) {
|
|
|
44
46
|
* @returns {Promise<Object[]>} Array of document projection objects.
|
|
45
47
|
*/
|
|
46
48
|
export async function getRecentDocuments(size = 10) {
|
|
47
|
-
const res = await api.get("/documents/recent", {
|
|
49
|
+
const res = await api.get("/documents/recent", {
|
|
50
|
+
params: { size: Math.min(size, 50) },
|
|
51
|
+
});
|
|
48
52
|
return res.data;
|
|
49
53
|
}
|
|
50
54
|
|
|
@@ -67,7 +71,9 @@ export async function deleteDocument(documentId) {
|
|
|
67
71
|
* @returns {Promise<Object>} The created UserDocument with extracted JSON.
|
|
68
72
|
*/
|
|
69
73
|
export async function processImage(templateId, base64Image) {
|
|
70
|
-
const res = await api.post(`/templates/${templateId}/process`, {
|
|
74
|
+
const res = await api.post(`/templates/${templateId}/process`, {
|
|
75
|
+
image: base64Image,
|
|
76
|
+
});
|
|
71
77
|
return res.data;
|
|
72
78
|
}
|
|
73
79
|
|
|
@@ -80,7 +86,9 @@ export async function processImage(templateId, base64Image) {
|
|
|
80
86
|
* @returns {Promise<Object>} The created UserDocument with merged extracted JSON.
|
|
81
87
|
*/
|
|
82
88
|
export async function processImagesMultipage(templateId, base64ImagesArray) {
|
|
83
|
-
const res = await api.post(`/templates/${templateId}/process-multipage`, {
|
|
89
|
+
const res = await api.post(`/templates/${templateId}/process-multipage`, {
|
|
90
|
+
images: base64ImagesArray,
|
|
91
|
+
});
|
|
84
92
|
return res.data;
|
|
85
93
|
}
|
|
86
94
|
|
|
@@ -163,7 +171,8 @@ export async function bulkPreconform(ids) {
|
|
|
163
171
|
*/
|
|
164
172
|
export async function exportDocumentsCsv(templateId, options = {}) {
|
|
165
173
|
const params = {};
|
|
166
|
-
if (options.fields && options.fields.length > 0)
|
|
174
|
+
if (options.fields && options.fields.length > 0)
|
|
175
|
+
params.fields = options.fields.join(",");
|
|
167
176
|
const res = await api.get(`/templates/${templateId}/documents/export/csv`, {
|
|
168
177
|
params,
|
|
169
178
|
responseType: "text",
|
|
@@ -184,4 +193,3 @@ export async function exportDocumentsJson(templateId) {
|
|
|
184
193
|
const res = await api.get(`/templates/${templateId}/documents/export/json`);
|
|
185
194
|
return res.data;
|
|
186
195
|
}
|
|
187
|
-
|
package/src/index.d.ts
CHANGED
|
@@ -81,12 +81,45 @@ export interface AppUserProfile {
|
|
|
81
81
|
webhook?: string | null;
|
|
82
82
|
/** Number of form templates owned. */
|
|
83
83
|
formTemplatesCount?: number;
|
|
84
|
-
/** Total documents processed. */
|
|
84
|
+
/** Total documents processed (lifetime). */
|
|
85
85
|
documentsCount?: number;
|
|
86
|
+
/** Documents remaining in the current billing cycle (plan quota). */
|
|
87
|
+
documentsAvailableThisMonth?: number;
|
|
88
|
+
/** Extra/add-on documents available (purchased separately). */
|
|
89
|
+
extraDocsAvailable?: number;
|
|
86
90
|
tier?: object;
|
|
87
91
|
subscription?: object;
|
|
88
92
|
}
|
|
89
93
|
|
|
94
|
+
/** A single document processing audit entry (upload history). */
|
|
95
|
+
export interface DocumentAuditEntry {
|
|
96
|
+
id?: string;
|
|
97
|
+
userId: string;
|
|
98
|
+
templateId?: string | null;
|
|
99
|
+
templateName?: string | null;
|
|
100
|
+
/** "SUCCESS" or "FAILURE". */
|
|
101
|
+
status: string;
|
|
102
|
+
uploadDate: string;
|
|
103
|
+
processingTimeMs?: number;
|
|
104
|
+
/** Number of pages processed. */
|
|
105
|
+
pages?: number;
|
|
106
|
+
/** Number of template fields. */
|
|
107
|
+
fields?: number;
|
|
108
|
+
errorMessage?: string | null;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** A sub-user belonging to an account. */
|
|
112
|
+
export interface SubUser {
|
|
113
|
+
username: string;
|
|
114
|
+
/** Granted permission strings (e.g. "upload", "view", "template", "settings", "export", "api"). */
|
|
115
|
+
permissions: string[];
|
|
116
|
+
/** Whether the sub-user is currently suspended. */
|
|
117
|
+
suspended: boolean;
|
|
118
|
+
/** Last known geographic location ("lat,lng" format). */
|
|
119
|
+
lastKnownLocation?: string | null;
|
|
120
|
+
lastLocationAt?: string | null;
|
|
121
|
+
}
|
|
122
|
+
|
|
90
123
|
/** AI credit balance. */
|
|
91
124
|
export interface CreditsBalance {
|
|
92
125
|
monthlyBalance: number;
|
|
@@ -117,7 +150,10 @@ export interface OcrToolConfig {
|
|
|
117
150
|
id?: string;
|
|
118
151
|
/** Human-friendly display name (e.g. "Proof of Residence Check"). */
|
|
119
152
|
name: string;
|
|
120
|
-
/**
|
|
153
|
+
/**
|
|
154
|
+
* Natural-language instruction evaluated against the document image. Max 3 000 characters
|
|
155
|
+
* (after parameter substitution). May contain {{?1}}, {{?2}}, … placeholders.
|
|
156
|
+
*/
|
|
121
157
|
prompt: string;
|
|
122
158
|
/** Expected output shape. */
|
|
123
159
|
outputType: OcrOutputType;
|
|
@@ -126,9 +162,38 @@ export interface OcrToolConfig {
|
|
|
126
162
|
* List of possible labels the AI must pick from.
|
|
127
163
|
*/
|
|
128
164
|
labels?: string[];
|
|
165
|
+
/**
|
|
166
|
+
* Dynamic parameter definitions for {{?N}} placeholders in `prompt`.
|
|
167
|
+
* At run time the caller supplies a value for each placeholder via `runOcrTool` `options.params`.
|
|
168
|
+
*/
|
|
169
|
+
parameterDefinitions?: OcrParameterDefinition[];
|
|
129
170
|
createdAt?: string;
|
|
130
171
|
}
|
|
131
172
|
|
|
173
|
+
/** Configuration for a single dynamic {{?N}} placeholder in an OCR tool prompt. */
|
|
174
|
+
export interface OcrParameterDefinition {
|
|
175
|
+
/** 1-based index matching the {{?N}} placeholder in the prompt. */
|
|
176
|
+
key: number;
|
|
177
|
+
/** Human-readable label shown in the UI and used in validation error messages. */
|
|
178
|
+
label: string;
|
|
179
|
+
/** Optional hint text displayed to the user when filling in this parameter. */
|
|
180
|
+
description?: string;
|
|
181
|
+
/**
|
|
182
|
+
* Maximum character count for this parameter's value (1–500, default 200).
|
|
183
|
+
* Affects the total substituted prompt length limit of 3 000 characters.
|
|
184
|
+
*/
|
|
185
|
+
maxChars?: number;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** Options accepted by {@link runOcrTool}. */
|
|
189
|
+
export interface OcrRunOptions {
|
|
190
|
+
/**
|
|
191
|
+
* Values for {{?N}} placeholders, keyed by the string form of the placeholder index (e.g. `"1"`, `"2"`).
|
|
192
|
+
* Each value must not exceed the parameter's `maxChars` limit.
|
|
193
|
+
*/
|
|
194
|
+
params?: Record<string, string>;
|
|
195
|
+
}
|
|
196
|
+
|
|
132
197
|
/** Result returned after running an OCR tool. */
|
|
133
198
|
export interface OcrRunResult {
|
|
134
199
|
/** The AI's answer (e.g. "YES", "invoice", or free-form text). */
|
|
@@ -484,6 +549,27 @@ export function getCreditsHistory(options?: {
|
|
|
484
549
|
totalElements: number;
|
|
485
550
|
}>;
|
|
486
551
|
|
|
552
|
+
/**
|
|
553
|
+
* Returns a paginated history of document processing events
|
|
554
|
+
* (uploads, OCR tool runs, both successes and failures).
|
|
555
|
+
*
|
|
556
|
+
* @param options
|
|
557
|
+
* @param [options.page=0] Zero-based page index.
|
|
558
|
+
* @param [options.size=20] Page size (max 100).
|
|
559
|
+
*
|
|
560
|
+
* @example
|
|
561
|
+
* const history = await getDocumentHistory({ size: 50 });
|
|
562
|
+
* history.content.forEach(e => console.log(e.templateName, e.status, e.uploadDate));
|
|
563
|
+
*/
|
|
564
|
+
export function getDocumentHistory(options?: {
|
|
565
|
+
page?: number;
|
|
566
|
+
size?: number;
|
|
567
|
+
}): Promise<{
|
|
568
|
+
content: DocumentAuditEntry[];
|
|
569
|
+
totalPages: number;
|
|
570
|
+
totalElements: number;
|
|
571
|
+
}>;
|
|
572
|
+
|
|
487
573
|
// ─── OCR Tools ────────────────────────────────────────────────────────────────
|
|
488
574
|
|
|
489
575
|
/**
|
|
@@ -526,14 +612,85 @@ export function deleteOcrTool(id: string): Promise<void>;
|
|
|
526
612
|
* The image may include a data-URL prefix (e.g. `data:image/jpeg;base64,...`)
|
|
527
613
|
* or be a plain base64 string. Max image size is 5 MB.
|
|
528
614
|
*
|
|
615
|
+
* Each run deducts **1 document credit** from the user's quota plus AI credits
|
|
616
|
+
* based on token usage (`ceil(totalTokens / 1000)` credits).
|
|
617
|
+
* The AI responds in the same language as the prompt / parameter values.
|
|
618
|
+
*
|
|
529
619
|
* @param id OCR tool ID.
|
|
530
620
|
* @param base64Image Base64-encoded image.
|
|
621
|
+
* @param options Optional run options, including dynamic parameter values.
|
|
622
|
+
*
|
|
623
|
+
* @throws {ExtractiaError} 400 — missing/invalid parameter or prompt too long after substitution.
|
|
624
|
+
* @throws {TierError} 402 — document quota or AI credits exhausted.
|
|
531
625
|
*
|
|
532
626
|
* @example
|
|
533
627
|
* const result = await runOcrTool('tool_789', base64String);
|
|
534
628
|
* if (result.answer === 'YES') console.log('Proof of residence confirmed');
|
|
629
|
+
*
|
|
630
|
+
* // With dynamic parameters:
|
|
631
|
+
* const result = await runOcrTool('ownership_tool', base64String, {
|
|
632
|
+
* params: { "1": "123 Main St", "2": "Jane Doe" }
|
|
633
|
+
* });
|
|
634
|
+
*/
|
|
635
|
+
export function runOcrTool(id: string, base64Image: string, options?: OcrRunOptions): Promise<OcrRunResult>;
|
|
636
|
+
|
|
637
|
+
// ─── Sub-Users ────────────────────────────────────────────────────────────────
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* Returns all sub-users for the authenticated account.
|
|
641
|
+
* Only available on plans that support sub-users (Pro and above).
|
|
642
|
+
*/
|
|
643
|
+
export function getSubUsers(): Promise<SubUser[]>;
|
|
644
|
+
|
|
645
|
+
/**
|
|
646
|
+
* Creates a new sub-user.
|
|
647
|
+
*
|
|
648
|
+
* Available permissions: `"upload"`, `"view"`, `"template"`, `"settings"`, `"export"`, `"api"`.
|
|
649
|
+
*
|
|
650
|
+
* @throws {ForbiddenError} 403 if the plan does not support sub-users or the limit is reached.
|
|
651
|
+
* @throws {ExtractiaError} 409 if the username is already taken.
|
|
652
|
+
*
|
|
653
|
+
* @example
|
|
654
|
+
* await createSubUser({
|
|
655
|
+
* username: 'agent_bob',
|
|
656
|
+
* password: 'SecurePass1',
|
|
657
|
+
* permissions: ['upload', 'view'],
|
|
658
|
+
* });
|
|
659
|
+
*/
|
|
660
|
+
export function createSubUser(subUser: {
|
|
661
|
+
username: string;
|
|
662
|
+
password: string;
|
|
663
|
+
permissions: string[];
|
|
664
|
+
}): Promise<{ username: string; permissions: string[] }>;
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* Deletes a sub-user by username.
|
|
668
|
+
* @param username The sub-user's username.
|
|
669
|
+
* @throws {NotFoundError} 404 if the sub-user does not exist.
|
|
670
|
+
*/
|
|
671
|
+
export function deleteSubUser(username: string): Promise<{ deleted: string }>;
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
* Updates the permissions and/or password of a sub-user.
|
|
675
|
+
* Only the provided fields are changed.
|
|
676
|
+
*
|
|
677
|
+
* @param username The sub-user's username.
|
|
678
|
+
* @param updates Fields to update.
|
|
679
|
+
* @throws {NotFoundError} 404 if the sub-user does not exist.
|
|
680
|
+
*/
|
|
681
|
+
export function updateSubUser(
|
|
682
|
+
username: string,
|
|
683
|
+
updates: { permissions?: string[]; password?: string }
|
|
684
|
+
): Promise<{ username: string; updated: boolean }>;
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* Toggles the suspended state of a sub-user.
|
|
688
|
+
* A suspended sub-user cannot log in until unsuspended.
|
|
689
|
+
*
|
|
690
|
+
* @param username The sub-user's username.
|
|
691
|
+
* @throws {NotFoundError} 404 if the sub-user does not exist.
|
|
535
692
|
*/
|
|
536
|
-
export function
|
|
693
|
+
export function toggleSuspendSubUser(username: string): Promise<{ username: string; suspended: boolean }>;
|
|
537
694
|
|
|
538
695
|
// ─── Default export ───────────────────────────────────────────────────────────
|
|
539
696
|
|
|
@@ -571,12 +728,19 @@ declare const extractia: {
|
|
|
571
728
|
// Analytics
|
|
572
729
|
getCreditsBalance: typeof getCreditsBalance;
|
|
573
730
|
getCreditsHistory: typeof getCreditsHistory;
|
|
731
|
+
getDocumentHistory: typeof getDocumentHistory;
|
|
574
732
|
// OCR Tools
|
|
575
733
|
getOcrTools: typeof getOcrTools;
|
|
576
734
|
createOcrTool: typeof createOcrTool;
|
|
577
735
|
updateOcrTool: typeof updateOcrTool;
|
|
578
736
|
deleteOcrTool: typeof deleteOcrTool;
|
|
579
737
|
runOcrTool: typeof runOcrTool;
|
|
738
|
+
// Sub-users
|
|
739
|
+
getSubUsers: typeof getSubUsers;
|
|
740
|
+
createSubUser: typeof createSubUser;
|
|
741
|
+
deleteSubUser: typeof deleteSubUser;
|
|
742
|
+
updateSubUser: typeof updateSubUser;
|
|
743
|
+
toggleSuspendSubUser: typeof toggleSuspendSubUser;
|
|
580
744
|
};
|
|
581
745
|
|
|
582
746
|
export default extractia;
|
package/src/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export * from "./templates.js";
|
|
|
3
3
|
export * from "./documents.js";
|
|
4
4
|
export * from "./analytics.js";
|
|
5
5
|
export * from "./ocrTools.js";
|
|
6
|
+
export * from "./subusers.js";
|
|
6
7
|
export {
|
|
7
8
|
ExtractiaError,
|
|
8
9
|
AuthError,
|
|
@@ -17,6 +18,7 @@ import * as templates from "./templates.js";
|
|
|
17
18
|
import * as documents from "./documents.js";
|
|
18
19
|
import * as analytics from "./analytics.js";
|
|
19
20
|
import * as ocrTools from "./ocrTools.js";
|
|
21
|
+
import * as subusers from "./subusers.js";
|
|
20
22
|
|
|
21
23
|
const extractia = {
|
|
22
24
|
...auth,
|
|
@@ -24,6 +26,7 @@ const extractia = {
|
|
|
24
26
|
...documents,
|
|
25
27
|
...analytics,
|
|
26
28
|
...ocrTools,
|
|
29
|
+
...subusers,
|
|
27
30
|
};
|
|
28
31
|
|
|
29
32
|
export default extractia;
|