@baasix/sdk 0.1.2 → 0.1.3
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 +70 -1
- package/dist/index.cjs +24 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +24 -30
- package/dist/index.js.map +1 -1
- package/dist/modules/auth.cjs +24 -30
- package/dist/modules/auth.cjs.map +1 -1
- package/dist/modules/auth.d.cts +11 -12
- package/dist/modules/auth.d.ts +11 -12
- package/dist/modules/auth.js +24 -30
- package/dist/modules/auth.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -145,9 +145,12 @@ const result = await baasix.auth.login({
|
|
|
145
145
|
### Get Current User
|
|
146
146
|
|
|
147
147
|
```typescript
|
|
148
|
-
// From server (makes API call)
|
|
148
|
+
// From server (makes API call to /auth/me)
|
|
149
149
|
const user = await baasix.auth.getUser();
|
|
150
150
|
|
|
151
|
+
// Alias for getUser()
|
|
152
|
+
const user = await baasix.auth.me();
|
|
153
|
+
|
|
151
154
|
// From cache (no API call)
|
|
152
155
|
const cachedUser = await baasix.auth.getCachedUser();
|
|
153
156
|
```
|
|
@@ -192,6 +195,49 @@ await baasix.auth.forgotPassword({
|
|
|
192
195
|
await baasix.auth.resetPassword('reset-token', 'newpassword123');
|
|
193
196
|
```
|
|
194
197
|
|
|
198
|
+
### Change Password
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
// Change current user's password (requires current password)
|
|
202
|
+
await baasix.auth.changePassword('currentPassword', 'newPassword');
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Token Management
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
// Get current access token
|
|
209
|
+
const token = await baasix.auth.getToken();
|
|
210
|
+
|
|
211
|
+
// Set a static token (for server-side/service accounts)
|
|
212
|
+
await baasix.auth.setToken('your-api-token');
|
|
213
|
+
|
|
214
|
+
// Refresh the current token
|
|
215
|
+
const { token, expiresIn } = await baasix.auth.refreshToken();
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Session & State Management
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
// Initialize auth state from storage (call on app startup)
|
|
222
|
+
const state = await baasix.auth.initialize();
|
|
223
|
+
|
|
224
|
+
// Get current auth state
|
|
225
|
+
const { user, isAuthenticated } = await baasix.auth.getState();
|
|
226
|
+
|
|
227
|
+
// Check if session is valid with server
|
|
228
|
+
const isValid = await baasix.auth.checkSession();
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Email Verification
|
|
232
|
+
|
|
233
|
+
```typescript
|
|
234
|
+
// Request email verification
|
|
235
|
+
await baasix.auth.requestEmailVerification('https://myapp.com/verify-email');
|
|
236
|
+
|
|
237
|
+
// Verify email with token
|
|
238
|
+
await baasix.auth.verifyEmail('verification-token');
|
|
239
|
+
```
|
|
240
|
+
|
|
195
241
|
### Multi-Tenant
|
|
196
242
|
|
|
197
243
|
```typescript
|
|
@@ -200,6 +246,29 @@ const tenants = await baasix.auth.getTenants();
|
|
|
200
246
|
|
|
201
247
|
// Switch tenant
|
|
202
248
|
const { user, token } = await baasix.auth.switchTenant('tenant-uuid');
|
|
249
|
+
|
|
250
|
+
// Send invitation
|
|
251
|
+
await baasix.auth.sendInvite({
|
|
252
|
+
email: 'newuser@example.com',
|
|
253
|
+
roleId: 'editor-role-uuid',
|
|
254
|
+
tenantId: 'tenant-uuid',
|
|
255
|
+
redirectUrl: 'https://myapp.com/accept-invite',
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
// Verify invitation
|
|
259
|
+
const inviteInfo = await baasix.auth.verifyInvite('invite-token');
|
|
260
|
+
|
|
261
|
+
// Accept invitation (for existing users)
|
|
262
|
+
const { user, token } = await baasix.auth.acceptInvite('invite-token');
|
|
263
|
+
|
|
264
|
+
// Register with invitation (for new users)
|
|
265
|
+
const { user, token } = await baasix.auth.registerWithInvite({
|
|
266
|
+
email: 'newuser@example.com',
|
|
267
|
+
password: 'password123',
|
|
268
|
+
firstName: 'John',
|
|
269
|
+
lastName: 'Doe',
|
|
270
|
+
inviteToken: 'invite-token',
|
|
271
|
+
});
|
|
203
272
|
```
|
|
204
273
|
|
|
205
274
|
## Items (CRUD Operations)
|
package/dist/index.cjs
CHANGED
|
@@ -614,6 +614,19 @@ var AuthModule = class {
|
|
|
614
614
|
throw error;
|
|
615
615
|
}
|
|
616
616
|
}
|
|
617
|
+
/**
|
|
618
|
+
* Alias for getUser() - Get the current authenticated user from the server
|
|
619
|
+
* Calls the /auth/me endpoint
|
|
620
|
+
*
|
|
621
|
+
* @example
|
|
622
|
+
* ```typescript
|
|
623
|
+
* const user = await baasix.auth.me();
|
|
624
|
+
* console.log(user?.email);
|
|
625
|
+
* ```
|
|
626
|
+
*/
|
|
627
|
+
async me() {
|
|
628
|
+
return this.getUser();
|
|
629
|
+
}
|
|
617
630
|
/**
|
|
618
631
|
* Get the cached current user (does not make an API call)
|
|
619
632
|
*
|
|
@@ -762,7 +775,7 @@ var AuthModule = class {
|
|
|
762
775
|
*/
|
|
763
776
|
async forgotPassword(options) {
|
|
764
777
|
await this.client.post(
|
|
765
|
-
"/auth/
|
|
778
|
+
"/auth/password/reset",
|
|
766
779
|
{
|
|
767
780
|
email: options.email,
|
|
768
781
|
link: options.redirectUrl
|
|
@@ -780,8 +793,8 @@ var AuthModule = class {
|
|
|
780
793
|
*/
|
|
781
794
|
async resetPassword(token, newPassword) {
|
|
782
795
|
await this.client.post(
|
|
783
|
-
|
|
784
|
-
{
|
|
796
|
+
`/auth/password/reset/${encodeURIComponent(token)}`,
|
|
797
|
+
{ password: newPassword },
|
|
785
798
|
{ skipAuth: true }
|
|
786
799
|
);
|
|
787
800
|
}
|
|
@@ -794,28 +807,11 @@ var AuthModule = class {
|
|
|
794
807
|
* ```
|
|
795
808
|
*/
|
|
796
809
|
async changePassword(currentPassword, newPassword) {
|
|
797
|
-
await this.client.post("/auth/change
|
|
810
|
+
await this.client.post("/auth/password/change", {
|
|
798
811
|
currentPassword,
|
|
799
812
|
newPassword
|
|
800
813
|
});
|
|
801
814
|
}
|
|
802
|
-
/**
|
|
803
|
-
* Update the current user's profile
|
|
804
|
-
*
|
|
805
|
-
* @example
|
|
806
|
-
* ```typescript
|
|
807
|
-
* const updatedUser = await baasix.auth.updateProfile({
|
|
808
|
-
* firstName: 'Jane',
|
|
809
|
-
* lastName: 'Doe'
|
|
810
|
-
* });
|
|
811
|
-
* ```
|
|
812
|
-
*/
|
|
813
|
-
async updateProfile(data) {
|
|
814
|
-
const response = await this.client.patch("/auth/me", data);
|
|
815
|
-
await this.storage.set(STORAGE_KEYS.USER, JSON.stringify(response.data));
|
|
816
|
-
this.emitAuthStateChange("USER_UPDATED", response.data);
|
|
817
|
-
return response.data;
|
|
818
|
-
}
|
|
819
815
|
/**
|
|
820
816
|
* Get available tenants for the current user (multi-tenant mode)
|
|
821
817
|
*
|
|
@@ -826,7 +822,7 @@ var AuthModule = class {
|
|
|
826
822
|
*/
|
|
827
823
|
async getTenants() {
|
|
828
824
|
const response = await this.client.get("/auth/tenants");
|
|
829
|
-
return response.
|
|
825
|
+
return response.tenants;
|
|
830
826
|
}
|
|
831
827
|
/**
|
|
832
828
|
* Switch to a different tenant (multi-tenant mode)
|
|
@@ -947,7 +943,7 @@ var AuthModule = class {
|
|
|
947
943
|
* ```
|
|
948
944
|
*/
|
|
949
945
|
async requestEmailVerification(redirectUrl) {
|
|
950
|
-
await this.client.post("/auth/
|
|
946
|
+
await this.client.post("/auth/email/verify", {
|
|
951
947
|
link: redirectUrl
|
|
952
948
|
});
|
|
953
949
|
}
|
|
@@ -963,8 +959,7 @@ var AuthModule = class {
|
|
|
963
959
|
* ```
|
|
964
960
|
*/
|
|
965
961
|
async verifyEmail(token) {
|
|
966
|
-
await this.client.get(
|
|
967
|
-
params: { token },
|
|
962
|
+
await this.client.get(`/auth/email/verify/${encodeURIComponent(token)}`, {
|
|
968
963
|
skipAuth: true
|
|
969
964
|
});
|
|
970
965
|
}
|
|
@@ -979,7 +974,7 @@ var AuthModule = class {
|
|
|
979
974
|
async checkSession() {
|
|
980
975
|
try {
|
|
981
976
|
const response = await this.client.get("/auth/check");
|
|
982
|
-
return response.
|
|
977
|
+
return response.valid;
|
|
983
978
|
} catch {
|
|
984
979
|
return false;
|
|
985
980
|
}
|
|
@@ -1024,16 +1019,15 @@ var AuthModule = class {
|
|
|
1024
1019
|
*/
|
|
1025
1020
|
async verifyInvite(token, redirectUrl) {
|
|
1026
1021
|
const response = await this.client.get(
|
|
1027
|
-
|
|
1022
|
+
`/auth/verify-invite/${encodeURIComponent(token)}`,
|
|
1028
1023
|
{
|
|
1029
1024
|
params: {
|
|
1030
|
-
token,
|
|
1031
1025
|
link: redirectUrl
|
|
1032
1026
|
},
|
|
1033
1027
|
skipAuth: true
|
|
1034
1028
|
}
|
|
1035
1029
|
);
|
|
1036
|
-
return response
|
|
1030
|
+
return response;
|
|
1037
1031
|
}
|
|
1038
1032
|
/**
|
|
1039
1033
|
* Accept an invitation (for existing users)
|
|
@@ -1046,7 +1040,7 @@ var AuthModule = class {
|
|
|
1046
1040
|
async acceptInvite(token) {
|
|
1047
1041
|
const response = await this.client.post(
|
|
1048
1042
|
"/auth/accept-invite",
|
|
1049
|
-
{ token }
|
|
1043
|
+
{ inviteToken: token }
|
|
1050
1044
|
);
|
|
1051
1045
|
await this.storeTokens(response);
|
|
1052
1046
|
this.emitAuthStateChange("SIGNED_IN", response.user);
|