@opensecret/react 1.3.7 → 1.4.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/dist/index.d.ts CHANGED
@@ -47,7 +47,12 @@ declare namespace api {
47
47
  requestAccountDeletion,
48
48
  confirmAccountDeletion,
49
49
  fetchModels,
50
+ createApiKey,
51
+ listApiKeys,
52
+ deleteApiKey,
50
53
  uploadDocument,
54
+ checkDocumentStatus,
55
+ uploadDocumentWithPolling,
51
56
  LoginResponse,
52
57
  UserResponse,
53
58
  KVListItem,
@@ -67,7 +72,13 @@ declare namespace api {
67
72
  EncryptDataResponse,
68
73
  DecryptDataRequest,
69
74
  DocumentUploadRequest,
70
- DocumentResponse
75
+ DocumentResponse,
76
+ DocumentUploadInitResponse,
77
+ ApiKey,
78
+ ApiKeyCreateResponse,
79
+ ApiKeyListResponse,
80
+ DocumentStatusRequest,
81
+ DocumentStatusResponse
71
82
  }
72
83
  }
73
84
 
@@ -119,6 +130,17 @@ export declare interface ApiEndpoint {
119
130
  context: ApiContext;
120
131
  }
121
132
 
133
+ export declare type ApiKey = {
134
+ name: string;
135
+ created_at: string;
136
+ };
137
+
138
+ export declare type ApiKeyCreateResponse = ApiKey & {
139
+ key: string;
140
+ };
141
+
142
+ export declare type ApiKeyListResponse = ApiKey[];
143
+
122
144
  /**
123
145
  * Response from initiating Apple OAuth authentication
124
146
  * @property auth_url - The Apple authorization URL to redirect the user to
@@ -209,6 +231,33 @@ declare function changePlatformPassword(currentPassword: string, newPassword: st
209
231
  message: string;
210
232
  }>;
211
233
 
234
+ /**
235
+ * Checks the status of a document processing task
236
+ * @param taskId - The task ID returned from uploadDocument
237
+ * @returns A promise resolving to the current status and optionally the processed document
238
+ * @throws {Error} If:
239
+ * - The user is not authenticated
240
+ * - The task ID is not found (404)
241
+ * - The user doesn't have access to the task (403)
242
+ *
243
+ * @description
244
+ * This function checks the status of an async document processing task.
245
+ * Status values include:
246
+ * - "pending": Document is queued for processing
247
+ * - "started": Document processing has begun
248
+ * - "success": Processing completed successfully (document field will be populated)
249
+ * - "failure": Processing failed (error field will contain details)
250
+ *
251
+ * Example usage:
252
+ * ```typescript
253
+ * const status = await checkDocumentStatus(taskId);
254
+ * if (status.status === "success" && status.document) {
255
+ * console.log(status.document.text);
256
+ * }
257
+ * ```
258
+ */
259
+ declare function checkDocumentStatus(taskId: string): Promise<DocumentStatusResponse>;
260
+
212
261
  /**
213
262
  * Confirms and completes the account deletion process
214
263
  * @param confirmationCode - The confirmation code from the verification email
@@ -248,12 +297,40 @@ declare function confirmPlatformPasswordReset(email: string, alphanumericCode: s
248
297
 
249
298
  declare function convertGuestToEmailAccount(email: string, password: string, name?: string | null): Promise<void>;
250
299
 
300
+ /**
301
+ * Creates a new API key for the authenticated user
302
+ * @param name - A descriptive name for the API key
303
+ * @returns A promise resolving to the API key details with the key value (only shown once)
304
+ * @throws {Error} If:
305
+ * - The user is not authenticated
306
+ * - The name is invalid
307
+ * - The request fails
308
+ *
309
+ * @description
310
+ * IMPORTANT: The `key` field is only returned once during creation and cannot be retrieved again.
311
+ * The SDK consumer should prompt users to save the key immediately.
312
+ *
313
+ * Example usage:
314
+ * ```typescript
315
+ * const apiKey = await createApiKey("Production Key");
316
+ * console.log(apiKey.key); // UUID format: 550e8400-e29b-41d4-a716-446655440000
317
+ * // Save this key securely - it won't be shown again!
318
+ * ```
319
+ */
320
+ export declare function createApiKey(name: string): Promise<ApiKeyCreateResponse>;
321
+
322
+ export declare function createCustomFetch(options?: CustomFetchOptions): (url: RequestInfo, init?: RequestInit) => Promise<Response>;
323
+
251
324
  declare function createOrganization(name: string): Promise<Organization>;
252
325
 
253
326
  declare function createProject(orgId: string, name: string, description?: string): Promise<Project>;
254
327
 
255
328
  declare function createProjectSecret(orgId: string, projectId: string, keyName: string, secret: string): Promise<ProjectSecret>;
256
329
 
330
+ export declare interface CustomFetchOptions {
331
+ apiKey?: string;
332
+ }
333
+
257
334
  /**
258
335
  * Decrypts data that was previously encrypted with the user's key
259
336
  * @param encryptedData - Base64-encoded encrypted data string
@@ -298,6 +375,29 @@ declare type DecryptDataRequest = {
298
375
  };
299
376
  };
300
377
 
378
+ /**
379
+ * Deletes an API key by its name
380
+ * @param name - The name of the API key to delete
381
+ * @returns A promise resolving to void
382
+ * @throws {Error} If:
383
+ * - The user is not authenticated
384
+ * - The API key with this name is not found
385
+ * - The user doesn't own the API key
386
+ * - The request fails
387
+ *
388
+ * @description
389
+ * Permanently deletes an API key. This action cannot be undone.
390
+ * Any requests using the deleted key will immediately fail with 401 Unauthorized.
391
+ * Names are unique per user, so this uniquely identifies the key to delete.
392
+ *
393
+ * Example usage:
394
+ * ```typescript
395
+ * await deleteApiKey("Production Key");
396
+ * console.log("API key deleted successfully");
397
+ * ```
398
+ */
399
+ export declare function deleteApiKey(name: string): Promise<void>;
400
+
301
401
  declare function deleteOrganization(orgId: string): Promise<void>;
302
402
 
303
403
  declare function deleteOrganizationInvite(orgId: string, inviteCode: string): Promise<{
@@ -320,6 +420,23 @@ export declare type DocumentResponse = {
320
420
  size: number;
321
421
  };
322
422
 
423
+ export declare type DocumentStatusRequest = {
424
+ task_id: string;
425
+ };
426
+
427
+ export declare type DocumentStatusResponse = {
428
+ status: string;
429
+ progress?: number;
430
+ error?: string;
431
+ document?: DocumentResponse;
432
+ };
433
+
434
+ export declare type DocumentUploadInitResponse = {
435
+ task_id: string;
436
+ filename: string;
437
+ size: number;
438
+ };
439
+
323
440
  declare type DocumentUploadRequest = {
324
441
  filename: string;
325
442
  content_base64: string;
@@ -398,13 +515,14 @@ declare function fetchLogout(refresh_token: string): Promise<void>;
398
515
 
399
516
  /**
400
517
  * Fetches available AI models from the OpenAI-compatible API
518
+ * @param apiKey - Optional API key to use instead of JWT token
401
519
  * @returns A promise resolving to an array of Model objects
402
520
  * @throws {Error} If:
403
- * - The user is not authenticated
521
+ * - The user is not authenticated (no JWT token or API key)
404
522
  * - The request fails
405
523
  * - The response format is invalid
406
524
  */
407
- declare function fetchModels(): Promise<Model[]>;
525
+ declare function fetchModels(apiKey?: string): Promise<Model[]>;
408
526
 
409
527
  /**
410
528
  * Fetches the private key as a mnemonic phrase with optional derivation paths
@@ -627,6 +745,30 @@ export declare type KVListItem = {
627
745
  updated_at: number;
628
746
  };
629
747
 
748
+ /**
749
+ * Lists all API keys for the authenticated user
750
+ * @returns A promise resolving to an object containing an array of API key metadata (without the actual keys)
751
+ * @throws {Error} If:
752
+ * - The user is not authenticated
753
+ * - The request fails
754
+ *
755
+ * @description
756
+ * Returns metadata about all API keys associated with the user's account.
757
+ * Note that the actual key values are never returned - they are only shown once during creation.
758
+ * The keys are sorted by created_at in descending order (newest first).
759
+ *
760
+ * Example usage:
761
+ * ```typescript
762
+ * const response = await listApiKeys();
763
+ * response.keys.forEach(key => {
764
+ * console.log(`${key.name} created at ${key.created_at}`);
765
+ * });
766
+ * ```
767
+ */
768
+ export declare function listApiKeys(): Promise<{
769
+ keys: ApiKeyListResponse;
770
+ }>;
771
+
630
772
  declare function listOrganizationInvites(orgId: string): Promise<OrganizationInvite[]>;
631
773
 
632
774
  declare function listOrganizationMembers(orgId: string): Promise<OrganizationMember[]>;
@@ -684,6 +826,16 @@ export declare type OpenSecretContextType = {
684
826
  * A UUID that identifies which project/tenant this instance belongs to.
685
827
  */
686
828
  clientId: string;
829
+ /**
830
+ * Optional API key for OpenAI endpoints.
831
+ * When set, this will be used instead of JWT for /v1/* endpoints.
832
+ */
833
+ apiKey?: string;
834
+ /**
835
+ * Sets the API key to use for OpenAI endpoints.
836
+ * @param key - The API key (UUID format) or undefined to clear
837
+ */
838
+ setApiKey: (key: string | undefined) => void;
687
839
  /**
688
840
  * Authenticates a user with email and password.
689
841
  *
@@ -1118,7 +1270,7 @@ export declare type OpenSecretContextType = {
1118
1270
  /**
1119
1271
  * Uploads a document for text extraction and processing
1120
1272
  * @param file - The file to upload (File or Blob object)
1121
- * @returns A promise resolving to the extracted document text and metadata
1273
+ * @returns A promise resolving to the task ID and initial metadata
1122
1274
  * @throws {Error} If:
1123
1275
  * - The file exceeds 10MB size limit
1124
1276
  * - The user is not authenticated (or is a guest user)
@@ -1127,8 +1279,8 @@ export declare type OpenSecretContextType = {
1127
1279
  *
1128
1280
  * @description
1129
1281
  * This function uploads a document to the Tinfoil processing service which:
1130
- * 1. Extracts text from various document formats (PDF, DOCX, TXT, etc.)
1131
- * 2. Returns the extracted text ready for use in chat prompts
1282
+ * 1. Accepts the document and returns a task ID immediately
1283
+ * 2. Processes the document asynchronously in the background
1132
1284
  * 3. Maintains end-to-end encryption using session keys
1133
1285
  *
1134
1286
  * Common supported formats include PDF, DOCX, XLSX, PPTX, TXT, RTF, and more.
@@ -1138,10 +1290,102 @@ export declare type OpenSecretContextType = {
1138
1290
  * ```typescript
1139
1291
  * const file = new File(["content"], "document.pdf", { type: "application/pdf" });
1140
1292
  * const result = await context.uploadDocument(file);
1141
- * console.log(result.text); // Extracted text from the document
1293
+ * console.log(result.task_id); // Task ID to check status
1294
+ * ```
1295
+ */
1296
+ uploadDocument: (file: File | Blob) => Promise<api.DocumentUploadInitResponse>;
1297
+ /**
1298
+ * Checks the status of a document processing task
1299
+ * @param taskId - The task ID returned from uploadDocument
1300
+ * @returns A promise resolving to the current status and optionally the processed document
1301
+ * @throws {Error} If:
1302
+ * - The user is not authenticated
1303
+ * - The task ID is not found (404)
1304
+ * - The user doesn't have access to the task (403)
1305
+ *
1306
+ * @description
1307
+ * This function checks the status of an async document processing task.
1308
+ * Status values include:
1309
+ * - "pending": Document is queued for processing
1310
+ * - "started": Document processing has begun
1311
+ * - "success": Processing completed successfully (document field will be populated)
1312
+ * - "failure": Processing failed (error field will contain details)
1313
+ *
1314
+ * Example usage:
1315
+ * ```typescript
1316
+ * const status = await context.checkDocumentStatus(taskId);
1317
+ * if (status.status === "success" && status.document) {
1318
+ * console.log(status.document.text);
1319
+ * }
1142
1320
  * ```
1143
1321
  */
1144
- uploadDocument: (file: File | Blob) => Promise<DocumentResponse>;
1322
+ checkDocumentStatus: (taskId: string) => Promise<api.DocumentStatusResponse>;
1323
+ /**
1324
+ * Uploads a document and polls for completion
1325
+ * @param file - The file to upload (File or Blob object)
1326
+ * @param options - Optional configuration for polling behavior
1327
+ * @returns A promise resolving to the processed document
1328
+ * @throws {Error} If:
1329
+ * - Upload fails (see uploadDocument errors)
1330
+ * - Processing fails (error from server)
1331
+ * - Processing times out (exceeds maxAttempts)
1332
+ *
1333
+ * @description
1334
+ * This is a convenience function that combines uploadDocument and checkDocumentStatus
1335
+ * to provide a simple interface that handles the async processing automatically.
1336
+ *
1337
+ * Options:
1338
+ * - pollInterval: Time between status checks in milliseconds (default: 2000)
1339
+ * - maxAttempts: Maximum number of status checks before timeout (default: 150 = 5 minutes)
1340
+ * - onProgress: Callback function called on each status update
1341
+ *
1342
+ * Example usage:
1343
+ * ```typescript
1344
+ * const file = new File(["content"], "document.pdf", { type: "application/pdf" });
1345
+ * const result = await context.uploadDocumentWithPolling(file, {
1346
+ * onProgress: (status, progress) => {
1347
+ * console.log(`Status: ${status}, Progress: ${progress || 0}%`);
1348
+ * }
1349
+ * });
1350
+ * console.log(result.text);
1351
+ * ```
1352
+ */
1353
+ uploadDocumentWithPolling: (file: File | Blob, options?: {
1354
+ pollInterval?: number;
1355
+ maxAttempts?: number;
1356
+ onProgress?: (status: string, progress?: number) => void;
1357
+ }) => Promise<DocumentResponse>;
1358
+ /**
1359
+ * Creates a new API key for the authenticated user
1360
+ * @param name - A descriptive name for the API key
1361
+ * @returns A promise resolving to the API key details with the key value (only shown once)
1362
+ * @throws {Error} If the user is not authenticated or the request fails
1363
+ *
1364
+ * IMPORTANT: The `key` field is only returned once during creation and cannot be retrieved again.
1365
+ * The SDK consumer should prompt users to save the key immediately.
1366
+ */
1367
+ createApiKey: typeof api.createApiKey;
1368
+ /**
1369
+ * Lists all API keys for the authenticated user
1370
+ * @returns A promise resolving to an object containing an array of API key metadata (without the actual keys)
1371
+ * @throws {Error} If the user is not authenticated or the request fails
1372
+ *
1373
+ * Returns metadata about all API keys associated with the user's account.
1374
+ * Note that the actual key values are never returned - they are only shown once during creation.
1375
+ * The keys are sorted by created_at in descending order (newest first).
1376
+ */
1377
+ listApiKeys: typeof api.listApiKeys;
1378
+ /**
1379
+ * Deletes an API key by its name
1380
+ * @param name - The name of the API key to delete
1381
+ * @returns A promise that resolves when the key is deleted
1382
+ * @throws {Error} If the user is not authenticated or the API key is not found
1383
+ *
1384
+ * Permanently deletes an API key. This action cannot be undone.
1385
+ * Any requests using the deleted key will immediately fail with 401 Unauthorized.
1386
+ * Names are unique per user, so this uniquely identifies the key to delete.
1387
+ */
1388
+ deleteApiKey: typeof api.deleteApiKey;
1145
1389
  };
1146
1390
 
1147
1391
  /**
@@ -1901,7 +2145,7 @@ declare function updateProject(orgId: string, projectId: string, updates: {
1901
2145
  /**
1902
2146
  * Uploads a document for text extraction and processing
1903
2147
  * @param file - The file to upload (File or Blob object)
1904
- * @returns A promise resolving to the extracted document text and metadata
2148
+ * @returns A promise resolving to the task ID and initial metadata
1905
2149
  * @throws {Error} If:
1906
2150
  * - The file exceeds 10MB size limit
1907
2151
  * - The user is not authenticated
@@ -1911,8 +2155,8 @@ declare function updateProject(orgId: string, projectId: string, updates: {
1911
2155
  *
1912
2156
  * @description
1913
2157
  * This function uploads a document to the Tinfoil processing service which:
1914
- * 1. Extracts text from various document formats (PDF, DOCX, TXT, etc.)
1915
- * 2. Returns the extracted text ready for use in chat prompts
2158
+ * 1. Accepts the document and returns a task ID immediately
2159
+ * 2. Processes the document asynchronously in the background
1916
2160
  * 3. Maintains end-to-end encryption using session keys
1917
2161
  *
1918
2162
  * The file is converted to base64 before upload due to encryption requirements.
@@ -1922,10 +2166,47 @@ declare function updateProject(orgId: string, projectId: string, updates: {
1922
2166
  * ```typescript
1923
2167
  * const file = new File(["content"], "document.pdf", { type: "application/pdf" });
1924
2168
  * const result = await uploadDocument(file);
1925
- * console.log(result.text); // Extracted text from the document
2169
+ * console.log(result.task_id); // Task ID to check status
2170
+ * ```
2171
+ */
2172
+ declare function uploadDocument(file: File | Blob): Promise<DocumentUploadInitResponse>;
2173
+
2174
+ /**
2175
+ * Uploads a document and polls for completion
2176
+ * @param file - The file to upload (File or Blob object)
2177
+ * @param options - Optional configuration for polling behavior
2178
+ * @returns A promise resolving to the processed document
2179
+ * @throws {Error} If:
2180
+ * - Upload fails (see uploadDocument errors)
2181
+ * - Processing fails (error from server)
2182
+ * - Processing times out (exceeds maxAttempts)
2183
+ *
2184
+ * @description
2185
+ * This is a convenience function that combines uploadDocument and checkDocumentStatus
2186
+ * to provide a simple interface that handles the async processing automatically.
2187
+ * It uploads the document, then polls the status endpoint until processing completes.
2188
+ *
2189
+ * Options:
2190
+ * - pollInterval: Time between status checks in milliseconds (default: 2000)
2191
+ * - maxAttempts: Maximum number of status checks before timeout (default: 150 = 5 minutes)
2192
+ * - onProgress: Callback function called on each status update
2193
+ *
2194
+ * Example usage:
2195
+ * ```typescript
2196
+ * const file = new File(["content"], "document.pdf", { type: "application/pdf" });
2197
+ * const result = await uploadDocumentWithPolling(file, {
2198
+ * onProgress: (status, progress) => {
2199
+ * console.log(`Status: ${status}, Progress: ${progress || 0}%`);
2200
+ * }
2201
+ * });
2202
+ * console.log(result.text);
1926
2203
  * ```
1927
2204
  */
1928
- declare function uploadDocument(file: File | Blob): Promise<DocumentResponse>;
2205
+ declare function uploadDocumentWithPolling(file: File | Blob, options?: {
2206
+ pollInterval?: number;
2207
+ maxAttempts?: number;
2208
+ onProgress?: (status: string, progress?: number) => void;
2209
+ }): Promise<DocumentResponse>;
1929
2210
 
1930
2211
  export declare function useOpenSecret(): OpenSecretContextType;
1931
2212