@seaverse/data-service-sdk 0.2.0 → 0.3.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
@@ -69,7 +69,7 @@ const firestoreToken = await dataClient.generateFirestoreToken({
69
69
  // Step 3: Initialize Firebase
70
70
  const app = initializeApp({ projectId: firestoreToken.project_id });
71
71
  const auth = getAuth(app);
72
- await signInWithCustomToken(auth, firestoreToken.id_token);
72
+ await signInWithCustomToken(auth, firestoreToken.custom_token);
73
73
  const db = getFirestore(app);
74
74
 
75
75
  // Step 4: Use Firestore with proper paths
@@ -118,7 +118,7 @@ const guestToken = await dataClient.generateGuestFirestoreToken({
118
118
  // Step 2: Initialize Firebase
119
119
  const app = initializeApp({ projectId: guestToken.project_id });
120
120
  const auth = getAuth(app);
121
- await signInWithCustomToken(auth, guestToken.id_token);
121
+ await signInWithCustomToken(auth, guestToken.custom_token);
122
122
  const db = getFirestore(app);
123
123
 
124
124
  // Step 3: Guest can write to publicData
@@ -189,8 +189,7 @@ interface GenerateFirestoreTokenRequest {
189
189
 
190
190
  ```typescript
191
191
  interface FirestoreTokenResponse {
192
- id_token: string; // Firebase ID Token for signInWithCustomToken()
193
- refresh_token?: string; // Firebase Refresh Token (optional)
192
+ custom_token: string; // Firebase Custom Token - use with signInWithCustomToken()
194
193
  project_id: string; // Firebase Project ID for initializeApp()
195
194
  database_id: string; // Firestore Database ID
196
195
  app_id?: string; // Application ID (use in Firestore paths)
@@ -208,7 +207,7 @@ const firestoreToken = await client.generateFirestoreToken({
208
207
  app_id: 'my-app-123'
209
208
  });
210
209
 
211
- console.log('Token:', firestoreToken.id_token);
210
+ console.log('Custom Token:', firestoreToken.custom_token);
212
211
  console.log('User ID:', firestoreToken.user_id);
213
212
  console.log('App ID:', firestoreToken.app_id);
214
213
  ```
@@ -243,7 +242,7 @@ const guestToken = await client.generateGuestFirestoreToken({
243
242
  app_id: 'my-app-123'
244
243
  });
245
244
 
246
- console.log('Guest Token:', guestToken.id_token);
245
+ console.log('Guest Custom Token:', guestToken.custom_token);
247
246
  console.log('Guest User ID:', guestToken.user_id);
248
247
  console.log('Role:', guestToken.role); // 'guest'
249
248
  ```
@@ -451,7 +450,7 @@ async function completeExample() {
451
450
  // 3. Initialize Firebase
452
451
  const app = initializeApp({ projectId: firestoreToken.project_id });
453
452
  const auth = getAuth(app);
454
- await signInWithCustomToken(auth, firestoreToken.id_token);
453
+ await signInWithCustomToken(auth, firestoreToken.custom_token);
455
454
  const db = getFirestore(app);
456
455
 
457
456
  const userId = firestoreToken.user_id;
package/dist/index.cjs CHANGED
@@ -65,7 +65,7 @@ const ENDPOINTS = {
65
65
  *
66
66
  * const app = initializeApp({ projectId: tokenResponse.project_id });
67
67
  * const auth = getAuth(app);
68
- * await signInWithCustomToken(auth, tokenResponse.id_token);
68
+ * await signInWithCustomToken(auth, tokenResponse.custom_token);
69
69
  * const db = getFirestore(app);
70
70
  *
71
71
  * // Step 3: Access Firestore data with correct paths
@@ -146,7 +146,7 @@ class DataServiceClient {
146
146
  *
147
147
  * IMPORTANT FOR LLM: After getting the token, you MUST:
148
148
  * 1. Initialize Firebase app with the project_id
149
- * 2. Sign in with the id_token using signInWithCustomToken()
149
+ * 2. Sign in with the custom_token using signInWithCustomToken()
150
150
  * 3. Always include required fields in documents: _appId, _createdAt, _createdBy
151
151
  *
152
152
  * @param request - The request containing user token and app ID
@@ -171,7 +171,7 @@ class DataServiceClient {
171
171
  * app_id: 'my-app-123'
172
172
  * });
173
173
  *
174
- * console.log('Firestore ID Token:', firestoreToken.id_token);
174
+ * console.log('Firestore Custom Token:', firestoreToken.custom_token);
175
175
  * console.log('User ID:', firestoreToken.user_id);
176
176
  * console.log('App ID:', firestoreToken.app_id);
177
177
  * console.log('Token expires in:', firestoreToken.expires_in, 'seconds');
@@ -183,7 +183,7 @@ class DataServiceClient {
183
183
  *
184
184
  * const app = initializeApp({ projectId: firestoreToken.project_id });
185
185
  * const auth = getAuth(app);
186
- * await signInWithCustomToken(auth, firestoreToken.id_token);
186
+ * await signInWithCustomToken(auth, firestoreToken.custom_token);
187
187
  * const db = getFirestore(app);
188
188
  * // Ready to use Firestore!
189
189
  * ```
@@ -226,7 +226,7 @@ class DataServiceClient {
226
226
  * app_id: 'my-app-123'
227
227
  * });
228
228
  *
229
- * console.log('Guest Firestore ID Token:', guestToken.id_token);
229
+ * console.log('Guest Firestore Custom Token:', guestToken.custom_token);
230
230
  * console.log('Guest User ID:', guestToken.user_id); // e.g., 'guest-abc123'
231
231
  * console.log('Role:', guestToken.role); // 'guest'
232
232
  *
@@ -237,7 +237,7 @@ class DataServiceClient {
237
237
  *
238
238
  * const app = initializeApp({ projectId: guestToken.project_id });
239
239
  * const auth = getAuth(app);
240
- * await signInWithCustomToken(auth, guestToken.id_token);
240
+ * await signInWithCustomToken(auth, guestToken.custom_token);
241
241
  * const db = getFirestore(app);
242
242
  *
243
243
  * // Guest can write to publicData
package/dist/index.d.ts CHANGED
@@ -98,24 +98,35 @@ interface GenerateGuestFirestoreTokenRequest {
98
98
  *
99
99
  * const app = initializeApp({ projectId: response.project_id });
100
100
  * const auth = getAuth(app);
101
- * await signInWithCustomToken(auth, response.id_token);
101
+ * await signInWithCustomToken(auth, response.custom_token);
102
102
  * const db = getFirestore(app);
103
103
  * // Now you can use Firestore with proper permissions
104
104
  * ```
105
105
  */
106
106
  interface FirestoreTokenResponse {
107
107
  /**
108
- * Firebase ID Token (exchanged from Custom Token)
109
- * Use this with signInWithCustomToken() to authenticate with Firebase
110
- * This token expires after the time specified in expires_in (typically 1 hour)
111
- */
112
- id_token: string;
113
- /**
114
- * Firebase Refresh Token (optional)
115
- * Used to refresh the id_token when it expires
116
- * May not be present for guest users
108
+ * Firebase Custom Token - Use this to authenticate with Firebase
109
+ *
110
+ * IMPORTANT: You MUST use this with signInWithCustomToken() to get authenticated:
111
+ *
112
+ * ```typescript
113
+ * import { getAuth, signInWithCustomToken } from 'firebase/auth';
114
+ * const auth = getAuth(app);
115
+ * await signInWithCustomToken(auth, response.custom_token);
116
+ * ```
117
+ *
118
+ * This Custom Token contains:
119
+ * - appId claim: For data isolation (determines which data you can access)
120
+ * - User ID: Identifies the user
121
+ *
122
+ * After calling signInWithCustomToken(), Firebase automatically:
123
+ * 1. Exchanges the Custom Token for an ID Token
124
+ * 2. Uses the ID Token for all subsequent Firestore requests
125
+ * 3. Handles token refresh automatically
126
+ *
127
+ * Custom Token itself does not expire, but the ID Token it generates expires after 1 hour
117
128
  */
118
- refresh_token?: string;
129
+ custom_token: string;
119
130
  /**
120
131
  * Firebase Project ID
121
132
  * Use this to initialize Firebase app: initializeApp({ projectId: '...' })
@@ -245,7 +256,7 @@ interface DataServiceClientOptions {
245
256
  *
246
257
  * const app = initializeApp({ projectId: tokenResponse.project_id });
247
258
  * const auth = getAuth(app);
248
- * await signInWithCustomToken(auth, tokenResponse.id_token);
259
+ * await signInWithCustomToken(auth, tokenResponse.custom_token);
249
260
  * const db = getFirestore(app);
250
261
  *
251
262
  * // Step 3: Access Firestore data with correct paths
@@ -287,7 +298,7 @@ declare class DataServiceClient {
287
298
  *
288
299
  * IMPORTANT FOR LLM: After getting the token, you MUST:
289
300
  * 1. Initialize Firebase app with the project_id
290
- * 2. Sign in with the id_token using signInWithCustomToken()
301
+ * 2. Sign in with the custom_token using signInWithCustomToken()
291
302
  * 3. Always include required fields in documents: _appId, _createdAt, _createdBy
292
303
  *
293
304
  * @param request - The request containing user token and app ID
@@ -312,7 +323,7 @@ declare class DataServiceClient {
312
323
  * app_id: 'my-app-123'
313
324
  * });
314
325
  *
315
- * console.log('Firestore ID Token:', firestoreToken.id_token);
326
+ * console.log('Firestore Custom Token:', firestoreToken.custom_token);
316
327
  * console.log('User ID:', firestoreToken.user_id);
317
328
  * console.log('App ID:', firestoreToken.app_id);
318
329
  * console.log('Token expires in:', firestoreToken.expires_in, 'seconds');
@@ -324,7 +335,7 @@ declare class DataServiceClient {
324
335
  *
325
336
  * const app = initializeApp({ projectId: firestoreToken.project_id });
326
337
  * const auth = getAuth(app);
327
- * await signInWithCustomToken(auth, firestoreToken.id_token);
338
+ * await signInWithCustomToken(auth, firestoreToken.custom_token);
328
339
  * const db = getFirestore(app);
329
340
  * // Ready to use Firestore!
330
341
  * ```
@@ -358,7 +369,7 @@ declare class DataServiceClient {
358
369
  * app_id: 'my-app-123'
359
370
  * });
360
371
  *
361
- * console.log('Guest Firestore ID Token:', guestToken.id_token);
372
+ * console.log('Guest Firestore Custom Token:', guestToken.custom_token);
362
373
  * console.log('Guest User ID:', guestToken.user_id); // e.g., 'guest-abc123'
363
374
  * console.log('Role:', guestToken.role); // 'guest'
364
375
  *
@@ -369,7 +380,7 @@ declare class DataServiceClient {
369
380
  *
370
381
  * const app = initializeApp({ projectId: guestToken.project_id });
371
382
  * const auth = getAuth(app);
372
- * await signInWithCustomToken(auth, guestToken.id_token);
383
+ * await signInWithCustomToken(auth, guestToken.custom_token);
373
384
  * const db = getFirestore(app);
374
385
  *
375
386
  * // Guest can write to publicData
package/dist/index.js CHANGED
@@ -63,7 +63,7 @@ const ENDPOINTS = {
63
63
  *
64
64
  * const app = initializeApp({ projectId: tokenResponse.project_id });
65
65
  * const auth = getAuth(app);
66
- * await signInWithCustomToken(auth, tokenResponse.id_token);
66
+ * await signInWithCustomToken(auth, tokenResponse.custom_token);
67
67
  * const db = getFirestore(app);
68
68
  *
69
69
  * // Step 3: Access Firestore data with correct paths
@@ -144,7 +144,7 @@ class DataServiceClient {
144
144
  *
145
145
  * IMPORTANT FOR LLM: After getting the token, you MUST:
146
146
  * 1. Initialize Firebase app with the project_id
147
- * 2. Sign in with the id_token using signInWithCustomToken()
147
+ * 2. Sign in with the custom_token using signInWithCustomToken()
148
148
  * 3. Always include required fields in documents: _appId, _createdAt, _createdBy
149
149
  *
150
150
  * @param request - The request containing user token and app ID
@@ -169,7 +169,7 @@ class DataServiceClient {
169
169
  * app_id: 'my-app-123'
170
170
  * });
171
171
  *
172
- * console.log('Firestore ID Token:', firestoreToken.id_token);
172
+ * console.log('Firestore Custom Token:', firestoreToken.custom_token);
173
173
  * console.log('User ID:', firestoreToken.user_id);
174
174
  * console.log('App ID:', firestoreToken.app_id);
175
175
  * console.log('Token expires in:', firestoreToken.expires_in, 'seconds');
@@ -181,7 +181,7 @@ class DataServiceClient {
181
181
  *
182
182
  * const app = initializeApp({ projectId: firestoreToken.project_id });
183
183
  * const auth = getAuth(app);
184
- * await signInWithCustomToken(auth, firestoreToken.id_token);
184
+ * await signInWithCustomToken(auth, firestoreToken.custom_token);
185
185
  * const db = getFirestore(app);
186
186
  * // Ready to use Firestore!
187
187
  * ```
@@ -224,7 +224,7 @@ class DataServiceClient {
224
224
  * app_id: 'my-app-123'
225
225
  * });
226
226
  *
227
- * console.log('Guest Firestore ID Token:', guestToken.id_token);
227
+ * console.log('Guest Firestore Custom Token:', guestToken.custom_token);
228
228
  * console.log('Guest User ID:', guestToken.user_id); // e.g., 'guest-abc123'
229
229
  * console.log('Role:', guestToken.role); // 'guest'
230
230
  *
@@ -235,7 +235,7 @@ class DataServiceClient {
235
235
  *
236
236
  * const app = initializeApp({ projectId: guestToken.project_id });
237
237
  * const auth = getAuth(app);
238
- * await signInWithCustomToken(auth, guestToken.id_token);
238
+ * await signInWithCustomToken(auth, guestToken.custom_token);
239
239
  * const db = getFirestore(app);
240
240
  *
241
241
  * // Guest can write to publicData
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seaverse/data-service-sdk",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "SDK for SeaVerse Data Service - Firestore token management with three-tier permission model",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",