@taruvi/sdk 1.2.8 → 1.2.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taruvi/sdk",
3
- "version": "1.2.8",
3
+ "version": "1.2.9",
4
4
  "description": "Taruvi SDK",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -1,4 +1,6 @@
1
1
  import type { Client } from "../../client.js";
2
+ import type { UserDataResponse } from "../user/types.js";
3
+ import { UserRoutes } from "../../lib-internal/routes/UserRoutes.js";
2
4
 
3
5
  /**
4
6
  * Auth Client - Handles user authentication using Web UI Flow
@@ -193,26 +195,18 @@ export class Auth {
193
195
  }
194
196
 
195
197
  /**
196
- * Get current user info from access token (JWT decode)
197
- * Note: This only decodes the token, doesn't validate signature
198
+ * Get current user from API
199
+ * @returns Promise with user data or null if not authenticated
198
200
  */
199
- getCurrentUser(): any | null {
200
- const accessToken = this.getAccessToken()
201
-
202
- if (!accessToken) {
201
+ async getCurrentUser(): Promise<UserDataResponse | null> {
202
+ if (!this.isUserAuthenticated()) {
203
203
  return null
204
204
  }
205
205
 
206
206
  try {
207
- // Decode JWT (middle part is payload)
208
- const parts = accessToken.split(".")
209
- if (parts.length !== 3 || !parts[1]) {
210
- throw new Error("Invalid JWT format")
211
- }
212
- const payload = JSON.parse(atob(parts[1]))
213
- return payload
207
+ return await this.client.httpClient.get<UserDataResponse>(UserRoutes.getCurrentUser())
214
208
  } catch (error) {
215
- console.error("Failed to decode access token:", error)
209
+ console.error("Failed to fetch current user:", error)
216
210
  return null
217
211
  }
218
212
  }
@@ -4,9 +4,9 @@ export interface UserCreateRequest {
4
4
  email: string
5
5
  first_name: string
6
6
  last_name: string
7
+ password: string
8
+ confirm_password: string
7
9
  // Optional fields
8
- password?: string
9
- confirm_password?: string
10
10
  is_active?: boolean
11
11
  is_staff?: boolean
12
12
  attributes?: string
@@ -26,19 +26,44 @@ export interface UserCreateResponse {
26
26
  date_joined: string
27
27
  }
28
28
 
29
+ export interface UserGroup {
30
+ id: number
31
+ name: string
32
+ }
33
+
34
+ export interface UserPermission {
35
+ id: number
36
+ name: string
37
+ codename: string
38
+ content_type: string // "app_label.model"
39
+ }
40
+
41
+ export interface UserRole {
42
+ name: string
43
+ slug: string
44
+ type: "app_role"
45
+ app_slug: string
46
+ source: "direct" | "site_role" | "inherited"
47
+ }
48
+
29
49
  export interface UserDataResponse {
30
- id: number,
31
- username: string,
32
- email: string,
33
- first_name: string,
34
- last_name: string,
35
- full_name: string,
36
- is_active: boolean,
37
- is_staff: boolean,
38
- is_deleted: boolean,
39
- date_joined: string, // ISO 8601 date-time string
40
- last_login: string, // ISO 8601 date-time string
41
- attributes: string
50
+ id: number
51
+ username: string
52
+ email: string
53
+ first_name: string
54
+ last_name: string
55
+ full_name: string
56
+ is_active: boolean
57
+ is_staff: boolean
58
+ is_superuser: boolean
59
+ is_deleted: boolean
60
+ date_joined: string // ISO 8601 date-time string
61
+ last_login: string // ISO 8601 date-time string
62
+ groups: UserGroup[]
63
+ user_permissions: UserPermission[]
64
+ attributes: Record<string, unknown>
65
+ missing_attributes: string[]
66
+ roles: UserRole[]
42
67
  }
43
68
 
44
69
  export interface UserUpdateRequest {