@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/README.md
CHANGED
|
@@ -41,6 +41,48 @@ These fields are enforced by Firestore Security Rules and ensure proper data iso
|
|
|
41
41
|
npm install @seaverse/data-service-sdk
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
+
## Browser vs Node.js Usage
|
|
45
|
+
|
|
46
|
+
### For Build Tools (Webpack/Vite/Parcel)
|
|
47
|
+
|
|
48
|
+
The SDK automatically uses the correct version:
|
|
49
|
+
|
|
50
|
+
```javascript
|
|
51
|
+
import { DataServiceClient } from '@seaverse/data-service-sdk';
|
|
52
|
+
// Bundler will automatically use the browser version
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### For Direct Browser Use (Without Build Tools)
|
|
56
|
+
|
|
57
|
+
**Option 1: ES Module (Recommended)**
|
|
58
|
+
|
|
59
|
+
```html
|
|
60
|
+
<script type="module">
|
|
61
|
+
import { DataServiceClient } from 'https://unpkg.com/@seaverse/data-service-sdk/dist/browser.js';
|
|
62
|
+
|
|
63
|
+
const client = new DataServiceClient();
|
|
64
|
+
// Use the client...
|
|
65
|
+
</script>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**Option 2: UMD via Script Tag**
|
|
69
|
+
|
|
70
|
+
```html
|
|
71
|
+
<script src="https://unpkg.com/@seaverse/data-service-sdk/dist/browser.umd.js"></script>
|
|
72
|
+
<script>
|
|
73
|
+
const client = new SeaVerseDataService.DataServiceClient();
|
|
74
|
+
// Use the client...
|
|
75
|
+
</script>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### For Node.js
|
|
79
|
+
|
|
80
|
+
```javascript
|
|
81
|
+
const { DataServiceClient } = require('@seaverse/data-service-sdk');
|
|
82
|
+
// or
|
|
83
|
+
import { DataServiceClient } from '@seaverse/data-service-sdk';
|
|
84
|
+
```
|
|
85
|
+
|
|
44
86
|
## Quick Start
|
|
45
87
|
|
|
46
88
|
### For Authenticated Users
|
|
@@ -69,7 +111,7 @@ const firestoreToken = await dataClient.generateFirestoreToken({
|
|
|
69
111
|
// Step 3: Initialize Firebase
|
|
70
112
|
const app = initializeApp({ projectId: firestoreToken.project_id });
|
|
71
113
|
const auth = getAuth(app);
|
|
72
|
-
await signInWithCustomToken(auth, firestoreToken.
|
|
114
|
+
await signInWithCustomToken(auth, firestoreToken.custom_token);
|
|
73
115
|
const db = getFirestore(app);
|
|
74
116
|
|
|
75
117
|
// Step 4: Use Firestore with proper paths
|
|
@@ -118,7 +160,7 @@ const guestToken = await dataClient.generateGuestFirestoreToken({
|
|
|
118
160
|
// Step 2: Initialize Firebase
|
|
119
161
|
const app = initializeApp({ projectId: guestToken.project_id });
|
|
120
162
|
const auth = getAuth(app);
|
|
121
|
-
await signInWithCustomToken(auth, guestToken.
|
|
163
|
+
await signInWithCustomToken(auth, guestToken.custom_token);
|
|
122
164
|
const db = getFirestore(app);
|
|
123
165
|
|
|
124
166
|
// Step 3: Guest can write to publicData
|
|
@@ -189,8 +231,7 @@ interface GenerateFirestoreTokenRequest {
|
|
|
189
231
|
|
|
190
232
|
```typescript
|
|
191
233
|
interface FirestoreTokenResponse {
|
|
192
|
-
|
|
193
|
-
refresh_token?: string; // Firebase Refresh Token (optional)
|
|
234
|
+
custom_token: string; // Firebase Custom Token - use with signInWithCustomToken()
|
|
194
235
|
project_id: string; // Firebase Project ID for initializeApp()
|
|
195
236
|
database_id: string; // Firestore Database ID
|
|
196
237
|
app_id?: string; // Application ID (use in Firestore paths)
|
|
@@ -208,7 +249,7 @@ const firestoreToken = await client.generateFirestoreToken({
|
|
|
208
249
|
app_id: 'my-app-123'
|
|
209
250
|
});
|
|
210
251
|
|
|
211
|
-
console.log('Token:', firestoreToken.
|
|
252
|
+
console.log('Custom Token:', firestoreToken.custom_token);
|
|
212
253
|
console.log('User ID:', firestoreToken.user_id);
|
|
213
254
|
console.log('App ID:', firestoreToken.app_id);
|
|
214
255
|
```
|
|
@@ -243,7 +284,7 @@ const guestToken = await client.generateGuestFirestoreToken({
|
|
|
243
284
|
app_id: 'my-app-123'
|
|
244
285
|
});
|
|
245
286
|
|
|
246
|
-
console.log('Guest Token:', guestToken.
|
|
287
|
+
console.log('Guest Custom Token:', guestToken.custom_token);
|
|
247
288
|
console.log('Guest User ID:', guestToken.user_id);
|
|
248
289
|
console.log('Role:', guestToken.role); // 'guest'
|
|
249
290
|
```
|
|
@@ -451,7 +492,7 @@ async function completeExample() {
|
|
|
451
492
|
// 3. Initialize Firebase
|
|
452
493
|
const app = initializeApp({ projectId: firestoreToken.project_id });
|
|
453
494
|
const auth = getAuth(app);
|
|
454
|
-
await signInWithCustomToken(auth, firestoreToken.
|
|
495
|
+
await signInWithCustomToken(auth, firestoreToken.custom_token);
|
|
455
496
|
const db = getFirestore(app);
|
|
456
497
|
|
|
457
498
|
const userId = firestoreToken.user_id;
|
|
@@ -522,6 +563,55 @@ For issues and questions, please visit:
|
|
|
522
563
|
- GitHub: https://github.com/seaverseai/sv-sdk
|
|
523
564
|
- Email: support@seaverse.com
|
|
524
565
|
|
|
566
|
+
## Browser Example (Vanilla JavaScript)
|
|
567
|
+
|
|
568
|
+
Here's a complete example for using the SDK directly in the browser without any build tools:
|
|
569
|
+
|
|
570
|
+
```html
|
|
571
|
+
<!DOCTYPE html>
|
|
572
|
+
<html>
|
|
573
|
+
<head>
|
|
574
|
+
<title>SeaVerse Data Service SDK - Browser Example</title>
|
|
575
|
+
</head>
|
|
576
|
+
<body>
|
|
577
|
+
<h1>Firestore Token Demo</h1>
|
|
578
|
+
<button id="getGuestToken">Get Guest Token</button>
|
|
579
|
+
<pre id="output"></pre>
|
|
580
|
+
|
|
581
|
+
<script type="module">
|
|
582
|
+
// Import from CDN
|
|
583
|
+
import { DataServiceClient } from 'https://unpkg.com/@seaverse/data-service-sdk/dist/browser.js';
|
|
584
|
+
|
|
585
|
+
const output = document.getElementById('output');
|
|
586
|
+
const client = new DataServiceClient();
|
|
587
|
+
|
|
588
|
+
document.getElementById('getGuestToken').addEventListener('click', async () => {
|
|
589
|
+
try {
|
|
590
|
+
output.textContent = 'Getting guest token...';
|
|
591
|
+
|
|
592
|
+
const guestToken = await client.generateGuestFirestoreToken({
|
|
593
|
+
app_id: 'my-app-123'
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
output.textContent = JSON.stringify({
|
|
597
|
+
custom_token: guestToken.custom_token.substring(0, 50) + '...',
|
|
598
|
+
user_id: guestToken.user_id,
|
|
599
|
+
role: guestToken.role,
|
|
600
|
+
project_id: guestToken.project_id,
|
|
601
|
+
expires_in: guestToken.expires_in
|
|
602
|
+
}, null, 2);
|
|
603
|
+
|
|
604
|
+
// Now you can use this token with Firebase SDK
|
|
605
|
+
console.log('Guest token received:', guestToken);
|
|
606
|
+
} catch (error) {
|
|
607
|
+
output.textContent = 'Error: ' + error.message;
|
|
608
|
+
}
|
|
609
|
+
});
|
|
610
|
+
</script>
|
|
611
|
+
</body>
|
|
612
|
+
</html>
|
|
613
|
+
```
|
|
614
|
+
|
|
525
615
|
## Related SDKs
|
|
526
616
|
|
|
527
617
|
- [@seaverse/auth-sdk](../auth-sdk) - User authentication and account management
|