@opensecret/react 1.3.6 → 1.3.8

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/dist/index.d.ts CHANGED
@@ -47,6 +47,9 @@ declare namespace api {
47
47
  requestAccountDeletion,
48
48
  confirmAccountDeletion,
49
49
  fetchModels,
50
+ uploadDocument,
51
+ checkDocumentStatus,
52
+ uploadDocumentWithPolling,
50
53
  LoginResponse,
51
54
  UserResponse,
52
55
  KVListItem,
@@ -64,7 +67,12 @@ declare namespace api {
64
67
  ThirdPartyTokenResponse,
65
68
  EncryptDataRequest,
66
69
  EncryptDataResponse,
67
- DecryptDataRequest
70
+ DecryptDataRequest,
71
+ DocumentUploadRequest,
72
+ DocumentResponse,
73
+ DocumentUploadInitResponse,
74
+ DocumentStatusRequest,
75
+ DocumentStatusResponse
68
76
  }
69
77
  }
70
78
 
@@ -206,6 +214,33 @@ declare function changePlatformPassword(currentPassword: string, newPassword: st
206
214
  message: string;
207
215
  }>;
208
216
 
217
+ /**
218
+ * Checks the status of a document processing task
219
+ * @param taskId - The task ID returned from uploadDocument
220
+ * @returns A promise resolving to the current status and optionally the processed document
221
+ * @throws {Error} If:
222
+ * - The user is not authenticated
223
+ * - The task ID is not found (404)
224
+ * - The user doesn't have access to the task (403)
225
+ *
226
+ * @description
227
+ * This function checks the status of an async document processing task.
228
+ * Status values include:
229
+ * - "pending": Document is queued for processing
230
+ * - "started": Document processing has begun
231
+ * - "success": Processing completed successfully (document field will be populated)
232
+ * - "failure": Processing failed (error field will contain details)
233
+ *
234
+ * Example usage:
235
+ * ```typescript
236
+ * const status = await checkDocumentStatus(taskId);
237
+ * if (status.status === "success" && status.document) {
238
+ * console.log(status.document.text);
239
+ * }
240
+ * ```
241
+ */
242
+ declare function checkDocumentStatus(taskId: string): Promise<DocumentStatusResponse>;
243
+
209
244
  /**
210
245
  * Confirms and completes the account deletion process
211
246
  * @param confirmationCode - The confirmation code from the verification email
@@ -311,6 +346,34 @@ declare type DeveloperResponse = PlatformUser & {
311
346
 
312
347
  export declare type DeveloperRole = "owner" | "admin" | "developer" | "viewer";
313
348
 
349
+ export declare type DocumentResponse = {
350
+ text: string;
351
+ filename: string;
352
+ size: number;
353
+ };
354
+
355
+ export declare type DocumentStatusRequest = {
356
+ task_id: string;
357
+ };
358
+
359
+ export declare type DocumentStatusResponse = {
360
+ status: string;
361
+ progress?: number;
362
+ error?: string;
363
+ document?: DocumentResponse;
364
+ };
365
+
366
+ export declare type DocumentUploadInitResponse = {
367
+ task_id: string;
368
+ filename: string;
369
+ size: number;
370
+ };
371
+
372
+ declare type DocumentUploadRequest = {
373
+ filename: string;
374
+ content_base64: string;
375
+ };
376
+
314
377
  declare type EmailSettings = {
315
378
  provider: string;
316
379
  send_from: string;
@@ -1101,6 +1164,94 @@ export declare type OpenSecretContextType = {
1101
1164
  * - Requires an active authentication session
1102
1165
  */
1103
1166
  fetchModels: () => Promise<Model[]>;
1167
+ /**
1168
+ * Uploads a document for text extraction and processing
1169
+ * @param file - The file to upload (File or Blob object)
1170
+ * @returns A promise resolving to the task ID and initial metadata
1171
+ * @throws {Error} If:
1172
+ * - The file exceeds 10MB size limit
1173
+ * - The user is not authenticated (or is a guest user)
1174
+ * - Usage limits are exceeded (403)
1175
+ * - Processing fails (500)
1176
+ *
1177
+ * @description
1178
+ * This function uploads a document to the Tinfoil processing service which:
1179
+ * 1. Accepts the document and returns a task ID immediately
1180
+ * 2. Processes the document asynchronously in the background
1181
+ * 3. Maintains end-to-end encryption using session keys
1182
+ *
1183
+ * Common supported formats include PDF, DOCX, XLSX, PPTX, TXT, RTF, and more.
1184
+ * Guest users will receive a 401 Unauthorized error.
1185
+ *
1186
+ * Example usage:
1187
+ * ```typescript
1188
+ * const file = new File(["content"], "document.pdf", { type: "application/pdf" });
1189
+ * const result = await context.uploadDocument(file);
1190
+ * console.log(result.task_id); // Task ID to check status
1191
+ * ```
1192
+ */
1193
+ uploadDocument: (file: File | Blob) => Promise<api.DocumentUploadInitResponse>;
1194
+ /**
1195
+ * Checks the status of a document processing task
1196
+ * @param taskId - The task ID returned from uploadDocument
1197
+ * @returns A promise resolving to the current status and optionally the processed document
1198
+ * @throws {Error} If:
1199
+ * - The user is not authenticated
1200
+ * - The task ID is not found (404)
1201
+ * - The user doesn't have access to the task (403)
1202
+ *
1203
+ * @description
1204
+ * This function checks the status of an async document processing task.
1205
+ * Status values include:
1206
+ * - "pending": Document is queued for processing
1207
+ * - "started": Document processing has begun
1208
+ * - "success": Processing completed successfully (document field will be populated)
1209
+ * - "failure": Processing failed (error field will contain details)
1210
+ *
1211
+ * Example usage:
1212
+ * ```typescript
1213
+ * const status = await context.checkDocumentStatus(taskId);
1214
+ * if (status.status === "success" && status.document) {
1215
+ * console.log(status.document.text);
1216
+ * }
1217
+ * ```
1218
+ */
1219
+ checkDocumentStatus: (taskId: string) => Promise<api.DocumentStatusResponse>;
1220
+ /**
1221
+ * Uploads a document and polls for completion
1222
+ * @param file - The file to upload (File or Blob object)
1223
+ * @param options - Optional configuration for polling behavior
1224
+ * @returns A promise resolving to the processed document
1225
+ * @throws {Error} If:
1226
+ * - Upload fails (see uploadDocument errors)
1227
+ * - Processing fails (error from server)
1228
+ * - Processing times out (exceeds maxAttempts)
1229
+ *
1230
+ * @description
1231
+ * This is a convenience function that combines uploadDocument and checkDocumentStatus
1232
+ * to provide a simple interface that handles the async processing automatically.
1233
+ *
1234
+ * Options:
1235
+ * - pollInterval: Time between status checks in milliseconds (default: 2000)
1236
+ * - maxAttempts: Maximum number of status checks before timeout (default: 150 = 5 minutes)
1237
+ * - onProgress: Callback function called on each status update
1238
+ *
1239
+ * Example usage:
1240
+ * ```typescript
1241
+ * const file = new File(["content"], "document.pdf", { type: "application/pdf" });
1242
+ * const result = await context.uploadDocumentWithPolling(file, {
1243
+ * onProgress: (status, progress) => {
1244
+ * console.log(`Status: ${status}, Progress: ${progress || 0}%`);
1245
+ * }
1246
+ * });
1247
+ * console.log(result.text);
1248
+ * ```
1249
+ */
1250
+ uploadDocumentWithPolling: (file: File | Blob, options?: {
1251
+ pollInterval?: number;
1252
+ maxAttempts?: number;
1253
+ onProgress?: (status: string, progress?: number) => void;
1254
+ }) => Promise<DocumentResponse>;
1104
1255
  };
1105
1256
 
1106
1257
  /**
@@ -1857,6 +2008,72 @@ declare function updateProject(orgId: string, projectId: string, updates: {
1857
2008
  status?: string;
1858
2009
  }): Promise<Project>;
1859
2010
 
2011
+ /**
2012
+ * Uploads a document for text extraction and processing
2013
+ * @param file - The file to upload (File or Blob object)
2014
+ * @returns A promise resolving to the task ID and initial metadata
2015
+ * @throws {Error} If:
2016
+ * - The file exceeds 10MB size limit
2017
+ * - The user is not authenticated
2018
+ * - The user is a guest (401)
2019
+ * - Usage limits are exceeded (403)
2020
+ * - Processing fails (500)
2021
+ *
2022
+ * @description
2023
+ * This function uploads a document to the Tinfoil processing service which:
2024
+ * 1. Accepts the document and returns a task ID immediately
2025
+ * 2. Processes the document asynchronously in the background
2026
+ * 3. Maintains end-to-end encryption using session keys
2027
+ *
2028
+ * The file is converted to base64 before upload due to encryption requirements.
2029
+ * Common supported formats include PDF, DOCX, XLSX, PPTX, TXT, RTF, and more.
2030
+ *
2031
+ * Example usage:
2032
+ * ```typescript
2033
+ * const file = new File(["content"], "document.pdf", { type: "application/pdf" });
2034
+ * const result = await uploadDocument(file);
2035
+ * console.log(result.task_id); // Task ID to check status
2036
+ * ```
2037
+ */
2038
+ declare function uploadDocument(file: File | Blob): Promise<DocumentUploadInitResponse>;
2039
+
2040
+ /**
2041
+ * Uploads a document and polls for completion
2042
+ * @param file - The file to upload (File or Blob object)
2043
+ * @param options - Optional configuration for polling behavior
2044
+ * @returns A promise resolving to the processed document
2045
+ * @throws {Error} If:
2046
+ * - Upload fails (see uploadDocument errors)
2047
+ * - Processing fails (error from server)
2048
+ * - Processing times out (exceeds maxAttempts)
2049
+ *
2050
+ * @description
2051
+ * This is a convenience function that combines uploadDocument and checkDocumentStatus
2052
+ * to provide a simple interface that handles the async processing automatically.
2053
+ * It uploads the document, then polls the status endpoint until processing completes.
2054
+ *
2055
+ * Options:
2056
+ * - pollInterval: Time between status checks in milliseconds (default: 2000)
2057
+ * - maxAttempts: Maximum number of status checks before timeout (default: 150 = 5 minutes)
2058
+ * - onProgress: Callback function called on each status update
2059
+ *
2060
+ * Example usage:
2061
+ * ```typescript
2062
+ * const file = new File(["content"], "document.pdf", { type: "application/pdf" });
2063
+ * const result = await uploadDocumentWithPolling(file, {
2064
+ * onProgress: (status, progress) => {
2065
+ * console.log(`Status: ${status}, Progress: ${progress || 0}%`);
2066
+ * }
2067
+ * });
2068
+ * console.log(result.text);
2069
+ * ```
2070
+ */
2071
+ declare function uploadDocumentWithPolling(file: File | Blob, options?: {
2072
+ pollInterval?: number;
2073
+ maxAttempts?: number;
2074
+ onProgress?: (status: string, progress?: number) => void;
2075
+ }): Promise<DocumentResponse>;
2076
+
1860
2077
  export declare function useOpenSecret(): OpenSecretContextType;
1861
2078
 
1862
2079
  export declare function useOpenSecretDeveloper(): OpenSecretDeveloperContextType;