@seaverse/data-service-sdk 0.6.0 → 0.7.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/README.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  SeaVerse Data Service SDK for accessing Firestore with secure token management and three-tier permission model.
4
4
 
5
+ ## 🤖 For LLM Users
6
+
7
+ **👉 Want the simplest way to use this SDK? Check out the [LLM Quick Start Guide](./LLM-QUICK-START.md)**
8
+
9
+ The Quick Start guide shows you the **recommended LLM-friendly API** that automatically handles:
10
+ - ✅ Required fields (`_appId`, `_createdAt`, `_createdBy`)
11
+ - ✅ Correct Firestore paths
12
+ - ✅ Server timestamps
13
+ - ✅ Single import source
14
+
15
+ **Most common LLM mistakes prevented!**
16
+
5
17
  ## Features
6
18
 
7
19
  - 🔐 Secure Firestore token generation for authenticated users and guests
@@ -232,17 +244,11 @@ getUserDataPath('my-app', '', 'notes'); // Error: userId must be non-empty
232
244
 
233
245
  ## Quick Start
234
246
 
235
- ### 🚀 Easiest Way (Recommended - Auto Firebase Setup)
247
+ ### 🚀 Easiest Way (🤖 LLM-Recommended)
236
248
 
237
249
  ```typescript
238
- import {
239
- DataServiceClient,
240
- initializeWithToken,
241
- getPublicDataPath, // 🛡️ Use path helpers!
242
- getUserDataPath // 🛡️ Use path helpers!
243
- } from '@seaverse/data-service-sdk';
250
+ import { DataServiceClient, initializeWithToken } from '@seaverse/data-service-sdk';
244
251
  import { AuthClient } from '@seaverse/auth-sdk';
245
- import { collection, addDoc, getDocs, serverTimestamp } from 'firebase/firestore';
246
252
 
247
253
  // Step 1: Login user
248
254
  const authClient = new AuthClient({ appId: 'my-app-123' });
@@ -258,47 +264,65 @@ const tokenResponse = await dataClient.generateFirestoreToken({
258
264
  app_id: 'my-app-123'
259
265
  });
260
266
 
261
- // Step 3: Auto-initialize Firebase (ONE LINE!)
262
- const { db, appId, userId } = await initializeWithToken(tokenResponse);
267
+ // Step 3: Initialize Firebase & get helper
268
+ const { helper } = await initializeWithToken(tokenResponse);
263
269
 
264
- // Step 4: Use Firestore directly with path helpers!
270
+ // Step 4: Use Firestore with helper (automatic required fields!)
265
271
 
266
- // Write to publicData (everyone can write)
267
- const postsPath = getPublicDataPath(appId, 'posts'); // 🛡️ Safe path!
268
- await addDoc(collection(db, postsPath), {
269
- _appId: appId, // REQUIRED
270
- _createdAt: serverTimestamp(), // REQUIRED
271
- _createdBy: userId, // REQUIRED
272
+ // ✅ LLM-FRIENDLY: Write to publicData - required fields auto-injected!
273
+ await helper.addToPublicData('posts', {
272
274
  title: 'My First Post',
273
275
  content: 'Hello world!'
274
276
  });
275
277
 
276
- // Read from publicData
277
- const snapshot = await getDocs(collection(db, postsPath));
278
- snapshot.forEach(doc => {
278
+ // ✅ LLM-FRIENDLY: Read from publicData
279
+ const posts = await helper.getPublicData('posts');
280
+ posts.forEach(doc => {
279
281
  console.log(doc.id, doc.data());
280
282
  });
281
283
 
282
- // Write to userData (private)
283
- const notesPath = getUserDataPath(appId, userId, 'notes'); // 🛡️ Safe path!
284
- await addDoc(collection(db, notesPath), {
285
- _appId: appId, // REQUIRED
286
- _createdAt: serverTimestamp(), // REQUIRED
287
- _createdBy: userId, // REQUIRED
284
+ // ✅ LLM-FRIENDLY: Write to userData (private) - auto-isolated!
285
+ await helper.addToUserData('notes', {
288
286
  title: 'Private Note',
289
287
  content: 'Only I can see this'
290
288
  });
291
289
  ```
292
290
 
293
- ### 👤 For Guest Users (Even Simpler!)
291
+ <details>
292
+ <summary>📖 Advanced: Manual Way (for fine-grained control)</summary>
294
293
 
295
294
  ```typescript
296
295
  import {
297
296
  DataServiceClient,
298
297
  initializeWithToken,
299
- getPublicDataPath // 🛡️ Use path helpers!
298
+ getPublicDataPath,
299
+ getUserDataPath,
300
+ collection,
301
+ addDoc,
302
+ getDocs,
303
+ serverTimestamp
300
304
  } from '@seaverse/data-service-sdk';
301
- import { collection, addDoc, serverTimestamp } from 'firebase/firestore';
305
+ import { AuthClient } from '@seaverse/auth-sdk';
306
+
307
+ // ... login and initialize ...
308
+ const { db, appId, userId } = await initializeWithToken(tokenResponse);
309
+
310
+ // Manual way: Use path helpers + required fields
311
+ const postsPath = getPublicDataPath(appId, 'posts');
312
+ await addDoc(collection(db, postsPath), {
313
+ _appId: appId, // REQUIRED
314
+ _createdAt: serverTimestamp(), // REQUIRED
315
+ _createdBy: userId, // REQUIRED
316
+ title: 'My First Post',
317
+ content: 'Hello world!'
318
+ });
319
+ ```
320
+ </details>
321
+
322
+ ### 👤 For Guest Users (🤖 Even Simpler!)
323
+
324
+ ```typescript
325
+ import { DataServiceClient, initializeWithToken } from '@seaverse/data-service-sdk';
302
326
 
303
327
  // Step 1: Get guest token (no authentication needed!)
304
328
  const dataClient = new DataServiceClient();
@@ -306,15 +330,11 @@ const tokenResponse = await dataClient.generateGuestFirestoreToken({
306
330
  app_id: 'my-app-123'
307
331
  });
308
332
 
309
- // Step 2: Auto-initialize Firebase (ONE LINE!)
310
- const { db, appId, userId } = await initializeWithToken(tokenResponse);
333
+ // Step 2: Initialize & get helper
334
+ const { helper } = await initializeWithToken(tokenResponse);
311
335
 
312
- // Step 3: Guest can write to publicData
313
- const commentsPath = getPublicDataPath(appId, 'comments'); // 🛡️ Safe path!
314
- await addDoc(collection(db, commentsPath), {
315
- _appId: appId,
316
- _createdAt: serverTimestamp(),
317
- _createdBy: userId, // Guest user ID (e.g., 'guest-abc123')
336
+ // Step 3: Guest can write to publicData (automatic required fields!)
337
+ await helper.addToPublicData('comments', {
318
338
  comment: 'Great app!',
319
339
  rating: 5
320
340
  });