tale-js-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/dist/acl/index.d.ts +170 -0
- package/dist/acl/index.js +747 -0
- package/dist/acl/types.d.ts +208 -0
- package/dist/acl/types.js +1 -0
- package/dist/auth/index.d.ts +2 -134
- package/dist/auth/index.js +120 -96
- package/dist/auth/types.d.ts +122 -0
- package/dist/auth/types.js +1 -0
- package/dist/common/types.d.ts +76 -0
- package/dist/common/types.js +3 -0
- package/dist/errors.js +18 -18
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/rbac/acl.d.ts +152 -0
- package/dist/rbac/acl.js +723 -0
- package/dist/rbac/index.d.ts +2 -0
- package/dist/rbac/index.js +2 -0
- package/dist/rbac/rbac.d.ts +198 -0
- package/dist/rbac/rbac.js +984 -0
- package/dist/rbac/types.d.ts +356 -0
- package/dist/rbac/types.js +1 -0
- package/dist/rbac/user-group.d.ts +122 -0
- package/dist/rbac/user-group.js +570 -0
- package/dist/status.js +3 -3
- package/dist/token.d.ts +1 -1
- package/dist/token.js +5 -4
- package/dist/user/index.d.ts +2 -142
- package/dist/user/index.js +60 -59
- package/dist/user/types.d.ts +96 -0
- package/dist/user/types.js +1 -0
- package/dist/user-group/index.d.ts +230 -0
- package/dist/user-group/index.js +560 -0
- package/dist/user-group/types.d.ts +61 -0
- package/dist/user-group/types.js +1 -0
- package/package.json +13 -14
- package/dist/auth.d.ts +0 -271
- package/dist/auth.js +0 -461
- package/dist/client.d.ts +0 -20
- package/dist/client.js +0 -62
- package/dist/info.d.ts +0 -9
- package/dist/info.js +0 -18
- package/dist/package.json +0 -36
- package/dist/src/index.d.ts +0 -1
- package/dist/src/index.js +0 -1
- package/dist/src/info.d.ts +0 -6
- package/dist/src/info.js +0 -4
- package/dist/user.d.ts +0 -242
- package/dist/user.js +0 -331
package/dist/user/index.d.ts
CHANGED
|
@@ -1,145 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
password_encrypted?: string;
|
|
4
|
-
nickname?: string;
|
|
5
|
-
phone?: string;
|
|
6
|
-
email?: string;
|
|
7
|
-
avatar_url?: string;
|
|
8
|
-
role_ids?: string[];
|
|
9
|
-
}
|
|
10
|
-
export interface AppInfo {
|
|
11
|
-
app_id: string;
|
|
12
|
-
org_id: string;
|
|
13
|
-
app_key: string;
|
|
14
|
-
app_name: string;
|
|
15
|
-
}
|
|
16
|
-
export interface User {
|
|
17
|
-
user_id: string;
|
|
18
|
-
nick_name: string;
|
|
19
|
-
avatar_url: string;
|
|
20
|
-
username: string;
|
|
21
|
-
email: string;
|
|
22
|
-
phone: string;
|
|
23
|
-
registered_at: string;
|
|
24
|
-
remark: string | null;
|
|
25
|
-
is_frozen: boolean;
|
|
26
|
-
latest_login_time?: string;
|
|
27
|
-
}
|
|
28
|
-
export interface Role {
|
|
29
|
-
role_id: string;
|
|
30
|
-
role_name: string;
|
|
31
|
-
description?: string;
|
|
32
|
-
}
|
|
33
|
-
export interface Privilege {
|
|
34
|
-
privilege_id: string;
|
|
35
|
-
privilege_name: string;
|
|
36
|
-
description?: string;
|
|
37
|
-
}
|
|
38
|
-
export interface UserGroup {
|
|
39
|
-
group_id: string;
|
|
40
|
-
group_name: string;
|
|
41
|
-
description?: string;
|
|
42
|
-
}
|
|
43
|
-
export interface UserLoginMethod {
|
|
44
|
-
method: string;
|
|
45
|
-
enabled: boolean;
|
|
46
|
-
}
|
|
47
|
-
export interface CreateUserResponse {
|
|
48
|
-
app: AppInfo;
|
|
49
|
-
user: User;
|
|
50
|
-
user_roles: Role[];
|
|
51
|
-
user_privileges: Privilege[];
|
|
52
|
-
user_groups: UserGroup[];
|
|
53
|
-
user_login_methods: UserLoginMethod[];
|
|
54
|
-
}
|
|
55
|
-
export interface CreateUserJson {
|
|
56
|
-
data: CreateUserResponse;
|
|
57
|
-
code: number;
|
|
58
|
-
msg: string;
|
|
59
|
-
}
|
|
60
|
-
export interface CreateUserOptions {
|
|
61
|
-
baseUrl?: string;
|
|
62
|
-
appKey?: string;
|
|
63
|
-
appSecret?: string;
|
|
64
|
-
appToken?: string;
|
|
65
|
-
}
|
|
66
|
-
export interface GetUserRequest {
|
|
67
|
-
user_id?: string;
|
|
68
|
-
include_rbac?: boolean;
|
|
69
|
-
include_login_methods?: boolean;
|
|
70
|
-
include_user_groups?: boolean;
|
|
71
|
-
include_acl?: boolean;
|
|
72
|
-
}
|
|
73
|
-
export interface DeleteUserResponse {
|
|
74
|
-
deleted: boolean;
|
|
75
|
-
user_id: string;
|
|
76
|
-
}
|
|
77
|
-
export interface DeleteUserJson {
|
|
78
|
-
data: DeleteUserResponse;
|
|
79
|
-
code: number;
|
|
80
|
-
msg: string;
|
|
81
|
-
}
|
|
82
|
-
export interface CommonOptions {
|
|
83
|
-
baseUrl?: string;
|
|
84
|
-
appKey?: string;
|
|
85
|
-
appSecret?: string;
|
|
86
|
-
appToken?: string;
|
|
87
|
-
}
|
|
88
|
-
export interface ListUsersRequest {
|
|
89
|
-
page?: number;
|
|
90
|
-
size?: number;
|
|
91
|
-
sort_by?: string;
|
|
92
|
-
sort_direction?: 'asc' | 'desc';
|
|
93
|
-
user_groups?: string[];
|
|
94
|
-
user_roles?: string[];
|
|
95
|
-
user_ids?: string[];
|
|
96
|
-
keyword?: string;
|
|
97
|
-
include_attributes?: boolean;
|
|
98
|
-
}
|
|
99
|
-
export interface UserAttribute {
|
|
100
|
-
attribute_id: string;
|
|
101
|
-
attribute_name: string;
|
|
102
|
-
attribute_value: string;
|
|
103
|
-
}
|
|
104
|
-
export interface UserListItem {
|
|
105
|
-
app: AppInfo;
|
|
106
|
-
user: User;
|
|
107
|
-
user_roles: Role[];
|
|
108
|
-
user_privileges: Privilege[];
|
|
109
|
-
user_groups: UserGroup[];
|
|
110
|
-
user_attributes?: UserAttribute[];
|
|
111
|
-
}
|
|
112
|
-
export interface Sort {
|
|
113
|
-
empty: boolean;
|
|
114
|
-
sorted: boolean;
|
|
115
|
-
unsorted: boolean;
|
|
116
|
-
}
|
|
117
|
-
export interface Pageable {
|
|
118
|
-
sort: Sort;
|
|
119
|
-
offset: number;
|
|
120
|
-
pageNumber: number;
|
|
121
|
-
pageSize: number;
|
|
122
|
-
paged: boolean;
|
|
123
|
-
unpaged: boolean;
|
|
124
|
-
}
|
|
125
|
-
export interface ListUsersResponse {
|
|
126
|
-
content: UserListItem[];
|
|
127
|
-
pageable: Pageable;
|
|
128
|
-
last: boolean;
|
|
129
|
-
totalPages: number;
|
|
130
|
-
totalElements: number;
|
|
131
|
-
size: number;
|
|
132
|
-
number: number;
|
|
133
|
-
sort: Sort;
|
|
134
|
-
first: boolean;
|
|
135
|
-
numberOfElements: number;
|
|
136
|
-
empty: boolean;
|
|
137
|
-
}
|
|
138
|
-
export interface ListUsersJson {
|
|
139
|
-
data: ListUsersResponse;
|
|
140
|
-
code: number;
|
|
141
|
-
msg: string;
|
|
142
|
-
}
|
|
1
|
+
import type { CreateUserRequest, AppInfo, User, Role, Privilege, UserGroup, UserLoginMethod, CreateUserResponse, CreateUserJson, CreateUserOptions, GetUserRequest, DeleteUserResponse, DeleteUserJson, CommonOptions, ListUsersRequest, UserAttribute, UserListItem, Sort, Pageable, ListUsersResponse, ListUsersJson } from "./types.js";
|
|
2
|
+
export type { CreateUserRequest, AppInfo, User, Role, Privilege, UserGroup, UserLoginMethod, CreateUserResponse, CreateUserJson, CreateUserOptions, GetUserRequest, DeleteUserResponse, DeleteUserJson, CommonOptions, ListUsersRequest, UserAttribute, UserListItem, Sort, Pageable, ListUsersResponse, ListUsersJson, };
|
|
143
3
|
/**
|
|
144
4
|
* Creates a new user in the Tale application.
|
|
145
5
|
*
|
package/dist/user/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getAppToken } from
|
|
2
|
-
import { ApiError, ConfigurationError, NetworkError } from
|
|
1
|
+
import { getAppToken } from "../token.js";
|
|
2
|
+
import { ApiError, ConfigurationError, NetworkError } from "../errors.js";
|
|
3
3
|
/**
|
|
4
4
|
* Creates a new user in the Tale application.
|
|
5
5
|
*
|
|
@@ -28,31 +28,31 @@ import { ApiError, ConfigurationError, NetworkError } from '../errors.js';
|
|
|
28
28
|
*/
|
|
29
29
|
export async function createUser(userData, options) {
|
|
30
30
|
// Validate required fields
|
|
31
|
-
if (!userData.username || userData.username.trim() ===
|
|
32
|
-
throw new ApiError(
|
|
31
|
+
if (!userData.username || userData.username.trim() === "") {
|
|
32
|
+
throw new ApiError("username is required", 400, "9400");
|
|
33
33
|
}
|
|
34
34
|
// Use provided app token or get one from token service
|
|
35
|
-
const token = options?.appToken ?? await getAppToken(options);
|
|
35
|
+
const token = options?.appToken ?? (await getAppToken(options));
|
|
36
36
|
// Determine base URL
|
|
37
37
|
const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
|
|
38
38
|
const base = options?.baseUrl ?? env?.TALE_BASE_URL ?? undefined;
|
|
39
39
|
if (!base) {
|
|
40
|
-
throw new ConfigurationError(
|
|
40
|
+
throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
|
|
41
41
|
}
|
|
42
|
-
const url = String(base).replace(/\/+$/,
|
|
42
|
+
const url = String(base).replace(/\/+$/, "") + "/account/v1/user";
|
|
43
43
|
let response;
|
|
44
44
|
try {
|
|
45
45
|
response = await globalThis.fetch(url, {
|
|
46
|
-
method:
|
|
46
|
+
method: "POST",
|
|
47
47
|
headers: {
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
"Content-Type": "application/json",
|
|
49
|
+
"x-t-token": token,
|
|
50
50
|
},
|
|
51
51
|
body: JSON.stringify(userData),
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
catch (error) {
|
|
55
|
-
throw new NetworkError(`Failed to create user: ${error instanceof Error ? error.message :
|
|
55
|
+
throw new NetworkError(`Failed to create user: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
56
56
|
}
|
|
57
57
|
let json;
|
|
58
58
|
try {
|
|
@@ -60,16 +60,16 @@ export async function createUser(userData, options) {
|
|
|
60
60
|
json = responseJson;
|
|
61
61
|
}
|
|
62
62
|
catch (error) {
|
|
63
|
-
throw new ApiError(`Failed to parse user creation response: ${error instanceof Error ? error.message :
|
|
63
|
+
throw new ApiError(`Failed to parse user creation response: ${error instanceof Error ? error.message : "Invalid JSON"}`, response.status);
|
|
64
64
|
}
|
|
65
65
|
// Handle API errors
|
|
66
66
|
if (json.code !== 200) {
|
|
67
|
-
const errorMsg = typeof json.msg ===
|
|
67
|
+
const errorMsg = typeof json.msg === "string" ? json.msg : "User creation failed";
|
|
68
68
|
throw new ApiError(errorMsg, response.status, json.code);
|
|
69
69
|
}
|
|
70
70
|
// Validate response structure
|
|
71
71
|
if (!json.data || !json.data.user || !json.data.app) {
|
|
72
|
-
throw new ApiError(
|
|
72
|
+
throw new ApiError("Invalid user creation response: missing required data", response.status);
|
|
73
73
|
}
|
|
74
74
|
return json.data;
|
|
75
75
|
}
|
|
@@ -97,15 +97,15 @@ export async function createUser(userData, options) {
|
|
|
97
97
|
*/
|
|
98
98
|
export async function getUserById(userId, options) {
|
|
99
99
|
// Use provided app token or get one from token service
|
|
100
|
-
const token = options?.appToken ?? await getAppToken(options);
|
|
100
|
+
const token = options?.appToken ?? (await getAppToken(options));
|
|
101
101
|
// Determine base URL
|
|
102
102
|
const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
|
|
103
103
|
const base = options?.baseUrl ?? env?.TALE_BASE_URL ?? undefined;
|
|
104
104
|
if (!base) {
|
|
105
|
-
throw new ConfigurationError(
|
|
105
|
+
throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
|
|
106
106
|
}
|
|
107
107
|
// Build URL with query parameters
|
|
108
|
-
const url = new URL(String(base).replace(/\/+$/,
|
|
108
|
+
const url = new URL(String(base).replace(/\/+$/, "") + "/account/v1/user");
|
|
109
109
|
// Add query parameters
|
|
110
110
|
const queryParams = {
|
|
111
111
|
user_id: userId,
|
|
@@ -113,7 +113,7 @@ export async function getUserById(userId, options) {
|
|
|
113
113
|
include_login_methods: true,
|
|
114
114
|
include_user_groups: true,
|
|
115
115
|
include_acl: false,
|
|
116
|
-
...options
|
|
116
|
+
...options,
|
|
117
117
|
};
|
|
118
118
|
Object.entries(queryParams).forEach(([key, value]) => {
|
|
119
119
|
if (value !== undefined) {
|
|
@@ -123,15 +123,15 @@ export async function getUserById(userId, options) {
|
|
|
123
123
|
let response;
|
|
124
124
|
try {
|
|
125
125
|
response = await globalThis.fetch(url.toString(), {
|
|
126
|
-
method:
|
|
126
|
+
method: "GET",
|
|
127
127
|
headers: {
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
"Content-Type": "application/json",
|
|
129
|
+
"x-t-token": token,
|
|
130
130
|
},
|
|
131
131
|
});
|
|
132
132
|
}
|
|
133
133
|
catch (error) {
|
|
134
|
-
throw new NetworkError(`Failed to get user: ${error instanceof Error ? error.message :
|
|
134
|
+
throw new NetworkError(`Failed to get user: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
135
135
|
}
|
|
136
136
|
let json;
|
|
137
137
|
try {
|
|
@@ -139,16 +139,16 @@ export async function getUserById(userId, options) {
|
|
|
139
139
|
json = responseJson;
|
|
140
140
|
}
|
|
141
141
|
catch (error) {
|
|
142
|
-
throw new ApiError(`Failed to parse user response: ${error instanceof Error ? error.message :
|
|
142
|
+
throw new ApiError(`Failed to parse user response: ${error instanceof Error ? error.message : "Invalid JSON"}`, response.status);
|
|
143
143
|
}
|
|
144
144
|
// Handle API errors
|
|
145
145
|
if (json.code !== 200) {
|
|
146
|
-
const errorMsg = typeof json.msg ===
|
|
146
|
+
const errorMsg = typeof json.msg === "string" ? json.msg : "User retrieval failed";
|
|
147
147
|
throw new ApiError(errorMsg, response.status, json.code);
|
|
148
148
|
}
|
|
149
149
|
// Validate response structure
|
|
150
150
|
if (!json.data || !json.data.user || !json.data.app) {
|
|
151
|
-
throw new ApiError(
|
|
151
|
+
throw new ApiError("Invalid user response: missing required data", response.status);
|
|
152
152
|
}
|
|
153
153
|
return json.data;
|
|
154
154
|
}
|
|
@@ -176,30 +176,31 @@ export async function getUserById(userId, options) {
|
|
|
176
176
|
*/
|
|
177
177
|
export async function deleteUser(userId, options) {
|
|
178
178
|
// Validate required fields
|
|
179
|
-
if (!userId || userId.trim() ===
|
|
180
|
-
throw new ApiError(
|
|
179
|
+
if (!userId || userId.trim() === "") {
|
|
180
|
+
throw new ApiError("user_id is required for deletion", 400, "9400");
|
|
181
181
|
}
|
|
182
182
|
// Use provided app token or get one from token service
|
|
183
|
-
const token = options?.appToken ?? await getAppToken(options);
|
|
183
|
+
const token = options?.appToken ?? (await getAppToken(options));
|
|
184
184
|
// Determine base URL
|
|
185
185
|
const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
|
|
186
186
|
const base = options?.baseUrl ?? env?.TALE_BASE_URL ?? undefined;
|
|
187
187
|
if (!base) {
|
|
188
|
-
throw new ConfigurationError(
|
|
188
|
+
throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
|
|
189
189
|
}
|
|
190
|
-
const url = String(base).replace(/\/+$/,
|
|
190
|
+
const url = String(base).replace(/\/+$/, "") +
|
|
191
|
+
`/account/v1/users/${encodeURIComponent(userId)}`;
|
|
191
192
|
let response;
|
|
192
193
|
try {
|
|
193
194
|
response = await globalThis.fetch(url, {
|
|
194
|
-
method:
|
|
195
|
+
method: "DELETE",
|
|
195
196
|
headers: {
|
|
196
|
-
|
|
197
|
-
|
|
197
|
+
"Content-Type": "application/json",
|
|
198
|
+
"x-t-token": token,
|
|
198
199
|
},
|
|
199
200
|
});
|
|
200
201
|
}
|
|
201
202
|
catch (error) {
|
|
202
|
-
throw new NetworkError(`Failed to delete user: ${error instanceof Error ? error.message :
|
|
203
|
+
throw new NetworkError(`Failed to delete user: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
203
204
|
}
|
|
204
205
|
let json;
|
|
205
206
|
try {
|
|
@@ -207,16 +208,16 @@ export async function deleteUser(userId, options) {
|
|
|
207
208
|
json = responseJson;
|
|
208
209
|
}
|
|
209
210
|
catch (error) {
|
|
210
|
-
throw new ApiError(`Failed to parse user deletion response: ${error instanceof Error ? error.message :
|
|
211
|
+
throw new ApiError(`Failed to parse user deletion response: ${error instanceof Error ? error.message : "Invalid JSON"}`, response.status);
|
|
211
212
|
}
|
|
212
213
|
// Handle API errors
|
|
213
214
|
if (json.code !== 200) {
|
|
214
|
-
const errorMsg = typeof json.msg ===
|
|
215
|
+
const errorMsg = typeof json.msg === "string" ? json.msg : "User deletion failed";
|
|
215
216
|
throw new ApiError(errorMsg, response.status, json.code);
|
|
216
217
|
}
|
|
217
218
|
// Validate response structure
|
|
218
219
|
if (!json.data || json.data.deleted !== true) {
|
|
219
|
-
throw new ApiError(
|
|
220
|
+
throw new ApiError("Invalid user deletion response: deletion not confirmed", response.status);
|
|
220
221
|
}
|
|
221
222
|
return json.data;
|
|
222
223
|
}
|
|
@@ -250,65 +251,65 @@ export async function deleteUser(userId, options) {
|
|
|
250
251
|
*/
|
|
251
252
|
export async function listUsers(options) {
|
|
252
253
|
// Use provided app token or get one from token service
|
|
253
|
-
const token = options?.appToken ?? await getAppToken(options);
|
|
254
|
+
const token = options?.appToken ?? (await getAppToken(options));
|
|
254
255
|
// Determine base URL
|
|
255
256
|
const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
|
|
256
257
|
const base = options?.baseUrl ?? env?.TALE_BASE_URL ?? undefined;
|
|
257
258
|
if (!base) {
|
|
258
|
-
throw new ConfigurationError(
|
|
259
|
+
throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
|
|
259
260
|
}
|
|
260
261
|
// Build URL with query parameters
|
|
261
|
-
const url = new URL(String(base).replace(/\/+$/,
|
|
262
|
+
const url = new URL(String(base).replace(/\/+$/, "") + "/account/v1/users");
|
|
262
263
|
// Add query parameters with defaults
|
|
263
264
|
const queryParams = {
|
|
264
265
|
page: 0,
|
|
265
266
|
size: 20,
|
|
266
|
-
sort_by:
|
|
267
|
-
sort_direction:
|
|
267
|
+
sort_by: "createdAt",
|
|
268
|
+
sort_direction: "desc",
|
|
268
269
|
include_attributes: false,
|
|
269
|
-
...options
|
|
270
|
+
...options,
|
|
270
271
|
};
|
|
271
272
|
// Handle array parameters (need to be comma-separated)
|
|
272
273
|
if (queryParams.user_groups && queryParams.user_groups.length > 0) {
|
|
273
|
-
url.searchParams.append(
|
|
274
|
+
url.searchParams.append("user_groups", queryParams.user_groups.join(","));
|
|
274
275
|
}
|
|
275
276
|
if (queryParams.user_roles && queryParams.user_roles.length > 0) {
|
|
276
|
-
url.searchParams.append(
|
|
277
|
+
url.searchParams.append("user_roles", queryParams.user_roles.join(","));
|
|
277
278
|
}
|
|
278
279
|
if (queryParams.user_ids && queryParams.user_ids.length > 0) {
|
|
279
|
-
url.searchParams.append(
|
|
280
|
+
url.searchParams.append("user_ids", queryParams.user_ids.join(","));
|
|
280
281
|
}
|
|
281
282
|
// Add other parameters
|
|
282
283
|
if (queryParams.page !== undefined) {
|
|
283
|
-
url.searchParams.append(
|
|
284
|
+
url.searchParams.append("page", String(queryParams.page));
|
|
284
285
|
}
|
|
285
286
|
if (queryParams.size !== undefined) {
|
|
286
|
-
url.searchParams.append(
|
|
287
|
+
url.searchParams.append("size", String(queryParams.size));
|
|
287
288
|
}
|
|
288
289
|
if (queryParams.sort_by) {
|
|
289
|
-
url.searchParams.append(
|
|
290
|
+
url.searchParams.append("sort_by", queryParams.sort_by);
|
|
290
291
|
}
|
|
291
292
|
if (queryParams.sort_direction) {
|
|
292
|
-
url.searchParams.append(
|
|
293
|
+
url.searchParams.append("sort_direction", queryParams.sort_direction);
|
|
293
294
|
}
|
|
294
295
|
if (queryParams.keyword) {
|
|
295
|
-
url.searchParams.append(
|
|
296
|
+
url.searchParams.append("keyword", queryParams.keyword);
|
|
296
297
|
}
|
|
297
298
|
if (queryParams.include_attributes !== undefined) {
|
|
298
|
-
url.searchParams.append(
|
|
299
|
+
url.searchParams.append("include_attributes", String(queryParams.include_attributes));
|
|
299
300
|
}
|
|
300
301
|
let response;
|
|
301
302
|
try {
|
|
302
303
|
response = await globalThis.fetch(url.toString(), {
|
|
303
|
-
method:
|
|
304
|
+
method: "GET",
|
|
304
305
|
headers: {
|
|
305
|
-
|
|
306
|
-
|
|
306
|
+
"Content-Type": "application/json",
|
|
307
|
+
"x-t-token": token,
|
|
307
308
|
},
|
|
308
309
|
});
|
|
309
310
|
}
|
|
310
311
|
catch (error) {
|
|
311
|
-
throw new NetworkError(`Failed to list users: ${error instanceof Error ? error.message :
|
|
312
|
+
throw new NetworkError(`Failed to list users: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
312
313
|
}
|
|
313
314
|
let json;
|
|
314
315
|
try {
|
|
@@ -316,16 +317,16 @@ export async function listUsers(options) {
|
|
|
316
317
|
json = responseJson;
|
|
317
318
|
}
|
|
318
319
|
catch (error) {
|
|
319
|
-
throw new ApiError(`Failed to parse users list response: ${error instanceof Error ? error.message :
|
|
320
|
+
throw new ApiError(`Failed to parse users list response: ${error instanceof Error ? error.message : "Invalid JSON"}`, response.status);
|
|
320
321
|
}
|
|
321
322
|
// Handle API errors
|
|
322
323
|
if (json.code !== 200) {
|
|
323
|
-
const errorMsg = typeof json.msg ===
|
|
324
|
+
const errorMsg = typeof json.msg === "string" ? json.msg : "Users list retrieval failed";
|
|
324
325
|
throw new ApiError(errorMsg, response.status, json.code);
|
|
325
326
|
}
|
|
326
327
|
// Validate response structure
|
|
327
328
|
if (!json.data || !Array.isArray(json.data.content)) {
|
|
328
|
-
throw new ApiError(
|
|
329
|
+
throw new ApiError("Invalid users list response: missing required data", response.status);
|
|
329
330
|
}
|
|
330
331
|
return json.data;
|
|
331
332
|
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { AppInfo, BaseUser, UserGroup, Role, Privilege, Sort, Pageable, CommonOptions } from "../common/types.js";
|
|
2
|
+
export type { AppInfo, UserGroup, Role, Privilege, Sort, Pageable, CommonOptions, };
|
|
3
|
+
/**
|
|
4
|
+
* User information (uses BaseUser from common types)
|
|
5
|
+
*/
|
|
6
|
+
export type User = BaseUser;
|
|
7
|
+
export interface CreateUserRequest {
|
|
8
|
+
username: string;
|
|
9
|
+
password_encrypted?: string;
|
|
10
|
+
nickname?: string;
|
|
11
|
+
phone?: string;
|
|
12
|
+
email?: string;
|
|
13
|
+
avatar_url?: string;
|
|
14
|
+
role_ids?: string[];
|
|
15
|
+
}
|
|
16
|
+
export interface UserLoginMethod {
|
|
17
|
+
method: string;
|
|
18
|
+
enabled: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface CreateUserResponse {
|
|
21
|
+
app: AppInfo;
|
|
22
|
+
user: User;
|
|
23
|
+
user_roles: Role[];
|
|
24
|
+
user_privileges: Privilege[];
|
|
25
|
+
user_groups: UserGroup[];
|
|
26
|
+
user_login_methods: UserLoginMethod[];
|
|
27
|
+
}
|
|
28
|
+
export interface CreateUserJson {
|
|
29
|
+
data: CreateUserResponse;
|
|
30
|
+
code: number;
|
|
31
|
+
msg: string;
|
|
32
|
+
}
|
|
33
|
+
export interface CreateUserOptions {
|
|
34
|
+
baseUrl?: string;
|
|
35
|
+
appKey?: string;
|
|
36
|
+
appSecret?: string;
|
|
37
|
+
appToken?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface GetUserRequest {
|
|
40
|
+
user_id?: string;
|
|
41
|
+
include_rbac?: boolean;
|
|
42
|
+
include_login_methods?: boolean;
|
|
43
|
+
include_user_groups?: boolean;
|
|
44
|
+
include_acl?: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface DeleteUserResponse {
|
|
47
|
+
deleted: boolean;
|
|
48
|
+
user_id: string;
|
|
49
|
+
}
|
|
50
|
+
export interface DeleteUserJson {
|
|
51
|
+
data: DeleteUserResponse;
|
|
52
|
+
code: number;
|
|
53
|
+
msg: string;
|
|
54
|
+
}
|
|
55
|
+
export interface ListUsersRequest {
|
|
56
|
+
page?: number;
|
|
57
|
+
size?: number;
|
|
58
|
+
sort_by?: string;
|
|
59
|
+
sort_direction?: "asc" | "desc";
|
|
60
|
+
user_groups?: string[];
|
|
61
|
+
user_roles?: string[];
|
|
62
|
+
user_ids?: string[];
|
|
63
|
+
keyword?: string;
|
|
64
|
+
include_attributes?: boolean;
|
|
65
|
+
}
|
|
66
|
+
export interface UserAttribute {
|
|
67
|
+
attribute_id: string;
|
|
68
|
+
attribute_name: string;
|
|
69
|
+
attribute_value: string;
|
|
70
|
+
}
|
|
71
|
+
export interface UserListItem {
|
|
72
|
+
app: AppInfo;
|
|
73
|
+
user: User;
|
|
74
|
+
user_roles: Role[];
|
|
75
|
+
user_privileges: Privilege[];
|
|
76
|
+
user_groups: UserGroup[];
|
|
77
|
+
user_attributes?: UserAttribute[];
|
|
78
|
+
}
|
|
79
|
+
export interface ListUsersResponse {
|
|
80
|
+
content: UserListItem[];
|
|
81
|
+
pageable: Pageable;
|
|
82
|
+
last: boolean;
|
|
83
|
+
totalPages: number;
|
|
84
|
+
totalElements: number;
|
|
85
|
+
size: number;
|
|
86
|
+
number: number;
|
|
87
|
+
sort: Sort;
|
|
88
|
+
first: boolean;
|
|
89
|
+
numberOfElements: number;
|
|
90
|
+
empty: boolean;
|
|
91
|
+
}
|
|
92
|
+
export interface ListUsersJson {
|
|
93
|
+
data: ListUsersResponse;
|
|
94
|
+
code: number;
|
|
95
|
+
msg: string;
|
|
96
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|