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/src/ocrTools.js CHANGED
@@ -14,11 +14,15 @@ export async function getOcrTools() {
14
14
  /**
15
15
  * Creates a new OCR tool configuration.
16
16
  *
17
- * @param {Object} config - Tool definition.
18
- * @param {string} config.name - Human-friendly display name.
19
- * @param {string} config.prompt - The AI instruction/question to evaluate against each image.
17
+ * @param {Object} config - Tool definition.
18
+ * @param {string} config.name - Human-friendly display name.
19
+ * @param {string} config.prompt - The AI instruction/question (max 3 000 chars). May include
20
+ * {{?1}}, {{?2}}, … placeholders for dynamic parameters.
20
21
  * @param {'YES_NO'|'LABEL'|'TEXT'} config.outputType - Expected output shape.
21
- * @param {string[]} [config.labels] - Required when outputType is 'LABEL'. List of possible labels.
22
+ * @param {string[]} [config.labels] - Required when outputType is 'LABEL'.
23
+ * @param {Array<{key:number,label:string,description?:string,maxChars?:number}>} [config.parameterDefinitions]
24
+ * Dynamic parameter definitions for {{?N}} placeholders. Each entry needs at minimum `key` (1-based) and
25
+ * `label`. Optional `maxChars` (1–500, default 200) limits per-parameter input length.
22
26
  * @returns {Promise<Object>} The created OcrToolConfig.
23
27
  */
24
28
  export async function createOcrTool(config) {
@@ -55,11 +59,26 @@ export async function deleteOcrTool(id) {
55
59
  * The image may include a data-URL prefix (e.g. `data:image/jpeg;base64,...`)
56
60
  * or be a raw base64 string.
57
61
  *
62
+ * Each run deducts **1 document credit** from the user's quota plus AI credits
63
+ * based on token usage: `ceil(totalTokens / 1000)` credits.
64
+ *
65
+ * The AI response language matches the language used in the prompt / parameter values.
66
+ *
58
67
  * @param {string} id - The OCR tool config ID.
59
- * @param {string} base64Image - Base64-encoded image (with or without data-URL prefix).
68
+ * @param {string} base64Image - Base64-encoded image (with or without data-URL prefix). Max 5 MB.
69
+ * @param {{ params?: Record<string, string> }} [options]
70
+ * Optional. `params` is a map from placeholder key (as string, e.g. "1") to value, used to
71
+ * substitute {{?N}} placeholders in the tool's prompt. Values must not exceed the per-parameter
72
+ * `maxChars` limit; the substituted prompt must not exceed 3 000 characters total.
60
73
  * @returns {Promise<{ answer: string, explanation: string }>} The AI result.
74
+ * @throws {ExtractiaError} 400 if a required parameter is missing/too long or the prompt limit is exceeded.
75
+ * @throws {TierError} 402 if the document quota or AI credits are exhausted.
61
76
  */
62
- export async function runOcrTool(id, base64Image) {
63
- const res = await api.post(`/ocr-tools/${id}/run`, { image: base64Image });
77
+ export async function runOcrTool(id, base64Image, options = {}) {
78
+ const body = { image: base64Image };
79
+ if (options.params && Object.keys(options.params).length > 0) {
80
+ body.params = options.params;
81
+ }
82
+ const res = await api.post(`/ocr-tools/${id}/run`, body);
64
83
  return res.data;
65
84
  }
@@ -0,0 +1,85 @@
1
+ // src/subusers.js
2
+ import api from "./apiClient.js";
3
+
4
+ /**
5
+ * Returns all sub-users for the authenticated account.
6
+ *
7
+ * Sub-users can log in to the web app and perform actions within the
8
+ * permissions granted by the owner. This endpoint is only available on
9
+ * plans that support sub-users (Pro and above).
10
+ *
11
+ * @returns {Promise<Array<{
12
+ * username: string,
13
+ * permissions: string[],
14
+ * suspended: boolean,
15
+ * lastKnownLocation?: string,
16
+ * lastLocationAt?: string
17
+ * }>>} Array of sub-user objects. Password hashes are never returned.
18
+ */
19
+ export async function getSubUsers() {
20
+ const res = await api.get("/me/subusers");
21
+ return res.data;
22
+ }
23
+
24
+ /**
25
+ * Creates a new sub-user for the authenticated account.
26
+ *
27
+ * Available permissions: `"upload"`, `"view"`, `"template"`, `"settings"`,
28
+ * `"export"`, `"api"`.
29
+ *
30
+ * @param {Object} subUser - Sub-user definition.
31
+ * @param {string} subUser.username - Unique username (must not be an existing account email).
32
+ * @param {string} subUser.password - Initial password (must differ from the owner's password).
33
+ * @param {string[]} subUser.permissions - List of permission strings to grant.
34
+ * @returns {Promise<{ username: string, permissions: string[] }>} Confirmation object.
35
+ * @throws {ForbiddenError} 403 if the plan does not allow sub-users or the limit is reached.
36
+ * @throws {ExtractiaError} 409 if the username is already taken.
37
+ */
38
+ export async function createSubUser({ username, password, permissions }) {
39
+ const res = await api.post("/me/subusers", { username, password, permissions });
40
+ return res.data;
41
+ }
42
+
43
+ /**
44
+ * Deletes a sub-user by username.
45
+ *
46
+ * @param {string} username - The sub-user's username.
47
+ * @returns {Promise<{ deleted: string }>} Confirmation with the deleted username.
48
+ * @throws {NotFoundError} 404 if the sub-user does not exist.
49
+ */
50
+ export async function deleteSubUser(username) {
51
+ const res = await api.delete(`/me/subusers/${encodeURIComponent(username)}`);
52
+ return res.data;
53
+ }
54
+
55
+ /**
56
+ * Updates the permissions and/or password of a sub-user.
57
+ *
58
+ * Pass only the fields you want to change. Omitting `password` leaves it unchanged.
59
+ *
60
+ * @param {string} username - The sub-user's username.
61
+ * @param {Object} updates - Fields to update.
62
+ * @param {string[]} [updates.permissions] - New permission set (replaces existing).
63
+ * @param {string} [updates.password] - New password (must differ from owner's password).
64
+ * @returns {Promise<{ username: string, updated: boolean }>}
65
+ * @throws {NotFoundError} 404 if the sub-user does not exist.
66
+ */
67
+ export async function updateSubUser(username, updates = {}) {
68
+ const res = await api.put(`/me/subusers/${encodeURIComponent(username)}`, updates);
69
+ return res.data;
70
+ }
71
+
72
+ /**
73
+ * Toggles the suspended state of a sub-user.
74
+ *
75
+ * A suspended sub-user cannot log in until unsuspended. Their permissions
76
+ * are retained and restored on unsuspension.
77
+ *
78
+ * @param {string} username - The sub-user's username.
79
+ * @returns {Promise<{ username: string, suspended: boolean }>} New suspension state.
80
+ * @throws {NotFoundError} 404 if the sub-user does not exist.
81
+ */
82
+ export async function toggleSuspendSubUser(username) {
83
+ const res = await api.put(`/me/subusers/${encodeURIComponent(username)}/suspend`);
84
+ return res.data;
85
+ }