extractia-sdk 1.2.0 → 1.3.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 +14 -14
- package/package.json +1 -1
- package/src/subusers.js +40 -16
package/README.md
CHANGED
|
@@ -839,19 +839,19 @@ Available permissions: `"upload"` · `"view"` · `"template"` · `"settings"` ·
|
|
|
839
839
|
### Document History
|
|
840
840
|
|
|
841
841
|
```js
|
|
842
|
-
import { getDocumentHistory } from
|
|
842
|
+
import { getDocumentHistory } from "extractia-sdk";
|
|
843
843
|
|
|
844
844
|
const log = await getDocumentHistory({ page: 0, size: 20 });
|
|
845
845
|
log.content.forEach((entry) => {
|
|
846
846
|
console.log(entry.templateName, entry.status, entry.uploadDate);
|
|
847
|
-
if (entry.status ===
|
|
847
|
+
if (entry.status === "FAILURE") console.error(entry.errorMessage);
|
|
848
848
|
});
|
|
849
849
|
```
|
|
850
850
|
|
|
851
851
|
### List Sub-Users
|
|
852
852
|
|
|
853
853
|
```js
|
|
854
|
-
import { getSubUsers } from
|
|
854
|
+
import { getSubUsers } from "extractia-sdk";
|
|
855
855
|
|
|
856
856
|
const users = await getSubUsers();
|
|
857
857
|
// [{ username: 'agent_carlos', permissions: ['upload','view'], suspended: false }]
|
|
@@ -860,12 +860,12 @@ const users = await getSubUsers();
|
|
|
860
860
|
### Create a Sub-User
|
|
861
861
|
|
|
862
862
|
```js
|
|
863
|
-
import { createSubUser } from
|
|
863
|
+
import { createSubUser } from "extractia-sdk";
|
|
864
864
|
|
|
865
865
|
const sub = await createSubUser({
|
|
866
|
-
username:
|
|
867
|
-
password:
|
|
868
|
-
permissions: [
|
|
866
|
+
username: "agent_carlos",
|
|
867
|
+
password: "SecurePass1",
|
|
868
|
+
permissions: ["upload", "view"],
|
|
869
869
|
});
|
|
870
870
|
```
|
|
871
871
|
|
|
@@ -881,10 +881,10 @@ const sub = await createSubUser({
|
|
|
881
881
|
Only the fields you include are changed. Omit `password` to keep it unchanged.
|
|
882
882
|
|
|
883
883
|
```js
|
|
884
|
-
import { updateSubUser } from
|
|
884
|
+
import { updateSubUser } from "extractia-sdk";
|
|
885
885
|
|
|
886
|
-
await updateSubUser(
|
|
887
|
-
permissions: [
|
|
886
|
+
await updateSubUser("agent_carlos", {
|
|
887
|
+
permissions: ["upload", "view", "export"],
|
|
888
888
|
// password: 'NewPass99', ← optional
|
|
889
889
|
});
|
|
890
890
|
```
|
|
@@ -892,9 +892,9 @@ await updateSubUser('agent_carlos', {
|
|
|
892
892
|
### Delete a Sub-User
|
|
893
893
|
|
|
894
894
|
```js
|
|
895
|
-
import { deleteSubUser } from
|
|
895
|
+
import { deleteSubUser } from "extractia-sdk";
|
|
896
896
|
|
|
897
|
-
await deleteSubUser(
|
|
897
|
+
await deleteSubUser("agent_carlos");
|
|
898
898
|
```
|
|
899
899
|
|
|
900
900
|
### Suspend / Reactivate
|
|
@@ -902,9 +902,9 @@ await deleteSubUser('agent_carlos');
|
|
|
902
902
|
A suspended sub-user cannot log in. Calling the same method again reactivates them.
|
|
903
903
|
|
|
904
904
|
```js
|
|
905
|
-
import { toggleSuspendSubUser } from
|
|
905
|
+
import { toggleSuspendSubUser } from "extractia-sdk";
|
|
906
906
|
|
|
907
|
-
const state = await toggleSuspendSubUser(
|
|
907
|
+
const state = await toggleSuspendSubUser("agent_carlos");
|
|
908
908
|
console.log(state.suspended); // true | false
|
|
909
909
|
```
|
|
910
910
|
|
package/package.json
CHANGED
package/src/subusers.js
CHANGED
|
@@ -11,6 +11,7 @@ import api from "./apiClient.js";
|
|
|
11
11
|
* @returns {Promise<Array<{
|
|
12
12
|
* username: string,
|
|
13
13
|
* permissions: string[],
|
|
14
|
+
* allowedFormIds: string[] | null,
|
|
14
15
|
* suspended: boolean,
|
|
15
16
|
* lastKnownLocation?: string,
|
|
16
17
|
* lastLocationAt?: string
|
|
@@ -25,24 +26,40 @@ export async function getSubUsers() {
|
|
|
25
26
|
* Creates a new sub-user for the authenticated account.
|
|
26
27
|
*
|
|
27
28
|
* Available permissions: `"upload"`, `"view"`, `"template"`, `"settings"`,
|
|
28
|
-
* `"export"`, `"
|
|
29
|
+
* `"export"`, `"ocr_tools"`, `"gallery"`, `"smart_scan"`, `"ia_agent"`.
|
|
29
30
|
*
|
|
30
|
-
* @param {Object}
|
|
31
|
-
* @param {string}
|
|
32
|
-
* @param {string}
|
|
33
|
-
* @param {string[]}
|
|
34
|
-
* @
|
|
31
|
+
* @param {Object} subUser - Sub-user definition.
|
|
32
|
+
* @param {string} subUser.username - Unique username (must not be an existing account email).
|
|
33
|
+
* @param {string} subUser.password - Initial password (must differ from the owner's password).
|
|
34
|
+
* @param {string[]} subUser.permissions - List of permission strings to grant.
|
|
35
|
+
* @param {string[]?} subUser.allowedFormIds - Optional list of form template IDs this sub-user may access.
|
|
36
|
+
* When omitted or null, the sub-user can access all forms.
|
|
37
|
+
* @returns {Promise<{ username: string, permissions: string[], allowedFormIds?: string[] }>} Confirmation object.
|
|
35
38
|
* @throws {ForbiddenError} 403 if the plan does not allow sub-users or the limit is reached.
|
|
36
39
|
* @throws {ExtractiaError} 409 if the username is already taken.
|
|
37
40
|
*/
|
|
38
|
-
export async function createSubUser({
|
|
39
|
-
|
|
41
|
+
export async function createSubUser({
|
|
42
|
+
username,
|
|
43
|
+
password,
|
|
44
|
+
permissions,
|
|
45
|
+
allowedFormIds,
|
|
46
|
+
}) {
|
|
47
|
+
const res = await api.post("/me/subusers", {
|
|
48
|
+
username,
|
|
49
|
+
password,
|
|
50
|
+
permissions,
|
|
51
|
+
...(allowedFormIds !== undefined ? { allowedFormIds } : {}),
|
|
52
|
+
});
|
|
40
53
|
return res.data;
|
|
41
54
|
}
|
|
42
55
|
|
|
43
56
|
/**
|
|
44
57
|
* Deletes a sub-user by username.
|
|
45
58
|
*
|
|
59
|
+
* @note The deleted sub-user's JWT token is immediately rejected by the server
|
|
60
|
+
* on every subsequent request — no grace period. Token revocation happens
|
|
61
|
+
* automatically via the authentication filter.
|
|
62
|
+
*
|
|
46
63
|
* @param {string} username - The sub-user's username.
|
|
47
64
|
* @returns {Promise<{ deleted: string }>} Confirmation with the deleted username.
|
|
48
65
|
* @throws {NotFoundError} 404 if the sub-user does not exist.
|
|
@@ -53,19 +70,24 @@ export async function deleteSubUser(username) {
|
|
|
53
70
|
}
|
|
54
71
|
|
|
55
72
|
/**
|
|
56
|
-
* Updates the permissions and/or password of a sub-user.
|
|
73
|
+
* Updates the permissions, allowed forms, and/or password of a sub-user.
|
|
57
74
|
*
|
|
58
|
-
* Pass only the fields you want to change. Omitting
|
|
75
|
+
* Pass only the fields you want to change. Omitting a field leaves it unchanged.
|
|
59
76
|
*
|
|
60
|
-
* @param {string} username
|
|
61
|
-
* @param {Object} updates
|
|
62
|
-
* @param {string[]} [updates.permissions]
|
|
63
|
-
* @param {string}
|
|
77
|
+
* @param {string} username - The sub-user's username.
|
|
78
|
+
* @param {Object} updates - Fields to update.
|
|
79
|
+
* @param {string[]} [updates.permissions] - New permission set (replaces existing).
|
|
80
|
+
* @param {string[]?} [updates.allowedFormIds] - New allowed form ID list (replaces existing).
|
|
81
|
+
* Pass an empty array to remove all restrictions.
|
|
82
|
+
* @param {string} [updates.password] - New password (must differ from owner's password).
|
|
64
83
|
* @returns {Promise<{ username: string, updated: boolean }>}
|
|
65
84
|
* @throws {NotFoundError} 404 if the sub-user does not exist.
|
|
66
85
|
*/
|
|
67
86
|
export async function updateSubUser(username, updates = {}) {
|
|
68
|
-
const res = await api.put(
|
|
87
|
+
const res = await api.put(
|
|
88
|
+
`/me/subusers/${encodeURIComponent(username)}`,
|
|
89
|
+
updates,
|
|
90
|
+
);
|
|
69
91
|
return res.data;
|
|
70
92
|
}
|
|
71
93
|
|
|
@@ -80,6 +102,8 @@ export async function updateSubUser(username, updates = {}) {
|
|
|
80
102
|
* @throws {NotFoundError} 404 if the sub-user does not exist.
|
|
81
103
|
*/
|
|
82
104
|
export async function toggleSuspendSubUser(username) {
|
|
83
|
-
const res = await api.put(
|
|
105
|
+
const res = await api.put(
|
|
106
|
+
`/me/subusers/${encodeURIComponent(username)}/suspend`,
|
|
107
|
+
);
|
|
84
108
|
return res.data;
|
|
85
109
|
}
|