@seaverse/data-service-sdk 0.5.0 → 0.5.2

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/README.md CHANGED
@@ -17,9 +17,56 @@ SeaVerse organizes your Firestore data into three permission levels:
17
17
 
18
18
  | Permission Level | Path Pattern | Read Access | Write Access | Use Case |
19
19
  |-----------------|--------------|-------------|--------------|----------|
20
- | **publicRead** | `appData/{app_id}/publicRead/...` | All authenticated users | Admin only | System configs, announcements, static content |
21
- | **publicData** | `appData/{app_id}/publicData/...` | All authenticated users | All authenticated users | User posts, comments, shared content |
22
- | **userData** | `appData/{app_id}/userData/{user_id}/...` | Owner only | Owner only | User settings, private notes, personal data |
20
+ | **publicRead** | `appData/{app_id}/publicRead/{collection}/{docId}` | All authenticated users | Admin only | System configs, announcements, static content |
21
+ | **publicData** | `appData/{app_id}/publicData/{collection}/{docId}` | All authenticated users | All authenticated users | User posts, comments, shared content |
22
+ | **userData** | `appData/{app_id}/userData/{user_id}/{collection}/{docId}` | Owner only | Owner only | User settings, private notes, personal data |
23
+
24
+ ### 🚨 CRITICAL: Firestore Path Rules (For LLM)
25
+
26
+ **Firestore path segments MUST follow these rules:**
27
+
28
+ 1. **Collection paths = ODD number of segments** (1, 3, 5, 7...)
29
+ - Example: `appData/my-app/publicData/posts` (4 segments) ❌ WRONG!
30
+ - Correct: Use collection() function, Firestore handles this automatically
31
+
32
+ 2. **Document paths = EVEN number of segments** (2, 4, 6, 8...)
33
+ - Example: `appData/my-app/publicData/posts/doc123` (5 segments) ✅ CORRECT!
34
+
35
+ 3. **How to use correctly:**
36
+
37
+ ```typescript
38
+ // ✅ CORRECT - Using collection() for collection paths
39
+ collection(db, `appData/${appId}/publicData/posts`) // Firestore handles this as a collection
40
+
41
+ // ✅ CORRECT - Using doc() for document paths
42
+ doc(db, `appData/${appId}/publicData/posts/doc123`) // 5 segments (odd) = document
43
+
44
+ // ❌ WRONG - Manually counting segments
45
+ // Don't worry about counting! Use Firebase functions:
46
+ // - collection() for collections
47
+ // - doc() for documents
48
+ // - addDoc() automatically adds document ID
49
+ ```
50
+
51
+ **Path Structure Examples:**
52
+
53
+ ```typescript
54
+ // Public Data (everyone can read/write)
55
+ const postsRef = collection(db, `appData/${appId}/publicData/posts`);
56
+ await addDoc(postsRef, { ...data }); // Firestore adds document ID
57
+
58
+ // User Private Data (owner only)
59
+ const notesRef = collection(db, `appData/${appId}/userData/${userId}/notes`);
60
+ await addDoc(notesRef, { ...data });
61
+
62
+ // Public Read-Only (everyone can read, admin can write)
63
+ const configRef = collection(db, `appData/${appId}/publicRead/config`);
64
+ await getDocs(configRef);
65
+ ```
66
+
67
+ **The pattern is always:**
68
+ - `appData` → `{app_id}` → `{permission_layer}` → `{collection}` → (auto-generated doc ID)
69
+ - This gives you 5 segments total = document path ✅
23
70
 
24
71
  ### Required Fields
25
72
 
@@ -190,6 +237,20 @@ const app = initializeApp({
190
237
 
191
238
  const auth = getAuth(app);
192
239
  await signInWithCustomToken(auth, tokenResponse.custom_token);
240
+
241
+ // ⚠️ IMPORTANT: Must specify database_id!
242
+ const db = getFirestore(app, tokenResponse.database_id);
243
+ ```
244
+
245
+ **🚨 CRITICAL: Always Specify database_id**
246
+
247
+ When initializing Firestore, you MUST pass the `database_id` from the token response:
248
+
249
+ ```typescript
250
+ // ✅ CORRECT - Specify database_id
251
+ const db = getFirestore(app, tokenResponse.database_id);
252
+
253
+ // ❌ WRONG - Will try to use "(default)" database which may not exist
193
254
  const db = getFirestore(app);
194
255
  ```
195
256
 
package/dist/browser.js CHANGED
@@ -4251,8 +4251,9 @@ async function initializeWithToken(tokenResponse) {
4251
4251
  // Sign in with custom token
4252
4252
  const auth = getAuth(app);
4253
4253
  await signInWithCustomToken(auth, tokenResponse.custom_token);
4254
- // Get Firestore instance
4255
- const db = getFirestore(app);
4254
+ // Get Firestore instance with correct database ID
4255
+ // IMPORTANT: Must specify database_id, not just use default!
4256
+ const db = getFirestore(app, tokenResponse.database_id);
4256
4257
  return {
4257
4258
  app,
4258
4259
  auth,