@seaverse/data-service-sdk 0.2.0 → 0.4.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 +97 -7
- package/dist/browser.js +4177 -0
- package/dist/browser.js.map +1 -0
- package/dist/browser.umd.js +4188 -0
- package/dist/browser.umd.js.map +1 -0
- package/dist/index.cjs +6 -6
- package/dist/index.d.ts +28 -17
- package/dist/index.js +6 -6
- package/package.json +7 -1
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.
|
|
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
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
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
|
-
|
|
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.
|
|
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
|
|
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
|
|
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.
|
|
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
|
|
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.
|
|
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.
|
|
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
|
|
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
|
|
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.
|
|
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
|
|
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.
|
|
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,16 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seaverse/data-service-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.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",
|
|
7
7
|
"module": "dist/index.js",
|
|
8
|
+
"browser": "dist/browser.js",
|
|
8
9
|
"types": "dist/index.d.ts",
|
|
9
10
|
"exports": {
|
|
10
11
|
".": {
|
|
12
|
+
"browser": "./dist/browser.js",
|
|
11
13
|
"import": "./dist/index.js",
|
|
12
14
|
"require": "./dist/index.cjs",
|
|
13
15
|
"types": "./dist/index.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"./browser": {
|
|
18
|
+
"import": "./dist/browser.js",
|
|
19
|
+
"script": "./dist/browser.umd.js"
|
|
14
20
|
}
|
|
15
21
|
},
|
|
16
22
|
"files": [
|