@opensecret/react 1.3.8 → 1.4.1

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
+ createApiKey,
51
+ listApiKeys,
52
+ deleteApiKey,
50
53
  uploadDocument,
51
54
  checkDocumentStatus,
52
55
  uploadDocumentWithPolling,
@@ -71,6 +74,9 @@ declare namespace api {
71
74
  DocumentUploadRequest,
72
75
  DocumentResponse,
73
76
  DocumentUploadInitResponse,
77
+ ApiKey,
78
+ ApiKeyCreateResponse,
79
+ ApiKeyListResponse,
74
80
  DocumentStatusRequest,
75
81
  DocumentStatusResponse
76
82
  }
@@ -124,6 +130,17 @@ export declare interface ApiEndpoint {
124
130
  context: ApiContext;
125
131
  }
126
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
+
127
144
  /**
128
145
  * Response from initiating Apple OAuth authentication
129
146
  * @property auth_url - The Apple authorization URL to redirect the user to
@@ -280,12 +297,40 @@ declare function confirmPlatformPasswordReset(email: string, alphanumericCode: s
280
297
 
281
298
  declare function convertGuestToEmailAccount(email: string, password: string, name?: string | null): Promise<void>;
282
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
+
283
324
  declare function createOrganization(name: string): Promise<Organization>;
284
325
 
285
326
  declare function createProject(orgId: string, name: string, description?: string): Promise<Project>;
286
327
 
287
328
  declare function createProjectSecret(orgId: string, projectId: string, keyName: string, secret: string): Promise<ProjectSecret>;
288
329
 
330
+ export declare interface CustomFetchOptions {
331
+ apiKey?: string;
332
+ }
333
+
289
334
  /**
290
335
  * Decrypts data that was previously encrypted with the user's key
291
336
  * @param encryptedData - Base64-encoded encrypted data string
@@ -330,6 +375,29 @@ declare type DecryptDataRequest = {
330
375
  };
331
376
  };
332
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
+
333
401
  declare function deleteOrganization(orgId: string): Promise<void>;
334
402
 
335
403
  declare function deleteOrganizationInvite(orgId: string, inviteCode: string): Promise<{
@@ -447,13 +515,14 @@ declare function fetchLogout(refresh_token: string): Promise<void>;
447
515
 
448
516
  /**
449
517
  * Fetches available AI models from the OpenAI-compatible API
518
+ * @param apiKey - Optional API key to use instead of JWT token
450
519
  * @returns A promise resolving to an array of Model objects
451
520
  * @throws {Error} If:
452
- * - The user is not authenticated
521
+ * - The user is not authenticated (no JWT token or API key)
453
522
  * - The request fails
454
523
  * - The response format is invalid
455
524
  */
456
- declare function fetchModels(): Promise<Model[]>;
525
+ declare function fetchModels(apiKey?: string): Promise<Model[]>;
457
526
 
458
527
  /**
459
528
  * Fetches the private key as a mnemonic phrase with optional derivation paths
@@ -676,6 +745,30 @@ export declare type KVListItem = {
676
745
  updated_at: number;
677
746
  };
678
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
+
679
772
  declare function listOrganizationInvites(orgId: string): Promise<OrganizationInvite[]>;
680
773
 
681
774
  declare function listOrganizationMembers(orgId: string): Promise<OrganizationMember[]>;
@@ -733,6 +826,16 @@ export declare type OpenSecretContextType = {
733
826
  * A UUID that identifies which project/tenant this instance belongs to.
734
827
  */
735
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;
736
839
  /**
737
840
  * Authenticates a user with email and password.
738
841
  *
@@ -1252,6 +1355,37 @@ export declare type OpenSecretContextType = {
1252
1355
  maxAttempts?: number;
1253
1356
  onProgress?: (status: string, progress?: number) => void;
1254
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;
1255
1389
  };
1256
1390
 
1257
1391
  /**