extractia-sdk 1.0.6 → 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/index.d.ts ADDED
@@ -0,0 +1,746 @@
1
+ // ─── Extractia SDK v1.1 — TypeScript type declarations ───────────────────────
2
+ // Keep in sync with JavaScript source files.
3
+
4
+ // ─── Primitives ───────────────────────────────────────────────────────────────
5
+
6
+ /** Supported field types for a FormField. */
7
+ export type FieldType =
8
+ | 'TEXT'
9
+ | 'NUMBER'
10
+ | 'PERCENTAGE'
11
+ | 'DATE'
12
+ | 'BOOLEAN'
13
+ | 'EMAIL'
14
+ | 'PHONE'
15
+ | 'ADDRESS'
16
+ | 'CURRENCY'
17
+ | 'LIST';
18
+
19
+ /** A single field definition within a FormTemplate. */
20
+ export interface FormField {
21
+ /** Display label shown in the UI (e.g. "Invoice Date"). */
22
+ label: string;
23
+ /** Data type used for extraction and rendering. */
24
+ type: FieldType;
25
+ /** Whether the field is required for extraction. */
26
+ required?: boolean;
27
+ /**
28
+ * Only present on LIST-type fields.
29
+ * Short singular noun for one item in the list (e.g. "Product", "LineItem").
30
+ */
31
+ listLabel?: string;
32
+ }
33
+
34
+ /** A template that defines the structure of documents to extract. */
35
+ export interface FormTemplate {
36
+ id: string;
37
+ /** Template name shown in the UI. */
38
+ label: string;
39
+ /** Ordered list of fields to extract from each document. */
40
+ fields: FormField[];
41
+ /** MongoDB ID of the owning user. */
42
+ userId: string;
43
+ createdAt?: string;
44
+ }
45
+
46
+ /** Extracted JSON from a single document. Keys match the template's field labels. */
47
+ export type ExtractionResult = Record<string, string | number | boolean | ExtractionResult | ExtractionResult[]>;
48
+
49
+ /** A processed document stored in the platform. */
50
+ export interface UserDocument {
51
+ id: string;
52
+ formTemplateId: string;
53
+ /** Raw AI extraction result (may be wrapped in markdown fences). */
54
+ rawJson?: string;
55
+ /** User-reviewed and potentially edited JSON. `null` if unreviewed. */
56
+ reviewedJson?: string | null;
57
+ /** Base64-encoded source image (only returned when `includeImage=1`). */
58
+ imageBase64?: string | null;
59
+ /** Whether the document has been reviewed/confirmed by a user. */
60
+ preconformed?: boolean;
61
+ /** Reviewer notes or annotations. */
62
+ notes?: string | null;
63
+ /** Document workflow status (e.g. "REVIEWED", "PENDING"). */
64
+ status?: string | null;
65
+ createdAt?: string;
66
+ }
67
+
68
+ /** Paginated document list response. */
69
+ export interface DocumentPage {
70
+ content: UserDocument[];
71
+ totalPages: number;
72
+ }
73
+
74
+ /** Authenticated user profile returned by `/me`. */
75
+ export interface AppUserProfile {
76
+ userId: string;
77
+ name?: string;
78
+ email: string;
79
+ signupDate?: string;
80
+ /** URL to receive webhook POST calls after document processing. */
81
+ webhook?: string | null;
82
+ /** Number of form templates owned. */
83
+ formTemplatesCount?: number;
84
+ /** Total documents processed (lifetime). */
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;
90
+ tier?: object;
91
+ subscription?: object;
92
+ }
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
+
123
+ /** AI credit balance. */
124
+ export interface CreditsBalance {
125
+ monthlyBalance: number;
126
+ addonBalance: number;
127
+ totalBalance: number;
128
+ }
129
+
130
+ /** A single AI credit consumption log entry. */
131
+ export interface CreditLogEntry {
132
+ id: string;
133
+ userId: string;
134
+ timestamp: string;
135
+ operation: string;
136
+ operationDetail?: string | null;
137
+ inputTokens?: number;
138
+ outputTokens?: number;
139
+ totalTokens?: number;
140
+ creditsConsumed: number;
141
+ /** Sub-user or API user who triggered the action. */
142
+ performedBy?: string | null;
143
+ }
144
+
145
+ /** OCR Tool output types. */
146
+ export type OcrOutputType = 'YES_NO' | 'LABEL' | 'TEXT';
147
+
148
+ /** An OCR Tool configuration. */
149
+ export interface OcrToolConfig {
150
+ id?: string;
151
+ /** Human-friendly display name (e.g. "Proof of Residence Check"). */
152
+ name: string;
153
+ /**
154
+ * Natural-language instruction evaluated against the document image. Max 3 000 characters
155
+ * (after parameter substitution). May contain {{?1}}, {{?2}}, … placeholders.
156
+ */
157
+ prompt: string;
158
+ /** Expected output shape. */
159
+ outputType: OcrOutputType;
160
+ /**
161
+ * Required when `outputType === 'LABEL'`.
162
+ * List of possible labels the AI must pick from.
163
+ */
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[];
170
+ createdAt?: string;
171
+ }
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
+
197
+ /** Result returned after running an OCR tool. */
198
+ export interface OcrRunResult {
199
+ /** The AI's answer (e.g. "YES", "invoice", or free-form text). */
200
+ answer: string;
201
+ /** Short rationale explaining the answer. */
202
+ explanation: string;
203
+ }
204
+
205
+ // ─── Error classes ────────────────────────────────────────────────────────────
206
+
207
+ /** Base error class for all Extractia SDK errors. */
208
+ export class ExtractiaError extends Error {
209
+ /** HTTP status code associated with the error. */
210
+ status: number;
211
+ constructor(message: string, status: number);
212
+ }
213
+
214
+ /** Thrown when the API token is missing or invalid (HTTP 401). */
215
+ export class AuthError extends ExtractiaError {
216
+ constructor(message?: string);
217
+ }
218
+
219
+ /** Thrown when the account lacks permission to perform the action (HTTP 403). */
220
+ export class ForbiddenError extends ExtractiaError {
221
+ constructor(message?: string);
222
+ }
223
+
224
+ /** Thrown when the active plan does not allow the requested operation (HTTP 402). */
225
+ export class TierError extends ExtractiaError {
226
+ constructor(message?: string, status?: number);
227
+ }
228
+
229
+ /** Thrown when the API rate limit is exceeded (HTTP 429). */
230
+ export class RateLimitError extends ExtractiaError {
231
+ /** Seconds to wait before the next request. */
232
+ retryAfter?: number;
233
+ constructor(message?: string);
234
+ }
235
+
236
+ /** Thrown when a requested resource was not found (HTTP 404). */
237
+ export class NotFoundError extends ExtractiaError {
238
+ constructor(message?: string);
239
+ }
240
+
241
+ // ─── Setup ────────────────────────────────────────────────────────────────────
242
+
243
+ /**
244
+ * Sets the Bearer API token used for all subsequent requests.
245
+ * **Must be called before any SDK method.**
246
+ *
247
+ * @param token Your Extractia API token (from Account → API Tokens).
248
+ *
249
+ * @example
250
+ * import { setToken } from 'extractia-sdk';
251
+ * setToken('ext_live_...');
252
+ */
253
+ export function setToken(token: string): void;
254
+
255
+ /**
256
+ * Configures SDK options.
257
+ * @param opts
258
+ * @param [opts.baseURL] Override the default API base URL (useful for self-hosted instances).
259
+ */
260
+ export function configure(opts: { baseURL?: string }): void;
261
+
262
+ // ─── Auth / Profile ───────────────────────────────────────────────────────────
263
+
264
+ /**
265
+ * Returns the profile and usage metrics of the authenticated user.
266
+ *
267
+ * @example
268
+ * const me = await getMyProfile();
269
+ * console.log(me.email, me.formTemplatesCount);
270
+ */
271
+ export function getMyProfile(): Promise<AppUserProfile>;
272
+
273
+ /**
274
+ * Updates the webhook URL for the authenticated user.
275
+ * All document processing completions will POST to this URL.
276
+ *
277
+ * @param url The new webhook URL. Pass an empty string to remove it.
278
+ *
279
+ * @example
280
+ * await updateWebhook('https://my-app.com/webhooks/extractia');
281
+ */
282
+ export function updateWebhook(url: string): Promise<void>;
283
+
284
+ // ─── Templates ────────────────────────────────────────────────────────────────
285
+
286
+ /** Returns all templates belonging to the authenticated user. */
287
+ export function getTemplates(): Promise<FormTemplate[]>;
288
+
289
+ /**
290
+ * Returns a single template by its ID.
291
+ * @param id Template ID.
292
+ */
293
+ export function getTemplateById(id: string): Promise<FormTemplate>;
294
+
295
+ /**
296
+ * Returns a template by its label name.
297
+ * @param name Template label (case-sensitive).
298
+ */
299
+ export function getTemplateByName(name: string): Promise<FormTemplate>;
300
+
301
+ /**
302
+ * Creates a new template.
303
+ * @param template Template definition (omit `id` and `userId`).
304
+ *
305
+ * @example
306
+ * const tpl = await createTemplate({
307
+ * label: 'Invoice',
308
+ * fields: [
309
+ * { label: 'Invoice Number', type: 'TEXT', required: true },
310
+ * { label: 'Total Amount', type: 'CURRENCY', required: true },
311
+ * { label: 'Issue Date', type: 'DATE', required: false },
312
+ * ]
313
+ * });
314
+ */
315
+ export function createTemplate(template: Omit<FormTemplate, 'id' | 'userId'>): Promise<FormTemplate>;
316
+
317
+ /**
318
+ * Updates an existing template.
319
+ * @param id Template ID.
320
+ * @param template Partial template definition to merge.
321
+ */
322
+ export function updateTemplate(id: string, template: Partial<FormTemplate>): Promise<FormTemplate>;
323
+
324
+ /**
325
+ * Deletes a template by its ID.
326
+ * Templates with associated documents cannot be deleted — delete the documents first.
327
+ * @param id Template ID.
328
+ */
329
+ export function deleteTemplate(id: string): Promise<void>;
330
+
331
+ /**
332
+ * Deletes all documents associated with a template (does not delete the template itself).
333
+ * @param id Template ID.
334
+ */
335
+ export function deleteAllTemplateDocuments(id: string): Promise<void>;
336
+
337
+ /**
338
+ * Uses AI to suggest extraction field definitions for a given document type.
339
+ *
340
+ * @param templateName Document type name (e.g. "Invoice", "Driver's License").
341
+ * @param extractionContext Optional natural-language description of what to extract
342
+ * (e.g. "I need the line items including product name and quantity").
343
+ * @returns Array of field suggestions ready to use in `createTemplate`.
344
+ *
345
+ * @example
346
+ * const fields = await suggestFields('Purchase Order', 'list all ordered products');
347
+ * const tpl = await createTemplate({ label: 'Purchase Order', fields });
348
+ */
349
+ export function suggestFields(
350
+ templateName: string,
351
+ extractionContext?: string
352
+ ): Promise<FormField[]>;
353
+
354
+ // ─── Documents ────────────────────────────────────────────────────────────────
355
+
356
+ /**
357
+ * Retrieves documents associated with a template (paginated, newest first).
358
+ *
359
+ * @param templateId Template ID.
360
+ * @param options Query options.
361
+ *
362
+ * @example
363
+ * const page = await getDocumentsByTemplateId('tpl_123', { index: 0, preconformed: true });
364
+ */
365
+ export function getDocumentsByTemplateId(
366
+ templateId: string,
367
+ options?: {
368
+ /** Filter by preconfirmed/reviewed status. */
369
+ preconformed?: boolean;
370
+ /** Zero-based page index. */
371
+ index?: number;
372
+ /** Sort direction: "1" = ASC, "-1" = DESC (default). */
373
+ sort?: string;
374
+ /** Whether to include the base64 source image in results. */
375
+ includeImage?: boolean;
376
+ }
377
+ ): Promise<DocumentPage>;
378
+
379
+ /**
380
+ * Returns a single document by template ID and document ID.
381
+ *
382
+ * @param templateId Template ID.
383
+ * @param docId Document ID.
384
+ * @param options
385
+ * @param [options.includeImage] Whether to include the base64 source image.
386
+ */
387
+ export function getDocumentById(
388
+ templateId: string,
389
+ docId: string,
390
+ options?: { includeImage?: boolean }
391
+ ): Promise<UserDocument>;
392
+
393
+ /**
394
+ * Returns the N most-recent documents across all templates.
395
+ *
396
+ * @param size Maximum number of documents to return (default 10, max 50).
397
+ */
398
+ export function getRecentDocuments(size?: number): Promise<UserDocument[]>;
399
+
400
+ /**
401
+ * Deletes a document by its ID.
402
+ * @param documentId Document ID.
403
+ */
404
+ export function deleteDocument(documentId: string): Promise<void>;
405
+
406
+ /**
407
+ * Processes a single base64-encoded image against a template.
408
+ * AI extracts the fields defined in the template and stores the result.
409
+ *
410
+ * @param templateId Template ID.
411
+ * @param base64Image Base64-encoded image (with or without `data:` prefix). Max 5 MB.
412
+ *
413
+ * @example
414
+ * const doc = await processImage('tpl_123', base64String);
415
+ * console.log(doc.rawJson); // Extracted JSON
416
+ */
417
+ export function processImage(templateId: string, base64Image: string): Promise<UserDocument>;
418
+
419
+ /**
420
+ * Processes multiple base64-encoded images as a multi-page document.
421
+ * All pages are merged into a single `UserDocument`.
422
+ *
423
+ * @param templateId Template ID.
424
+ * @param base64ImagesArray Array of base64-encoded images (one per page, max 5 MB each).
425
+ */
426
+ export function processImagesMultipage(
427
+ templateId: string,
428
+ base64ImagesArray: string[]
429
+ ): Promise<UserDocument>;
430
+
431
+ /**
432
+ * Generates an AI bullet-point summary for the extracted data of a document.
433
+ * Consumes AI credits.
434
+ *
435
+ * @param docId Document ID.
436
+ *
437
+ * @example
438
+ * const { summary } = await generateDocumentSummary('doc_456');
439
+ * console.log(summary); // "• Invoice #1042 issued on Jan 5 2025..."
440
+ */
441
+ export function generateDocumentSummary(docId: string): Promise<{ summary: string }>;
442
+
443
+ /**
444
+ * Updates the workflow status of a document.
445
+ *
446
+ * @param docId Document ID.
447
+ * @param status New status string (e.g. "REVIEWED", "APPROVED", "REJECTED").
448
+ */
449
+ export function updateDocumentStatus(
450
+ docId: string,
451
+ status: string
452
+ ): Promise<{ id: string; status: string }>;
453
+
454
+ /**
455
+ * Saves or clears reviewer notes on a document.
456
+ *
457
+ * @param docId Document ID.
458
+ * @param notes Annotation text. Pass an empty string to clear existing notes.
459
+ */
460
+ export function updateDocumentNotes(
461
+ docId: string,
462
+ notes: string
463
+ ): Promise<{ id: string; notes: string }>;
464
+
465
+ /**
466
+ * Updates the extracted JSON data of a document and optionally marks it as reviewed.
467
+ *
468
+ * Use this to correct AI extraction errors programmatically or to mark a document
469
+ * as confirmed.
470
+ *
471
+ * @param docId Document ID.
472
+ * @param data New extracted data as a plain object.
473
+ * @param options
474
+ * @param [options.preconformed=false] Mark the document as reviewed/confirmed.
475
+ *
476
+ * @example
477
+ * await updateDocumentData('doc_456', { 'Total Amount': 1250.00 }, { preconformed: true });
478
+ */
479
+ export function updateDocumentData(
480
+ docId: string,
481
+ data: Record<string, unknown>,
482
+ options?: { preconformed?: boolean }
483
+ ): Promise<UserDocument>;
484
+
485
+ /**
486
+ * Marks multiple documents as preconformed (reviewed) in a single request.
487
+ *
488
+ * @param ids Array of document IDs.
489
+ * @returns Object with the count of documents actually updated.
490
+ */
491
+ export function bulkPreconform(ids: string[]): Promise<{ updated: number }>;
492
+
493
+ /**
494
+ * Exports all documents of a template as raw CSV text.
495
+ *
496
+ * The CSV includes all extracted fields plus `preconformed` and `uploadedAt` columns.
497
+ *
498
+ * @param templateId Template ID.
499
+ * @param options
500
+ * @param [options.fields] Optional subset of column names to include (dot-notation for nested).
501
+ *
502
+ * @example
503
+ * const csv = await exportDocumentsCsv('tpl_123');
504
+ * fs.writeFileSync('documents.csv', csv);
505
+ */
506
+ export function exportDocumentsCsv(
507
+ templateId: string,
508
+ options?: { fields?: string[] }
509
+ ): Promise<string>;
510
+
511
+ /**
512
+ * Exports all documents of a template as a JSON array.
513
+ *
514
+ * Each element contains the extracted field map plus three metadata keys:
515
+ * `_id`, `_preconformed`, and `_uploadedAt`.
516
+ *
517
+ * @param templateId Template ID.
518
+ *
519
+ * @example
520
+ * const data = await exportDocumentsJson('tpl_123');
521
+ * data.forEach(doc => console.log(doc._id, doc['Invoice Number']));
522
+ */
523
+ export function exportDocumentsJson(templateId: string): Promise<Record<string, unknown>[]>;
524
+
525
+ // ─── Analytics / Credits ──────────────────────────────────────────────────────
526
+
527
+ /**
528
+ * Returns the current AI-credit balance for the authenticated user.
529
+ *
530
+ * @example
531
+ * const balance = await getCreditsBalance();
532
+ * console.log(`You have ${balance.totalBalance} credits remaining.`);
533
+ */
534
+ export function getCreditsBalance(): Promise<CreditsBalance>;
535
+
536
+ /**
537
+ * Returns a paginated history of AI credit consumption events.
538
+ *
539
+ * @param options
540
+ * @param [options.page=0] Zero-based page index.
541
+ * @param [options.size=20] Page size (max 100).
542
+ */
543
+ export function getCreditsHistory(options?: {
544
+ page?: number;
545
+ size?: number;
546
+ }): Promise<{
547
+ content: CreditLogEntry[];
548
+ totalPages: number;
549
+ totalElements: number;
550
+ }>;
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
+
573
+ // ─── OCR Tools ────────────────────────────────────────────────────────────────
574
+
575
+ /**
576
+ * Returns all OCR tool configurations belonging to the authenticated user.
577
+ *
578
+ * @example
579
+ * const tools = await getOcrTools();
580
+ */
581
+ export function getOcrTools(): Promise<OcrToolConfig[]>;
582
+
583
+ /**
584
+ * Creates a new OCR tool configuration.
585
+ *
586
+ * @example
587
+ * const tool = await createOcrTool({
588
+ * name: 'Proof of Residence Check',
589
+ * prompt: 'Does this document appear to be a valid proof of residence?',
590
+ * outputType: 'YES_NO',
591
+ * });
592
+ */
593
+ export function createOcrTool(config: Omit<OcrToolConfig, 'id' | 'createdAt'>): Promise<OcrToolConfig>;
594
+
595
+ /**
596
+ * Updates an existing OCR tool configuration.
597
+ *
598
+ * @param id OCR tool ID.
599
+ * @param config Updated fields.
600
+ */
601
+ export function updateOcrTool(id: string, config: Partial<Omit<OcrToolConfig, 'id' | 'createdAt'>>): Promise<OcrToolConfig>;
602
+
603
+ /**
604
+ * Deletes an OCR tool configuration.
605
+ * @param id OCR tool ID.
606
+ */
607
+ export function deleteOcrTool(id: string): Promise<void>;
608
+
609
+ /**
610
+ * Runs an OCR tool against a base64-encoded image.
611
+ *
612
+ * The image may include a data-URL prefix (e.g. `data:image/jpeg;base64,...`)
613
+ * or be a plain base64 string. Max image size is 5 MB.
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
+ *
619
+ * @param id OCR tool ID.
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.
625
+ *
626
+ * @example
627
+ * const result = await runOcrTool('tool_789', base64String);
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.
692
+ */
693
+ export function toggleSuspendSubUser(username: string): Promise<{ username: string; suspended: boolean }>;
694
+
695
+ // ─── Default export ───────────────────────────────────────────────────────────
696
+
697
+ /** Namespace object bundling all SDK methods for UMD / CommonJS consumers. */
698
+ declare const extractia: {
699
+ // Setup
700
+ setToken: typeof setToken;
701
+ configure: typeof configure;
702
+ // Auth
703
+ getMyProfile: typeof getMyProfile;
704
+ updateWebhook: typeof updateWebhook;
705
+ // Templates
706
+ getTemplates: typeof getTemplates;
707
+ getTemplateById: typeof getTemplateById;
708
+ getTemplateByName: typeof getTemplateByName;
709
+ createTemplate: typeof createTemplate;
710
+ updateTemplate: typeof updateTemplate;
711
+ deleteTemplate: typeof deleteTemplate;
712
+ deleteAllTemplateDocuments: typeof deleteAllTemplateDocuments;
713
+ suggestFields: typeof suggestFields;
714
+ // Documents
715
+ getDocumentsByTemplateId: typeof getDocumentsByTemplateId;
716
+ getDocumentById: typeof getDocumentById;
717
+ getRecentDocuments: typeof getRecentDocuments;
718
+ deleteDocument: typeof deleteDocument;
719
+ processImage: typeof processImage;
720
+ processImagesMultipage: typeof processImagesMultipage;
721
+ generateDocumentSummary: typeof generateDocumentSummary;
722
+ updateDocumentStatus: typeof updateDocumentStatus;
723
+ updateDocumentNotes: typeof updateDocumentNotes;
724
+ updateDocumentData: typeof updateDocumentData;
725
+ bulkPreconform: typeof bulkPreconform;
726
+ exportDocumentsCsv: typeof exportDocumentsCsv;
727
+ exportDocumentsJson: typeof exportDocumentsJson;
728
+ // Analytics
729
+ getCreditsBalance: typeof getCreditsBalance;
730
+ getCreditsHistory: typeof getCreditsHistory;
731
+ getDocumentHistory: typeof getDocumentHistory;
732
+ // OCR Tools
733
+ getOcrTools: typeof getOcrTools;
734
+ createOcrTool: typeof createOcrTool;
735
+ updateOcrTool: typeof updateOcrTool;
736
+ deleteOcrTool: typeof deleteOcrTool;
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;
744
+ };
745
+
746
+ export default extractia;