@wowsql/sdk 3.4.0 → 3.5.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 +45 -35
- package/dist/auth.d.ts +10 -1
- package/dist/auth.js +4 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -58,7 +58,7 @@ import { ProjectAuthClient } from '@wowsql/sdk';
|
|
|
58
58
|
|
|
59
59
|
const auth = new ProjectAuthClient({
|
|
60
60
|
projectUrl: 'myproject', // or https://myproject.wowsql.com
|
|
61
|
-
|
|
61
|
+
apiKey: 'your-anon-key' // Use anon key for client-side, service key for server-side
|
|
62
62
|
});
|
|
63
63
|
```
|
|
64
64
|
|
|
@@ -646,30 +646,34 @@ WOWSQL uses **different API keys for different operations**. Understanding which
|
|
|
646
646
|
|
|
647
647
|
### Key Types Overview
|
|
648
648
|
|
|
649
|
+
## 🔑 Unified Authentication
|
|
650
|
+
|
|
651
|
+
**✨ One Project = One Set of Keys for ALL Operations**
|
|
652
|
+
|
|
653
|
+
WOWSQL uses **unified authentication** - the same API keys work for both database operations AND authentication operations.
|
|
654
|
+
|
|
649
655
|
| Operation Type | Recommended Key | Alternative Key | Used By |
|
|
650
656
|
|---------------|----------------|-----------------|---------|
|
|
651
|
-
| **Database Operations** (CRUD) | Service Role Key (`
|
|
652
|
-
| **Authentication Operations** (OAuth, sign-in) |
|
|
657
|
+
| **Database Operations** (CRUD) | Service Role Key (`wowsql_service_...`) | Anonymous Key (`wowsql_anon_...`) | `WOWSQLClient` |
|
|
658
|
+
| **Authentication Operations** (OAuth, sign-in) | Anonymous Key (`wowsql_anon_...`) | Service Role Key (`wowsql_service_...`) | `ProjectAuthClient` |
|
|
653
659
|
|
|
654
660
|
### Where to Find Your Keys
|
|
655
661
|
|
|
656
|
-
All keys are found in: **WOWSQL Dashboard → Authentication → PROJECT KEYS**
|
|
657
|
-
|
|
658
|
-
1. **Service Role Key** (`wowbase_service_...`)
|
|
659
|
-
- Location: "Service Role Key (keep secret)"
|
|
660
|
-
- Used for: Database CRUD operations (recommended for server-side)
|
|
661
|
-
- Can also be used for authentication operations (fallback)
|
|
662
|
-
- **Important**: Click the eye icon to reveal this key
|
|
662
|
+
All keys are found in: **WOWSQL Dashboard → Settings → API Keys** or **Authentication → PROJECT KEYS**
|
|
663
663
|
|
|
664
|
-
|
|
665
|
-
- Location: "
|
|
666
|
-
- Used for:
|
|
667
|
-
|
|
664
|
+
1. **Anonymous Key** (`wowsql_anon_...`) ✨ **Unified Key**
|
|
665
|
+
- Location: "Anonymous Key (Public)"
|
|
666
|
+
- Used for:
|
|
667
|
+
- ✅ Client-side auth operations (signup, login, OAuth)
|
|
668
|
+
- ✅ Public/client-side database operations with limited permissions
|
|
669
|
+
- **Safe to expose** in frontend code (browser, mobile apps)
|
|
668
670
|
|
|
669
|
-
|
|
670
|
-
- Location: "
|
|
671
|
-
- Used for:
|
|
672
|
-
|
|
671
|
+
2. **Service Role Key** (`wowsql_service_...`) ✨ **Unified Key**
|
|
672
|
+
- Location: "Service Role Key (keep secret)"
|
|
673
|
+
- Used for:
|
|
674
|
+
- ✅ Server-side auth operations (admin, full access)
|
|
675
|
+
- ✅ Server-side database operations (full access, bypass RLS)
|
|
676
|
+
- **NEVER expose** in frontend code - server-side only!
|
|
673
677
|
|
|
674
678
|
### Database Operations
|
|
675
679
|
|
|
@@ -681,13 +685,13 @@ import WOWSQLClient from '@wowsql/sdk';
|
|
|
681
685
|
// Using Service Role Key (recommended for server-side, full access)
|
|
682
686
|
const client = new WOWSQLClient({
|
|
683
687
|
projectUrl: 'myproject',
|
|
684
|
-
apiKey: '
|
|
688
|
+
apiKey: 'wowsql_service_your-service-key-here' // Service Role Key
|
|
685
689
|
});
|
|
686
690
|
|
|
687
691
|
// Using Anonymous Key (for public/client-side access with limited permissions)
|
|
688
692
|
const client = new WOWSQLClient({
|
|
689
693
|
projectUrl: 'myproject',
|
|
690
|
-
apiKey: '
|
|
694
|
+
apiKey: 'wowsql_anon_your-anon-key-here' // Anonymous Key
|
|
691
695
|
});
|
|
692
696
|
|
|
693
697
|
// Query data
|
|
@@ -696,21 +700,21 @@ const users = await client.table('users').get();
|
|
|
696
700
|
|
|
697
701
|
### Authentication Operations
|
|
698
702
|
|
|
699
|
-
|
|
703
|
+
**✨ UNIFIED AUTHENTICATION:** Use the **same keys** as database operations!
|
|
700
704
|
|
|
701
705
|
```typescript
|
|
702
706
|
import { ProjectAuthClient } from '@wowsql/sdk';
|
|
703
707
|
|
|
704
|
-
// Using
|
|
708
|
+
// Using Anonymous Key (recommended for client-side auth operations)
|
|
705
709
|
const auth = new ProjectAuthClient({
|
|
706
710
|
projectUrl: 'myproject',
|
|
707
|
-
|
|
711
|
+
apiKey: 'wowsql_anon_your-anon-key-here' // Same key as database operations!
|
|
708
712
|
});
|
|
709
713
|
|
|
710
|
-
// Using Service Role Key (
|
|
714
|
+
// Using Service Role Key (for server-side auth operations)
|
|
711
715
|
const auth = new ProjectAuthClient({
|
|
712
716
|
projectUrl: 'myproject',
|
|
713
|
-
|
|
717
|
+
apiKey: 'wowsql_service_your-service-key-here' // Same key as database operations!
|
|
714
718
|
});
|
|
715
719
|
|
|
716
720
|
// OAuth authentication
|
|
@@ -720,36 +724,42 @@ const { authorizationUrl } = await auth.getOAuthAuthorizationUrl(
|
|
|
720
724
|
);
|
|
721
725
|
```
|
|
722
726
|
|
|
727
|
+
**Note:** The `publicApiKey` parameter is deprecated but still works for backward compatibility. Use `apiKey` instead.
|
|
728
|
+
|
|
723
729
|
### Environment Variables
|
|
724
730
|
|
|
725
731
|
Best practice: Use environment variables for API keys:
|
|
726
732
|
|
|
727
733
|
```typescript
|
|
734
|
+
// UNIFIED AUTHENTICATION: Same keys for both operations!
|
|
735
|
+
|
|
728
736
|
// Database operations - Service Role Key
|
|
729
737
|
const dbClient = new WOWSQLClient({
|
|
730
738
|
projectUrl: process.env.WOWSQL_PROJECT_URL!,
|
|
731
739
|
apiKey: process.env.WOWSQL_SERVICE_ROLE_KEY! // or WOWSQL_ANON_KEY
|
|
732
740
|
});
|
|
733
741
|
|
|
734
|
-
// Authentication operations -
|
|
742
|
+
// Authentication operations - Use the SAME key!
|
|
735
743
|
const authClient = new ProjectAuthClient({
|
|
736
744
|
projectUrl: process.env.WOWSQL_PROJECT_URL!,
|
|
737
|
-
|
|
745
|
+
apiKey: process.env.WOWSQL_ANON_KEY! // Same key for client-side auth
|
|
746
|
+
// Or use WOWSQL_SERVICE_ROLE_KEY for server-side auth
|
|
738
747
|
});
|
|
739
748
|
```
|
|
740
749
|
|
|
741
750
|
### Key Usage Summary
|
|
742
751
|
|
|
752
|
+
**✨ UNIFIED AUTHENTICATION:**
|
|
743
753
|
- **`WOWSQLClient`** → Uses **Service Role Key** or **Anonymous Key** for database operations
|
|
744
|
-
- **`ProjectAuthClient`** → Uses **
|
|
745
|
-
- **
|
|
746
|
-
- **
|
|
747
|
-
- **
|
|
754
|
+
- **`ProjectAuthClient`** → Uses **Anonymous Key** (client-side) or **Service Role Key** (server-side) for authentication operations
|
|
755
|
+
- **Same keys work for both** database AND authentication operations! 🎉
|
|
756
|
+
- **Anonymous Key** (`wowsql_anon_...`) → Client-side operations (auth + database)
|
|
757
|
+
- **Service Role Key** (`wowsql_service_...`) → Server-side operations (auth + database)
|
|
748
758
|
|
|
749
759
|
### Security Best Practices
|
|
750
760
|
|
|
751
761
|
1. **Never expose Service Role Key** in client-side code or public repositories
|
|
752
|
-
2. **Use
|
|
762
|
+
2. **Use Anonymous Key** for client-side authentication flows (same key as database operations)
|
|
753
763
|
3. **Use Anonymous Key** for public database access with limited permissions
|
|
754
764
|
4. **Store keys in environment variables**, never hardcode them
|
|
755
765
|
5. **Rotate keys regularly** if compromised
|
|
@@ -759,11 +769,11 @@ const authClient = new ProjectAuthClient({
|
|
|
759
769
|
**Error: "Invalid API key for project"**
|
|
760
770
|
- Ensure you're using the correct key type for the operation
|
|
761
771
|
- Database operations require Service Role Key or Anonymous Key
|
|
762
|
-
- Authentication operations require
|
|
772
|
+
- Authentication operations require Anonymous Key (client-side) or Service Role Key (server-side)
|
|
763
773
|
- Verify the key is copied correctly (no extra spaces)
|
|
764
774
|
|
|
765
775
|
**Error: "Authentication failed"**
|
|
766
|
-
- Check that you're using
|
|
776
|
+
- Check that you're using the correct key: Anonymous Key for client-side, Service Role Key for server-side
|
|
767
777
|
- Verify the project URL matches your dashboard
|
|
768
778
|
- Ensure the key hasn't been revoked or expired
|
|
769
779
|
|
|
@@ -948,7 +958,7 @@ try {
|
|
|
948
958
|
|
|
949
959
|
### Can I use this in the browser?
|
|
950
960
|
|
|
951
|
-
Yes! The SDK works in both Node.js and browser environments. However, **never expose your Service Role Key in client-side code** for production applications. Use
|
|
961
|
+
Yes! The SDK works in both Node.js and browser environments. However, **never expose your Service Role Key in client-side code** for production applications. Use **Anonymous Key** for both authentication and limited database access. For full database operations, use a backend proxy with Service Role Key.
|
|
952
962
|
|
|
953
963
|
### What about rate limits?
|
|
954
964
|
|
package/dist/auth.d.ts
CHANGED
|
@@ -7,7 +7,16 @@ export interface ProjectAuthClientConfig {
|
|
|
7
7
|
secure?: boolean;
|
|
8
8
|
/** Request timeout in milliseconds */
|
|
9
9
|
timeout?: number;
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Unified API key - Anonymous Key (wowsql_anon_...) for client-side,
|
|
12
|
+
* or Service Role Key (wowsql_service_...) for server-side.
|
|
13
|
+
* UNIFIED AUTHENTICATION: Same key works for both auth and database operations.
|
|
14
|
+
*/
|
|
15
|
+
apiKey?: string;
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated Use apiKey instead. Kept for backward compatibility.
|
|
18
|
+
* Unified API key - same as apiKey parameter.
|
|
19
|
+
*/
|
|
11
20
|
publicApiKey?: string;
|
|
12
21
|
/** Custom token storage implementation (defaults to in-memory) */
|
|
13
22
|
storage?: AuthTokenStorage;
|
package/dist/auth.js
CHANGED
|
@@ -31,12 +31,15 @@ class ProjectAuthClient {
|
|
|
31
31
|
this.storage = config.storage || new MemoryAuthTokenStorage();
|
|
32
32
|
this.accessToken = this.storage.getAccessToken();
|
|
33
33
|
this.refreshToken = this.storage.getRefreshToken();
|
|
34
|
+
// UNIFIED AUTHENTICATION: Use apiKey (new) or publicApiKey (deprecated) for backward compatibility
|
|
35
|
+
const unifiedApiKey = config.apiKey || config.publicApiKey;
|
|
34
36
|
this.client = axios_1.default.create({
|
|
35
37
|
baseURL: baseUrl,
|
|
36
38
|
timeout: config.timeout ?? 30000,
|
|
37
39
|
headers: {
|
|
38
40
|
'Content-Type': 'application/json',
|
|
39
|
-
|
|
41
|
+
// UNIFIED AUTHENTICATION: Use Authorization header (same as database operations)
|
|
42
|
+
...(unifiedApiKey ? { 'Authorization': `Bearer ${unifiedApiKey}` } : {}),
|
|
40
43
|
},
|
|
41
44
|
});
|
|
42
45
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wowsql/sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "Official TypeScript/JavaScript SDK for WowSQL - MySQL Backend-as-a-Service with S3 Storage, type-safe queries and fluent API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|