@taruvi/sdk 1.2.7 → 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.7",
3
+ "version": "1.2.9",
4
4
  "description": "Taruvi SDK",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
package/src/index.ts CHANGED
@@ -16,9 +16,9 @@ export { Analytics } from "./lib/Analytics/AnalyticsClient.js"
16
16
  // Export types
17
17
  export type { TaruviConfig, StorageFilters, DatabaseFilters } from "./types.js"
18
18
  export type { AuthTokens } from "./lib-internal/token/TokenClient.js"
19
- export type { UserCreateRequest, UserCreateResponse as UserResponse, UserDataResponse } from "./lib/user/types.js"
19
+ export type { UserCreateRequest, UserCreateResponse as UserResponse, UserDataResponse, UserUpdateRequest, UserUpdateResponse } from "./lib/user/types.js"
20
20
  export type { Principal, Resource, Resources } from "./lib/Policy/types.js"
21
- export type { RoleResponse } from "./lib/App/types.js"
21
+ export type { RoleResponse, SettingsResponse as AppSettingsResponse } from "./lib/App/types.js"
22
22
  export type { FunctionRequest, FunctionResponse, FunctionInvocation } from "./lib/Function/types.js"
23
23
  export type { DatabaseRequest, DatabaseResponse, FilterOperator, SortOrder } from "./lib/Database/types.js"
24
24
  export type { StorageRequest, StorageUpdateRequest, StorageResponse } from "./lib/Storage/types.js"
@@ -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
  }
@@ -21,8 +21,8 @@ export class User {
21
21
  return await this.client.httpClient.put(UserRoutes.updateUser(username), body)
22
22
  }
23
23
 
24
- async getUser(username: string, body: UserUpdateRequest): Promise<UserCreateResponse> {
25
- return await this.client.httpClient.put(UserRoutes.getUser(username), body)
24
+ async getUser(username: string): Promise<UserDataResponse> {
25
+ return await this.client.httpClient.get<UserDataResponse>(UserRoutes.getUser(username))
26
26
  }
27
27
 
28
28
  async list(filters: UserList) {
@@ -1,60 +1,92 @@
1
1
  export interface UserCreateRequest {
2
- username: string,
3
- email: string,
4
- password: string,
5
- confirm_password: string,
6
- first_name: string,
7
- last_name: string,
8
- is_active: boolean,
9
- is_staff: boolean,
10
- attributes: string
2
+ // Required fields
3
+ username: string
4
+ email: string
5
+ first_name: string
6
+ last_name: string
7
+ password: string
8
+ confirm_password: string
9
+ // Optional fields
10
+ is_active?: boolean
11
+ is_staff?: boolean
12
+ attributes?: string
11
13
  }
12
14
 
13
15
  export interface UserCreateResponse {
14
- username: string,
15
- email: string,
16
- first_name: string,
17
- last_name: string,
18
- is_active: boolean,
19
- is_staff: boolean,
20
- attributes: string
16
+ id: number
17
+ uuid: string
18
+ username: string
19
+ email: string
20
+ first_name: string
21
+ last_name: string
22
+ is_active: boolean
23
+ is_staff: boolean
24
+ is_superuser: boolean
25
+ is_deleted: boolean
26
+ date_joined: string
27
+ }
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"
21
47
  }
22
48
 
23
49
  export interface UserDataResponse {
24
- id: number,
25
- username: string,
26
- email: string,
27
- first_name: string,
28
- last_name: string,
29
- full_name: string,
30
- is_active: boolean,
31
- is_staff: boolean,
32
- is_deleted: boolean,
33
- date_joined: string, // ISO 8601 date-time string
34
- last_login: string, // ISO 8601 date-time string
35
- 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[]
36
67
  }
37
68
 
38
69
  export interface UserUpdateRequest {
39
- username?: string,
40
- email?: string,
41
- password?: string,
42
- confirm_password?: string,
43
- first_name?: string,
44
- last_name?: string,
45
- is_active?: boolean,
46
- is_staff?: boolean,
47
- attributes?: string
70
+ username?: string
71
+ email?: string
72
+ first_name?: string
73
+ last_name?: string
74
+ is_active?: boolean
75
+ is_staff?: boolean
48
76
  }
49
77
 
50
78
  export interface UserUpdateResponse {
51
- username: string,
52
- email: string,
53
- first_name: string,
54
- last_name: string,
55
- is_active: boolean,
56
- is_staff: boolean,
57
- attributes: string
79
+ id: number
80
+ uuid: string
81
+ username: string
82
+ email: string
83
+ first_name: string
84
+ last_name: string
85
+ is_active: boolean
86
+ is_staff: boolean
87
+ is_superuser: boolean
88
+ is_deleted: boolean
89
+ date_joined: string
58
90
  }
59
91
 
60
92
  export interface UserList {