@prmichaelsen/firebase-admin-sdk-v8 2.0.20 → 2.0.21
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/.github/workflows/e2e-tests.yml +11 -2
- package/README.md +121 -0
- package/package.json +1 -1
|
@@ -31,11 +31,20 @@ jobs:
|
|
|
31
31
|
run: |
|
|
32
32
|
echo '${{ secrets.FIREBASE_SERVICE_ACCOUNT }}' > service-account.json
|
|
33
33
|
|
|
34
|
-
- name: Run e2e tests
|
|
35
|
-
run: npm run test:e2e
|
|
34
|
+
- name: Run e2e tests with coverage
|
|
35
|
+
run: npm run test:e2e -- --coverage
|
|
36
36
|
env:
|
|
37
37
|
NODE_ENV: test
|
|
38
38
|
|
|
39
|
+
- name: Upload e2e coverage to Codecov
|
|
40
|
+
uses: codecov/codecov-action@v4
|
|
41
|
+
with:
|
|
42
|
+
token: ${{ secrets.CODECOV_TOKEN }}
|
|
43
|
+
files: ./coverage/lcov.info
|
|
44
|
+
flags: e2etests
|
|
45
|
+
name: codecov-e2e
|
|
46
|
+
fail_ci_if_error: false
|
|
47
|
+
|
|
39
48
|
- name: Clean up service account file
|
|
40
49
|
if: always()
|
|
41
50
|
run: rm -f service-account.json
|
package/README.md
CHANGED
|
@@ -521,11 +521,132 @@ For better query performance:
|
|
|
521
521
|
| Firestore Queries | ✅ | where, orderBy, limit, cursors |
|
|
522
522
|
| Firestore Batch | ✅ | Up to 500 operations |
|
|
523
523
|
| Firestore Transactions | ❌ | Not yet implemented |
|
|
524
|
+
| **Realtime Listeners** | **❌** | **See explanation below** |
|
|
524
525
|
| Field Values | ✅ | increment, arrayUnion, serverTimestamp, etc. |
|
|
525
526
|
| Realtime Database | ❌ | Not planned |
|
|
526
527
|
| Cloud Storage | ❌ | Not yet implemented |
|
|
527
528
|
| Cloud Messaging | ❌ | Not yet implemented |
|
|
528
529
|
|
|
530
|
+
## ⚠️ Realtime Listeners Not Supported
|
|
531
|
+
|
|
532
|
+
This library **does not support** Firestore realtime listeners (`onSnapshot()`). Here's why:
|
|
533
|
+
|
|
534
|
+
### Technical Limitation
|
|
535
|
+
|
|
536
|
+
**This library uses the Firestore REST API**, which is:
|
|
537
|
+
- ✅ Stateless (request/response only)
|
|
538
|
+
- ✅ Compatible with edge runtimes (Cloudflare Workers, Vercel Edge)
|
|
539
|
+
- ❌ **No persistent connections**
|
|
540
|
+
- ❌ **No server-push capabilities**
|
|
541
|
+
- ❌ **No streaming support**
|
|
542
|
+
|
|
543
|
+
**Realtime listeners require**:
|
|
544
|
+
- Persistent connections (WebSocket or gRPC)
|
|
545
|
+
- Bidirectional streaming
|
|
546
|
+
- Server-push architecture
|
|
547
|
+
|
|
548
|
+
The Firestore REST API simply doesn't provide these capabilities.
|
|
549
|
+
|
|
550
|
+
### Why Not Implement gRPC?
|
|
551
|
+
|
|
552
|
+
While Firestore does offer a gRPC API with streaming support, implementing it would require:
|
|
553
|
+
|
|
554
|
+
1. **Complex Protocol Implementation**
|
|
555
|
+
- HTTP/2 framing
|
|
556
|
+
- gRPC message framing
|
|
557
|
+
- Protobuf encoding/decoding
|
|
558
|
+
- Authentication flow
|
|
559
|
+
- Reconnection logic
|
|
560
|
+
- ~100+ hours of development
|
|
561
|
+
|
|
562
|
+
2. **Runtime Limitations**
|
|
563
|
+
- Cloudflare Workers doesn't support full gRPC (only gRPC-Web)
|
|
564
|
+
- gRPC-Web requires a proxy server
|
|
565
|
+
- Can't connect directly to Firestore's gRPC endpoint
|
|
566
|
+
- Would only work in Durable Objects, not regular Workers
|
|
567
|
+
|
|
568
|
+
3. **Maintenance Burden**
|
|
569
|
+
- Must keep up with Firestore protocol changes
|
|
570
|
+
- Complex debugging and error handling
|
|
571
|
+
- High ongoing maintenance cost
|
|
572
|
+
|
|
573
|
+
### Alternatives
|
|
574
|
+
|
|
575
|
+
If you need realtime updates, consider these approaches:
|
|
576
|
+
|
|
577
|
+
#### 1. **Polling (Simple)**
|
|
578
|
+
```typescript
|
|
579
|
+
// Poll for changes every 5 seconds
|
|
580
|
+
setInterval(async () => {
|
|
581
|
+
const doc = await getDocument('users', 'user123');
|
|
582
|
+
// Handle updates
|
|
583
|
+
}, 5000);
|
|
584
|
+
```
|
|
585
|
+
|
|
586
|
+
**Pros**: Simple, works everywhere
|
|
587
|
+
**Cons**: 5-second delay, polling costs
|
|
588
|
+
|
|
589
|
+
#### 2. **Durable Objects + Polling (Better)**
|
|
590
|
+
```typescript
|
|
591
|
+
// Durable Object polls once, broadcasts to many clients
|
|
592
|
+
export class FirestoreSync {
|
|
593
|
+
async poll() {
|
|
594
|
+
const doc = await getDocument('users', 'user123');
|
|
595
|
+
// Broadcast to all connected WebSocket clients
|
|
596
|
+
for (const ws of this.sessions) {
|
|
597
|
+
ws.send(JSON.stringify(doc));
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
**Pros**: One poll serves many clients, WebSocket push to clients
|
|
604
|
+
**Cons**: Still polling-based, Cloudflare-specific
|
|
605
|
+
|
|
606
|
+
#### 3. **Hybrid Architecture (Best)**
|
|
607
|
+
```typescript
|
|
608
|
+
// Use firebase-admin-node for realtime in Node.js
|
|
609
|
+
import admin from 'firebase-admin';
|
|
610
|
+
|
|
611
|
+
admin.firestore().collection('users').doc('user123')
|
|
612
|
+
.onSnapshot((snapshot) => {
|
|
613
|
+
// True realtime updates
|
|
614
|
+
console.log('Update:', snapshot.data());
|
|
615
|
+
});
|
|
616
|
+
|
|
617
|
+
// Use this library for CRUD in edge functions
|
|
618
|
+
import { getDocument } from '@prmichaelsen/firebase-admin-sdk-v8';
|
|
619
|
+
const doc = await getDocument('users', 'user123');
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
**Pros**: True realtime where needed, edge performance for CRUD
|
|
623
|
+
**Cons**: Requires separate Node.js service
|
|
624
|
+
|
|
625
|
+
#### 4. **Firebase Client SDK (Frontend)**
|
|
626
|
+
```typescript
|
|
627
|
+
// Use Firebase Client SDK in browser/mobile
|
|
628
|
+
import { onSnapshot, doc } from 'firebase/firestore';
|
|
629
|
+
|
|
630
|
+
onSnapshot(doc(db, 'users', 'user123'), (snapshot) => {
|
|
631
|
+
console.log('Update:', snapshot.data());
|
|
632
|
+
});
|
|
633
|
+
```
|
|
634
|
+
|
|
635
|
+
**Pros**: True realtime, built-in, well-supported
|
|
636
|
+
**Cons**: Client-side only, requires Firebase Auth
|
|
637
|
+
|
|
638
|
+
### Recommendation
|
|
639
|
+
|
|
640
|
+
- **For edge runtimes**: Use polling or Durable Objects pattern
|
|
641
|
+
- **For true realtime**: Use `firebase-admin-node` in Node.js
|
|
642
|
+
- **For client apps**: Use Firebase Client SDK
|
|
643
|
+
- **For hybrid**: Use this library for CRUD + Node.js for realtime
|
|
644
|
+
|
|
645
|
+
### Related
|
|
646
|
+
|
|
647
|
+
- [firebase-admin-node](https://github.com/firebase/firebase-admin-node) - Full Admin SDK with realtime support
|
|
648
|
+
- [Firebase Client SDK](https://firebase.google.com/docs/firestore/query-data/listen) - Client-side realtime listeners
|
|
649
|
+
|
|
529
650
|
## 🗺️ Roadmap
|
|
530
651
|
|
|
531
652
|
- [ ] Custom token creation
|
package/package.json
CHANGED