@prmichaelsen/firebase-admin-sdk-v8 2.0.21 → 2.1.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.mts CHANGED
@@ -195,6 +195,7 @@ interface BatchWriteResult {
195
195
  interface SDKConfig {
196
196
  serviceAccount?: ServiceAccount | string;
197
197
  projectId?: string;
198
+ apiKey?: string;
198
199
  }
199
200
  /**
200
201
  * Initialize the Firebase Admin SDK with configuration
@@ -250,6 +251,21 @@ declare function getProjectId(): string;
250
251
  * ID token verification supporting both Firebase v9 and v10 token formats
251
252
  */
252
253
 
254
+ /**
255
+ * Custom claims for custom tokens
256
+ */
257
+ interface CustomClaims {
258
+ [key: string]: any;
259
+ }
260
+ /**
261
+ * Response from signInWithCustomToken
262
+ */
263
+ interface CustomTokenSignInResponse {
264
+ idToken: string;
265
+ refreshToken: string;
266
+ expiresIn: string;
267
+ localId: string;
268
+ }
253
269
  /**
254
270
  * Verify a Firebase ID token
255
271
  * Supports both Firebase v9 (securetoken) and v10 (session) token formats
@@ -280,6 +296,45 @@ declare function verifyIdToken(idToken: string): Promise<DecodedIdToken>;
280
296
  * ```
281
297
  */
282
298
  declare function getUserFromToken(idToken: string): Promise<UserInfo>;
299
+ /**
300
+ * Create a custom token for a user
301
+ *
302
+ * @param uid - User ID
303
+ * @param customClaims - Optional custom claims to include in token
304
+ * @returns Custom JWT token
305
+ *
306
+ * @example
307
+ * ```typescript
308
+ * // Create token with custom claims
309
+ * const token = await createCustomToken('user123', {
310
+ * role: 'admin',
311
+ * premium: true,
312
+ * });
313
+ *
314
+ * // Use token on client to sign in
315
+ * await signInWithCustomToken(auth, token);
316
+ * ```
317
+ */
318
+ declare function createCustomToken(uid: string, customClaims?: CustomClaims): Promise<string>;
319
+ /**
320
+ * Exchange a custom token for an ID token and refresh token
321
+ *
322
+ * @param customToken - Custom JWT token created with createCustomToken
323
+ * @returns User credentials (idToken, refreshToken, expiresIn, localId)
324
+ *
325
+ * @example
326
+ * ```typescript
327
+ * // Server-side: Create custom token
328
+ * const customToken = await createCustomToken('user123', { role: 'admin' });
329
+ *
330
+ * // Exchange for ID token
331
+ * const credentials = await signInWithCustomToken(customToken);
332
+ *
333
+ * // Use ID token for authenticated requests
334
+ * const user = await verifyIdToken(credentials.idToken);
335
+ * ```
336
+ */
337
+ declare function signInWithCustomToken(customToken: string): Promise<CustomTokenSignInResponse>;
283
338
  /**
284
339
  * Get Auth instance (for compatibility, but not used in new implementation)
285
340
  * @deprecated Use verifyIdToken directly
@@ -425,6 +480,189 @@ declare function queryDocuments(collectionPath: string, options?: QueryOptions):
425
480
  */
426
481
  declare function batchWrite(operations: BatchWrite[]): Promise<BatchWriteResult>;
427
482
 
483
+ /**
484
+ * Firebase Storage client using Google Cloud Storage REST API
485
+ * Compatible with edge runtimes (Cloudflare Workers, Vercel Edge, etc.)
486
+ */
487
+ /**
488
+ * Options for uploading files
489
+ */
490
+ interface UploadOptions {
491
+ contentType?: string;
492
+ metadata?: Record<string, string>;
493
+ public?: boolean;
494
+ }
495
+ /**
496
+ * Options for downloading files
497
+ */
498
+ interface DownloadOptions {
499
+ responseType?: 'arraybuffer' | 'blob';
500
+ }
501
+ /**
502
+ * Options for listing files
503
+ */
504
+ interface ListOptions {
505
+ prefix?: string;
506
+ delimiter?: string;
507
+ maxResults?: number;
508
+ pageToken?: string;
509
+ }
510
+ /**
511
+ * File metadata returned by Storage API
512
+ */
513
+ interface FileMetadata {
514
+ name: string;
515
+ bucket: string;
516
+ size: string;
517
+ contentType: string;
518
+ timeCreated: string;
519
+ updated: string;
520
+ md5Hash: string;
521
+ metadata?: Record<string, string>;
522
+ }
523
+ /**
524
+ * Result of listing files
525
+ */
526
+ interface ListFilesResult {
527
+ files: FileMetadata[];
528
+ nextPageToken?: string;
529
+ }
530
+ /**
531
+ * Upload a file to Firebase Storage
532
+ *
533
+ * @param path - File path in storage (e.g., 'images/photo.jpg')
534
+ * @param data - File data as ArrayBuffer, Uint8Array, or Blob
535
+ * @param options - Upload options (contentType, metadata, public)
536
+ * @returns File metadata
537
+ *
538
+ * @example
539
+ * ```typescript
540
+ * const data = new TextEncoder().encode('Hello, Storage!');
541
+ * const metadata = await uploadFile('files/hello.txt', data, {
542
+ * contentType: 'text/plain',
543
+ * metadata: { userId: '123' },
544
+ * });
545
+ * ```
546
+ */
547
+ declare function uploadFile(path: string, data: ArrayBuffer | Uint8Array | Blob, options?: UploadOptions): Promise<FileMetadata>;
548
+ /**
549
+ * Download a file from Firebase Storage
550
+ *
551
+ * @param path - File path in storage
552
+ * @param options - Download options
553
+ * @returns File data as ArrayBuffer
554
+ *
555
+ * @example
556
+ * ```typescript
557
+ * const data = await downloadFile('files/hello.txt');
558
+ * const text = new TextDecoder().decode(data);
559
+ * console.log(text); // "Hello, Storage!"
560
+ * ```
561
+ */
562
+ declare function downloadFile(path: string, _options?: DownloadOptions): Promise<ArrayBuffer>;
563
+ /**
564
+ * Delete a file from Firebase Storage
565
+ *
566
+ * @param path - File path in storage
567
+ *
568
+ * @example
569
+ * ```typescript
570
+ * await deleteFile('files/hello.txt');
571
+ * ```
572
+ */
573
+ declare function deleteFile(path: string): Promise<void>;
574
+ /**
575
+ * Get file metadata from Firebase Storage
576
+ *
577
+ * @param path - File path in storage
578
+ * @returns File metadata
579
+ *
580
+ * @example
581
+ * ```typescript
582
+ * const metadata = await getFileMetadata('files/hello.txt');
583
+ * console.log(metadata.size, metadata.contentType);
584
+ * ```
585
+ */
586
+ declare function getFileMetadata(path: string): Promise<FileMetadata>;
587
+ /**
588
+ * List files in Firebase Storage
589
+ *
590
+ * @param options - List options (prefix, delimiter, maxResults, pageToken)
591
+ * @returns List of files and optional next page token
592
+ *
593
+ * @example
594
+ * ```typescript
595
+ * // List all files with prefix
596
+ * const { files } = await listFiles({ prefix: 'images/' });
597
+ *
598
+ * // List with pagination
599
+ * const { files, nextPageToken } = await listFiles({ maxResults: 10 });
600
+ * if (nextPageToken) {
601
+ * const nextPage = await listFiles({ pageToken: nextPageToken });
602
+ * }
603
+ * ```
604
+ */
605
+ declare function listFiles(options?: ListOptions): Promise<ListFilesResult>;
606
+ /**
607
+ * Check if a file exists in Firebase Storage
608
+ *
609
+ * @param path - File path in storage
610
+ * @returns True if file exists, false otherwise
611
+ *
612
+ * @example
613
+ * ```typescript
614
+ * if (await fileExists('files/hello.txt')) {
615
+ * console.log('File exists!');
616
+ * }
617
+ * ```
618
+ */
619
+ declare function fileExists(path: string): Promise<boolean>;
620
+
621
+ /**
622
+ * Generate signed URLs for temporary access to Firebase Storage files
623
+ * Uses Google Cloud Storage V4 signing process
624
+ */
625
+ /**
626
+ * Options for generating signed URLs
627
+ */
628
+ interface SignedUrlOptions {
629
+ action: 'read' | 'write' | 'delete';
630
+ expires: Date | number;
631
+ contentType?: string;
632
+ responseDisposition?: string;
633
+ responseType?: string;
634
+ }
635
+ /**
636
+ * Generate a signed URL for temporary access to a Storage file
637
+ *
638
+ * Uses Google Cloud Storage V4 signing process
639
+ *
640
+ * @param path - File path in storage (e.g., 'images/photo.jpg')
641
+ * @param options - Signed URL options
642
+ * @returns Signed URL that can be used without authentication
643
+ *
644
+ * @example
645
+ * ```typescript
646
+ * // Generate read URL valid for 1 hour
647
+ * const url = await generateSignedUrl('files/hello.txt', {
648
+ * action: 'read',
649
+ * expires: 3600,
650
+ * });
651
+ *
652
+ * // Generate write URL with content type
653
+ * const uploadUrl = await generateSignedUrl('files/upload.jpg', {
654
+ * action: 'write',
655
+ * expires: 1800, // 30 minutes
656
+ * contentType: 'image/jpeg',
657
+ * });
658
+ *
659
+ * // Use the URL (no auth needed)
660
+ * const response = await fetch(url);
661
+ * const data = await response.arrayBuffer();
662
+ * ```
663
+ */
664
+ declare function generateSignedUrl(path: string, options: SignedUrlOptions): Promise<string>;
665
+
428
666
  /**
429
667
  * Firebase Admin SDK v8 - Field Value Helpers
430
668
  * Special field values for Firestore operations
@@ -522,4 +760,4 @@ declare function getAdminAccessToken(): Promise<string>;
522
760
  */
523
761
  declare function clearTokenCache(): void;
524
762
 
525
- export { type BatchWrite, type BatchWriteResult, type DataObject, type DecodedIdToken, type DocumentReference, FieldValue, type FieldValue$1 as FieldValueSentinel, FieldValueType, type FirestoreDocument, type FirestoreValue, type QueryFilter, type QueryOptions, type QueryOrder, type ServiceAccount, type SetOptions, type TokenResponse, type UpdateOptions, type UserInfo, type WhereFilterOp, addDocument, batchWrite, clearConfig, clearTokenCache, deleteDocument, getAdminAccessToken, getAuth, getConfig, getDocument, getProjectId, getServiceAccount, getUserFromToken, initializeApp, queryDocuments, setDocument, updateDocument, verifyIdToken };
763
+ export { type BatchWrite, type BatchWriteResult, type CustomClaims, type CustomTokenSignInResponse, type DataObject, type DecodedIdToken, type DocumentReference, type DownloadOptions, FieldValue, type FieldValue$1 as FieldValueSentinel, FieldValueType, type FileMetadata, type FirestoreDocument, type FirestoreValue, type ListFilesResult, type ListOptions, type QueryFilter, type QueryOptions, type QueryOrder, type ServiceAccount, type SetOptions, type SignedUrlOptions, type TokenResponse, type UpdateOptions, type UploadOptions, type UserInfo, type WhereFilterOp, addDocument, batchWrite, clearConfig, clearTokenCache, createCustomToken, deleteDocument, deleteFile, downloadFile, fileExists, generateSignedUrl, getAdminAccessToken, getAuth, getConfig, getDocument, getFileMetadata, getProjectId, getServiceAccount, getUserFromToken, initializeApp, listFiles, queryDocuments, setDocument, signInWithCustomToken, updateDocument, uploadFile, verifyIdToken };
package/dist/index.d.ts CHANGED
@@ -195,6 +195,7 @@ interface BatchWriteResult {
195
195
  interface SDKConfig {
196
196
  serviceAccount?: ServiceAccount | string;
197
197
  projectId?: string;
198
+ apiKey?: string;
198
199
  }
199
200
  /**
200
201
  * Initialize the Firebase Admin SDK with configuration
@@ -250,6 +251,21 @@ declare function getProjectId(): string;
250
251
  * ID token verification supporting both Firebase v9 and v10 token formats
251
252
  */
252
253
 
254
+ /**
255
+ * Custom claims for custom tokens
256
+ */
257
+ interface CustomClaims {
258
+ [key: string]: any;
259
+ }
260
+ /**
261
+ * Response from signInWithCustomToken
262
+ */
263
+ interface CustomTokenSignInResponse {
264
+ idToken: string;
265
+ refreshToken: string;
266
+ expiresIn: string;
267
+ localId: string;
268
+ }
253
269
  /**
254
270
  * Verify a Firebase ID token
255
271
  * Supports both Firebase v9 (securetoken) and v10 (session) token formats
@@ -280,6 +296,45 @@ declare function verifyIdToken(idToken: string): Promise<DecodedIdToken>;
280
296
  * ```
281
297
  */
282
298
  declare function getUserFromToken(idToken: string): Promise<UserInfo>;
299
+ /**
300
+ * Create a custom token for a user
301
+ *
302
+ * @param uid - User ID
303
+ * @param customClaims - Optional custom claims to include in token
304
+ * @returns Custom JWT token
305
+ *
306
+ * @example
307
+ * ```typescript
308
+ * // Create token with custom claims
309
+ * const token = await createCustomToken('user123', {
310
+ * role: 'admin',
311
+ * premium: true,
312
+ * });
313
+ *
314
+ * // Use token on client to sign in
315
+ * await signInWithCustomToken(auth, token);
316
+ * ```
317
+ */
318
+ declare function createCustomToken(uid: string, customClaims?: CustomClaims): Promise<string>;
319
+ /**
320
+ * Exchange a custom token for an ID token and refresh token
321
+ *
322
+ * @param customToken - Custom JWT token created with createCustomToken
323
+ * @returns User credentials (idToken, refreshToken, expiresIn, localId)
324
+ *
325
+ * @example
326
+ * ```typescript
327
+ * // Server-side: Create custom token
328
+ * const customToken = await createCustomToken('user123', { role: 'admin' });
329
+ *
330
+ * // Exchange for ID token
331
+ * const credentials = await signInWithCustomToken(customToken);
332
+ *
333
+ * // Use ID token for authenticated requests
334
+ * const user = await verifyIdToken(credentials.idToken);
335
+ * ```
336
+ */
337
+ declare function signInWithCustomToken(customToken: string): Promise<CustomTokenSignInResponse>;
283
338
  /**
284
339
  * Get Auth instance (for compatibility, but not used in new implementation)
285
340
  * @deprecated Use verifyIdToken directly
@@ -425,6 +480,189 @@ declare function queryDocuments(collectionPath: string, options?: QueryOptions):
425
480
  */
426
481
  declare function batchWrite(operations: BatchWrite[]): Promise<BatchWriteResult>;
427
482
 
483
+ /**
484
+ * Firebase Storage client using Google Cloud Storage REST API
485
+ * Compatible with edge runtimes (Cloudflare Workers, Vercel Edge, etc.)
486
+ */
487
+ /**
488
+ * Options for uploading files
489
+ */
490
+ interface UploadOptions {
491
+ contentType?: string;
492
+ metadata?: Record<string, string>;
493
+ public?: boolean;
494
+ }
495
+ /**
496
+ * Options for downloading files
497
+ */
498
+ interface DownloadOptions {
499
+ responseType?: 'arraybuffer' | 'blob';
500
+ }
501
+ /**
502
+ * Options for listing files
503
+ */
504
+ interface ListOptions {
505
+ prefix?: string;
506
+ delimiter?: string;
507
+ maxResults?: number;
508
+ pageToken?: string;
509
+ }
510
+ /**
511
+ * File metadata returned by Storage API
512
+ */
513
+ interface FileMetadata {
514
+ name: string;
515
+ bucket: string;
516
+ size: string;
517
+ contentType: string;
518
+ timeCreated: string;
519
+ updated: string;
520
+ md5Hash: string;
521
+ metadata?: Record<string, string>;
522
+ }
523
+ /**
524
+ * Result of listing files
525
+ */
526
+ interface ListFilesResult {
527
+ files: FileMetadata[];
528
+ nextPageToken?: string;
529
+ }
530
+ /**
531
+ * Upload a file to Firebase Storage
532
+ *
533
+ * @param path - File path in storage (e.g., 'images/photo.jpg')
534
+ * @param data - File data as ArrayBuffer, Uint8Array, or Blob
535
+ * @param options - Upload options (contentType, metadata, public)
536
+ * @returns File metadata
537
+ *
538
+ * @example
539
+ * ```typescript
540
+ * const data = new TextEncoder().encode('Hello, Storage!');
541
+ * const metadata = await uploadFile('files/hello.txt', data, {
542
+ * contentType: 'text/plain',
543
+ * metadata: { userId: '123' },
544
+ * });
545
+ * ```
546
+ */
547
+ declare function uploadFile(path: string, data: ArrayBuffer | Uint8Array | Blob, options?: UploadOptions): Promise<FileMetadata>;
548
+ /**
549
+ * Download a file from Firebase Storage
550
+ *
551
+ * @param path - File path in storage
552
+ * @param options - Download options
553
+ * @returns File data as ArrayBuffer
554
+ *
555
+ * @example
556
+ * ```typescript
557
+ * const data = await downloadFile('files/hello.txt');
558
+ * const text = new TextDecoder().decode(data);
559
+ * console.log(text); // "Hello, Storage!"
560
+ * ```
561
+ */
562
+ declare function downloadFile(path: string, _options?: DownloadOptions): Promise<ArrayBuffer>;
563
+ /**
564
+ * Delete a file from Firebase Storage
565
+ *
566
+ * @param path - File path in storage
567
+ *
568
+ * @example
569
+ * ```typescript
570
+ * await deleteFile('files/hello.txt');
571
+ * ```
572
+ */
573
+ declare function deleteFile(path: string): Promise<void>;
574
+ /**
575
+ * Get file metadata from Firebase Storage
576
+ *
577
+ * @param path - File path in storage
578
+ * @returns File metadata
579
+ *
580
+ * @example
581
+ * ```typescript
582
+ * const metadata = await getFileMetadata('files/hello.txt');
583
+ * console.log(metadata.size, metadata.contentType);
584
+ * ```
585
+ */
586
+ declare function getFileMetadata(path: string): Promise<FileMetadata>;
587
+ /**
588
+ * List files in Firebase Storage
589
+ *
590
+ * @param options - List options (prefix, delimiter, maxResults, pageToken)
591
+ * @returns List of files and optional next page token
592
+ *
593
+ * @example
594
+ * ```typescript
595
+ * // List all files with prefix
596
+ * const { files } = await listFiles({ prefix: 'images/' });
597
+ *
598
+ * // List with pagination
599
+ * const { files, nextPageToken } = await listFiles({ maxResults: 10 });
600
+ * if (nextPageToken) {
601
+ * const nextPage = await listFiles({ pageToken: nextPageToken });
602
+ * }
603
+ * ```
604
+ */
605
+ declare function listFiles(options?: ListOptions): Promise<ListFilesResult>;
606
+ /**
607
+ * Check if a file exists in Firebase Storage
608
+ *
609
+ * @param path - File path in storage
610
+ * @returns True if file exists, false otherwise
611
+ *
612
+ * @example
613
+ * ```typescript
614
+ * if (await fileExists('files/hello.txt')) {
615
+ * console.log('File exists!');
616
+ * }
617
+ * ```
618
+ */
619
+ declare function fileExists(path: string): Promise<boolean>;
620
+
621
+ /**
622
+ * Generate signed URLs for temporary access to Firebase Storage files
623
+ * Uses Google Cloud Storage V4 signing process
624
+ */
625
+ /**
626
+ * Options for generating signed URLs
627
+ */
628
+ interface SignedUrlOptions {
629
+ action: 'read' | 'write' | 'delete';
630
+ expires: Date | number;
631
+ contentType?: string;
632
+ responseDisposition?: string;
633
+ responseType?: string;
634
+ }
635
+ /**
636
+ * Generate a signed URL for temporary access to a Storage file
637
+ *
638
+ * Uses Google Cloud Storage V4 signing process
639
+ *
640
+ * @param path - File path in storage (e.g., 'images/photo.jpg')
641
+ * @param options - Signed URL options
642
+ * @returns Signed URL that can be used without authentication
643
+ *
644
+ * @example
645
+ * ```typescript
646
+ * // Generate read URL valid for 1 hour
647
+ * const url = await generateSignedUrl('files/hello.txt', {
648
+ * action: 'read',
649
+ * expires: 3600,
650
+ * });
651
+ *
652
+ * // Generate write URL with content type
653
+ * const uploadUrl = await generateSignedUrl('files/upload.jpg', {
654
+ * action: 'write',
655
+ * expires: 1800, // 30 minutes
656
+ * contentType: 'image/jpeg',
657
+ * });
658
+ *
659
+ * // Use the URL (no auth needed)
660
+ * const response = await fetch(url);
661
+ * const data = await response.arrayBuffer();
662
+ * ```
663
+ */
664
+ declare function generateSignedUrl(path: string, options: SignedUrlOptions): Promise<string>;
665
+
428
666
  /**
429
667
  * Firebase Admin SDK v8 - Field Value Helpers
430
668
  * Special field values for Firestore operations
@@ -522,4 +760,4 @@ declare function getAdminAccessToken(): Promise<string>;
522
760
  */
523
761
  declare function clearTokenCache(): void;
524
762
 
525
- export { type BatchWrite, type BatchWriteResult, type DataObject, type DecodedIdToken, type DocumentReference, FieldValue, type FieldValue$1 as FieldValueSentinel, FieldValueType, type FirestoreDocument, type FirestoreValue, type QueryFilter, type QueryOptions, type QueryOrder, type ServiceAccount, type SetOptions, type TokenResponse, type UpdateOptions, type UserInfo, type WhereFilterOp, addDocument, batchWrite, clearConfig, clearTokenCache, deleteDocument, getAdminAccessToken, getAuth, getConfig, getDocument, getProjectId, getServiceAccount, getUserFromToken, initializeApp, queryDocuments, setDocument, updateDocument, verifyIdToken };
763
+ export { type BatchWrite, type BatchWriteResult, type CustomClaims, type CustomTokenSignInResponse, type DataObject, type DecodedIdToken, type DocumentReference, type DownloadOptions, FieldValue, type FieldValue$1 as FieldValueSentinel, FieldValueType, type FileMetadata, type FirestoreDocument, type FirestoreValue, type ListFilesResult, type ListOptions, type QueryFilter, type QueryOptions, type QueryOrder, type ServiceAccount, type SetOptions, type SignedUrlOptions, type TokenResponse, type UpdateOptions, type UploadOptions, type UserInfo, type WhereFilterOp, addDocument, batchWrite, clearConfig, clearTokenCache, createCustomToken, deleteDocument, deleteFile, downloadFile, fileExists, generateSignedUrl, getAdminAccessToken, getAuth, getConfig, getDocument, getFileMetadata, getProjectId, getServiceAccount, getUserFromToken, initializeApp, listFiles, queryDocuments, setDocument, signInWithCustomToken, updateDocument, uploadFile, verifyIdToken };