@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 +1 -1
- package/src/index.ts +2 -2
- package/src/lib/auth/AuthClient.ts +8 -14
- package/src/lib/user/UserClient.ts +2 -2
- package/src/lib/user/types.ts +76 -44
package/package.json
CHANGED
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
|
|
197
|
-
*
|
|
198
|
+
* Get current user from API
|
|
199
|
+
* @returns Promise with user data or null if not authenticated
|
|
198
200
|
*/
|
|
199
|
-
getCurrentUser():
|
|
200
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
25
|
-
return await this.client.httpClient.
|
|
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) {
|
package/src/lib/user/types.ts
CHANGED
|
@@ -1,60 +1,92 @@
|
|
|
1
1
|
export interface UserCreateRequest {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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 {
|