tale-js-sdk 1.0.0 → 1.1.0

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.js CHANGED
@@ -1,5 +1,23 @@
1
1
  import { getAppToken } from "../token.js";
2
2
  import { ApiError, ConfigurationError, NetworkError } from "../errors.js";
3
+ // ==================== Helper Functions ====================
4
+ /**
5
+ * Parses standard API response format: { code, msg, data }
6
+ */
7
+ function parseApiResponse(json, errorMessage, statusCode) {
8
+ if (typeof json !== 'object' || json === null) {
9
+ throw new ApiError(`Invalid response: ${errorMessage} - not an object`, statusCode);
10
+ }
11
+ const response = json;
12
+ if (response.code !== 200) {
13
+ const errorMsg = typeof response.msg === "string" ? response.msg : errorMessage;
14
+ throw new ApiError(errorMsg, statusCode, response.code);
15
+ }
16
+ if (!response.data) {
17
+ throw new ApiError(`Invalid response: ${errorMessage} - missing data`, statusCode);
18
+ }
19
+ return response.data;
20
+ }
3
21
  // ==================== ACL Record Management (v2) ====================
4
22
  /**
5
23
  * Gets an ACL record by ID.
@@ -48,15 +66,8 @@ export async function getAclRecord(recordId, options) {
48
66
  catch (error) {
49
67
  throw new NetworkError(`Failed to get ACL record: ${error instanceof Error ? error.message : "Unknown error"}`);
50
68
  }
51
- const json = (await response.json());
52
- if (json.code !== 200) {
53
- const errorMsg = typeof json.msg === "string" ? json.msg : "Failed to get ACL record";
54
- throw new ApiError(errorMsg, response.status, json.code);
55
- }
56
- if (!json.data) {
57
- throw new ApiError("Invalid ACL record response: missing data", response.status);
58
- }
59
- return json.data;
69
+ const json = await response.json();
70
+ return parseApiResponse(json, "Failed to get ACL record", response.status);
60
71
  }
61
72
  /**
62
73
  * Lists ACL records with pagination and optional filtering.
@@ -91,10 +102,12 @@ export async function listAclRecords(options) {
91
102
  throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
92
103
  }
93
104
  const url = new URL(String(base).replace(/\/+$/, "") + "/acl/v2/records");
105
+ // 分离 AclOptions 字段,只保留请求参数
106
+ const { appToken, baseUrl, ...requestParams } = options || {};
94
107
  const queryParams = {
95
108
  page: 0,
96
109
  size: 20,
97
- ...options,
110
+ ...requestParams,
98
111
  };
99
112
  Object.entries(queryParams).forEach(([key, value]) => {
100
113
  if (value !== undefined) {
@@ -114,15 +127,12 @@ export async function listAclRecords(options) {
114
127
  catch (error) {
115
128
  throw new NetworkError(`Failed to list ACL records: ${error instanceof Error ? error.message : "Unknown error"}`);
116
129
  }
117
- const json = (await response.json());
118
- if (json.code !== 200) {
119
- const errorMsg = typeof json.msg === "string" ? json.msg : "Failed to list ACL records";
120
- throw new ApiError(errorMsg, response.status, json.code);
130
+ const json = await response.json();
131
+ const data = parseApiResponse(json, "Failed to list ACL records", response.status);
132
+ if (!Array.isArray(data.content)) {
133
+ throw new ApiError("Invalid ACL records response: content is not an array", response.status);
121
134
  }
122
- if (!json.data || !Array.isArray(json.data.content)) {
123
- throw new ApiError("Invalid ACL records response: missing data", response.status);
124
- }
125
- return json.data;
135
+ return data;
126
136
  }
127
137
  /**
128
138
  * Creates a new ACL record.
@@ -183,15 +193,8 @@ export async function createAclRecord(request, options) {
183
193
  catch (error) {
184
194
  throw new NetworkError(`Failed to create ACL record: ${error instanceof Error ? error.message : "Unknown error"}`);
185
195
  }
186
- const json = (await response.json());
187
- if (json.code !== 200) {
188
- const errorMsg = typeof json.msg === "string" ? json.msg : "Failed to create ACL record";
189
- throw new ApiError(errorMsg, response.status, json.code);
190
- }
191
- if (!json.data) {
192
- throw new ApiError("Invalid ACL record creation response: missing data", response.status);
193
- }
194
- return json.data;
196
+ const json = await response.json();
197
+ return parseApiResponse(json, "Failed to create ACL record", response.status);
195
198
  }
196
199
  /**
197
200
  * Batch creates ACL records.
@@ -253,17 +256,8 @@ export async function batchCreateAclRecords(requests, options) {
253
256
  catch (error) {
254
257
  throw new NetworkError(`Failed to batch create ACL records: ${error instanceof Error ? error.message : "Unknown error"}`);
255
258
  }
256
- const json = (await response.json());
257
- if (json.code !== 200) {
258
- const errorMsg = typeof json.msg === "string"
259
- ? json.msg
260
- : "Failed to batch create ACL records";
261
- throw new ApiError(errorMsg, response.status, json.code);
262
- }
263
- if (!json.data) {
264
- throw new ApiError("Invalid ACL batch creation response: missing data", response.status);
265
- }
266
- return json.data;
259
+ const json = await response.json();
260
+ return parseApiResponse(json, "Failed to batch create ACL records", response.status);
267
261
  }
268
262
  /**
269
263
  * Updates an existing ACL record.
@@ -317,15 +311,8 @@ export async function updateAclRecord(recordId, request, options) {
317
311
  catch (error) {
318
312
  throw new NetworkError(`Failed to update ACL record: ${error instanceof Error ? error.message : "Unknown error"}`);
319
313
  }
320
- const json = (await response.json());
321
- if (json.code !== 200) {
322
- const errorMsg = typeof json.msg === "string" ? json.msg : "Failed to update ACL record";
323
- throw new ApiError(errorMsg, response.status, json.code);
324
- }
325
- if (!json.data) {
326
- throw new ApiError("Invalid ACL record update response: missing data", response.status);
327
- }
328
- return json.data;
314
+ const json = await response.json();
315
+ return parseApiResponse(json, "Failed to update ACL record", response.status);
329
316
  }
330
317
  /**
331
318
  * Deletes an ACL record.
@@ -374,10 +361,15 @@ export async function deleteAclRecord(recordId, options) {
374
361
  catch (error) {
375
362
  throw new NetworkError(`Failed to delete ACL record: ${error instanceof Error ? error.message : "Unknown error"}`);
376
363
  }
377
- const json = (await response.json());
378
- if (json.code !== 200) {
379
- const errorMsg = typeof json.msg === "string" ? json.msg : "Failed to delete ACL record";
380
- throw new ApiError(errorMsg, response.status, json.code);
364
+ const json = await response.json();
365
+ // Delete response may not have data field, handle differently
366
+ if (typeof json !== 'object' || json === null) {
367
+ throw new ApiError("Invalid ACL record deletion response", response.status);
368
+ }
369
+ const apiResponse = json;
370
+ if (apiResponse.code !== 200) {
371
+ const errorMsg = typeof apiResponse.msg === "string" ? apiResponse.msg : "Failed to delete ACL record";
372
+ throw new ApiError(errorMsg, response.status, apiResponse.code);
381
373
  }
382
374
  }
383
375
  // ==================== ACL Template Management ====================
@@ -471,12 +463,14 @@ export async function listAclTemplates(options) {
471
463
  throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
472
464
  }
473
465
  const url = new URL(String(base).replace(/\/+$/, "") + "/acl/v1/templates");
466
+ // 分离 AclOptions 字段,只保留请求参数
467
+ const { appToken, baseUrl, ...requestParams } = options || {};
474
468
  const queryParams = {
475
469
  page: 0,
476
470
  size: 20,
477
471
  sort_by: "createdAt",
478
472
  sort_direction: "desc",
479
- ...options,
473
+ ...requestParams,
480
474
  };
481
475
  Object.entries(queryParams).forEach(([key, value]) => {
482
476
  if (value !== undefined) {
@@ -52,6 +52,7 @@ export interface UpdateAclRecordRequest {
52
52
  export interface ListAclRecordsRequest {
53
53
  page?: number;
54
54
  size?: number;
55
+ sort?: string;
55
56
  template_id?: string;
56
57
  subject_type?: string;
57
58
  subject_id?: string;
package/dist/index.d.ts CHANGED
@@ -5,5 +5,6 @@ export * from "./auth/index.js";
5
5
  export * from "./user-group/index.js";
6
6
  export * from "./rbac/index.js";
7
7
  export * from "./acl/index.js";
8
+ export * from "./user-attribute/index.js";
8
9
  export * from "./errors.js";
9
10
  export type { CommonOptions, PageResponse, UserGroup, Role, Privilege, AppInfo, User } from "./common/types.js";
package/dist/index.js CHANGED
@@ -5,4 +5,5 @@ export * from "./auth/index.js";
5
5
  export * from "./user-group/index.js";
6
6
  export * from "./rbac/index.js";
7
7
  export * from "./acl/index.js";
8
+ export * from "./user-attribute/index.js";
8
9
  export * from "./errors.js";
@@ -1,5 +1,5 @@
1
- import type { CreateUserRequest, AppInfo, User, Role, Privilege, UserGroup, UserLoginMethod, CreateUserResponse, CreateUserJson, CreateUserOptions, GetUserRequest, DeleteUserResponse, DeleteUserJson, CommonOptions, ListUsersRequest, UserAttribute, UserListItem, ListUsersResponse, ListUsersJson, UpdateUserRequest, UpdateUserResponse, UpdateUserJson, UpdateUserPasswordRequest, UpdateUserPasswordResponse, UpdateUserPasswordJson, UploadAvatarResponse, UploadAvatarJson, AvatarPresignedUrlResponse, AvatarPresignedUrlJson, UpdateUserFrozenStatusRequest, UserFrozenStatusResponse, UpdateUserFrozenStatusJson, GetUserFrozenStatusJson } from "./types.js";
2
- export type { CreateUserRequest, AppInfo, User, Role, Privilege, UserGroup, UserLoginMethod, CreateUserResponse, CreateUserJson, CreateUserOptions, GetUserRequest, DeleteUserResponse, DeleteUserJson, CommonOptions, ListUsersRequest, UserAttribute, UserListItem, ListUsersResponse, ListUsersJson, UpdateUserRequest, UpdateUserResponse, UpdateUserJson, UpdateUserPasswordRequest, UpdateUserPasswordResponse, UpdateUserPasswordJson, UploadAvatarResponse, UploadAvatarJson, AvatarPresignedUrlResponse, AvatarPresignedUrlJson, UpdateUserFrozenStatusRequest, UserFrozenStatusResponse, UpdateUserFrozenStatusJson, GetUserFrozenStatusJson, };
1
+ import type { CreateUserRequest, AppInfo, User, Role, Privilege, UserGroup, UserLoginMethod, CreateUserResponse, CreateUserJson, CreateUserOptions, GetUserRequest, DeleteUserResponse, DeleteUserJson, CommonOptions, ListUsersRequest, UserAttributeItemDTO, UserListItem, ListUsersResponse, ListUsersJson, UpdateUserRequest, UpdateUserResponse, UpdateUserJson, UpdateUserPasswordRequest, UpdateUserPasswordResponse, UpdateUserPasswordJson, UploadAvatarResponse, UploadAvatarJson, AvatarPresignedUrlResponse, AvatarPresignedUrlJson, UpdateUserFrozenStatusRequest, UserFrozenStatusResponse, UpdateUserFrozenStatusJson, GetUserFrozenStatusJson } from "./types.js";
2
+ export type { CreateUserRequest, AppInfo, User, Role, Privilege, UserGroup, UserLoginMethod, CreateUserResponse, CreateUserJson, CreateUserOptions, GetUserRequest, DeleteUserResponse, DeleteUserJson, CommonOptions, ListUsersRequest, UserAttributeItemDTO, UserListItem, ListUsersResponse, ListUsersJson, UpdateUserRequest, UpdateUserResponse, UpdateUserJson, UpdateUserPasswordRequest, UpdateUserPasswordResponse, UpdateUserPasswordJson, UploadAvatarResponse, UploadAvatarJson, AvatarPresignedUrlResponse, AvatarPresignedUrlJson, UpdateUserFrozenStatusRequest, UserFrozenStatusResponse, UpdateUserFrozenStatusJson, GetUserFrozenStatusJson, };
3
3
  /**
4
4
  * Creates a new user in the Tale application.
5
5
  *
@@ -1,5 +1,6 @@
1
1
  import type { AppInfo, User, UserGroup, Role, Privilege, CommonOptions, PageResponse } from "../common/types.js";
2
- export type { AppInfo, User, UserGroup, Role, Privilege, CommonOptions, PageResponse, };
2
+ import type { UserAttributeItemDTO } from "../user-attribute/types.js";
3
+ export type { AppInfo, User, UserGroup, Role, Privilege, CommonOptions, PageResponse, UserAttributeItemDTO, };
3
4
  export interface CreateUserRequest {
4
5
  username: string;
5
6
  password_encrypted?: string;
@@ -59,18 +60,13 @@ export interface ListUsersRequest {
59
60
  keyword?: string;
60
61
  include_attributes?: boolean;
61
62
  }
62
- export interface UserAttribute {
63
- attribute_id: string;
64
- attribute_name: string;
65
- attribute_value: string;
66
- }
67
63
  export interface UserListItem {
68
64
  app: AppInfo;
69
65
  user: User;
70
66
  user_roles: Role[];
71
67
  user_privileges: Privilege[];
72
68
  user_groups: UserGroup[];
73
- user_attributes?: UserAttribute[];
69
+ user_attributes?: UserAttributeItemDTO[];
74
70
  }
75
71
  export interface ListUsersResponse extends PageResponse<UserListItem> {
76
72
  content: UserListItem[];
@@ -0,0 +1,194 @@
1
+ import type { UserAttributeDefinition, UserAttributeDTO, UserAttributeItemDTO, UserAttributeGroupedDTO, CreateUserAttributeDefinitionRequest, UpdateUserAttributeDefinitionRequest, SetUserAttributeRequest, ListUserAttributeDefinitionsRequest, ListUserAttributesRequest, ListAllUserAttributesRequest, UserAttributeOptions } from "./types.js";
2
+ export type { UserAttributeDefinition, UserAttributeDTO, UserAttributeItemDTO, UserAttributeGroupedDTO, CreateUserAttributeDefinitionRequest, UpdateUserAttributeDefinitionRequest, SetUserAttributeRequest, ListUserAttributeDefinitionsRequest, ListUserAttributesRequest, ListAllUserAttributesRequest, UserAttributeOptions, };
3
+ /**
4
+ * Creates a new user attribute definition.
5
+ *
6
+ * @param request - Attribute definition creation request
7
+ * @param options - Optional configuration
8
+ * @returns Promise resolving to created attribute definition
9
+ * @throws {ConfigurationError} When required environment variables are missing
10
+ * @throws {ApiError} When API request fails
11
+ * @throws {NetworkError} When network request fails
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const definition = await createUserAttributeDefinition({
16
+ * attribute_name: "department",
17
+ * description: "User's department",
18
+ * schema_definition: { type: "string" },
19
+ * is_enabled: true,
20
+ * });
21
+ * ```
22
+ */
23
+ export declare function createUserAttributeDefinition(request: CreateUserAttributeDefinitionRequest, options?: UserAttributeOptions): Promise<UserAttributeDefinition>;
24
+ /**
25
+ * Updates an existing user attribute definition.
26
+ *
27
+ * @param openId - Attribute definition open ID
28
+ * @param request - Attribute definition update request
29
+ * @param options - Optional configuration
30
+ * @returns Promise resolving to updated attribute definition
31
+ * @throws {ConfigurationError} When required environment variables are missing
32
+ * @throws {ApiError} When API request fails
33
+ * @throws {NetworkError} When network request fails
34
+ */
35
+ export declare function updateUserAttributeDefinition(openId: string, request: UpdateUserAttributeDefinitionRequest, options?: UserAttributeOptions): Promise<UserAttributeDefinition>;
36
+ /**
37
+ * Deletes a user attribute definition.
38
+ *
39
+ * @param openId - Attribute definition open ID
40
+ * @param options - Optional configuration
41
+ * @throws {ConfigurationError} When required environment variables are missing
42
+ * @throws {ApiError} When API request fails
43
+ * @throws {NetworkError} When network request fails
44
+ */
45
+ export declare function deleteUserAttributeDefinition(openId: string, options?: UserAttributeOptions): Promise<void>;
46
+ /**
47
+ * Gets a user attribute definition by open ID.
48
+ *
49
+ * @param openId - Attribute definition open ID
50
+ * @param options - Optional configuration
51
+ * @returns Promise resolving to attribute definition
52
+ * @throws {ConfigurationError} When required environment variables are missing
53
+ * @throws {ApiError} When API request fails
54
+ * @throws {NetworkError} When network request fails
55
+ */
56
+ export declare function getUserAttributeDefinition(openId: string, options?: UserAttributeOptions): Promise<UserAttributeDefinition>;
57
+ /**
58
+ * Lists user attribute definitions with pagination and optional filtering.
59
+ *
60
+ * @param request - List request parameters
61
+ * @param options - Optional configuration
62
+ * @returns Promise resolving to paginated list of attribute definitions
63
+ * @throws {ConfigurationError} When required environment variables are missing
64
+ * @throws {ApiError} When API request fails
65
+ * @throws {NetworkError} When network request fails
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * const result = await listUserAttributeDefinitions({
70
+ * page: 0,
71
+ * size: 20,
72
+ * keyword: "department",
73
+ * });
74
+ * console.log(result.content); // Array of definitions
75
+ * console.log(result.totalElements); // Total count
76
+ * ```
77
+ */
78
+ export declare function listUserAttributeDefinitions(request?: ListUserAttributeDefinitionsRequest & UserAttributeOptions): Promise<{
79
+ content: UserAttributeDefinition[];
80
+ totalElements: number;
81
+ }>;
82
+ /**
83
+ * Lists all enabled user attribute definitions.
84
+ *
85
+ * @param options - Optional configuration
86
+ * @returns Promise resolving to array of enabled attribute definitions
87
+ * @throws {ConfigurationError} When required environment variables are missing
88
+ * @throws {ApiError} When API request fails
89
+ * @throws {NetworkError} When network request fails
90
+ */
91
+ export declare function listEnabledUserAttributeDefinitions(options?: UserAttributeOptions): Promise<UserAttributeDefinition[]>;
92
+ /**
93
+ * Toggles the enabled status of a user attribute definition.
94
+ *
95
+ * @param openId - Attribute definition open ID
96
+ * @param isEnabled - Whether the definition should be enabled
97
+ * @param options - Optional configuration
98
+ * @returns Promise resolving to updated attribute definition
99
+ * @throws {ConfigurationError} When required environment variables are missing
100
+ * @throws {ApiError} When API request fails
101
+ * @throws {NetworkError} When network request fails
102
+ */
103
+ export declare function toggleUserAttributeDefinitionStatus(openId: string, isEnabled: boolean, options?: UserAttributeOptions): Promise<UserAttributeDefinition>;
104
+ /**
105
+ * Sets a user attribute value.
106
+ *
107
+ * @param userId - User ID
108
+ * @param attributeDefinitionId - Attribute definition ID
109
+ * @param request - Attribute value to set
110
+ * @param options - Optional configuration
111
+ * @returns Promise resolving to updated user attribute
112
+ * @throws {ConfigurationError} When required environment variables are missing
113
+ * @throws {ApiError} When API request fails
114
+ * @throws {NetworkError} When network request fails
115
+ */
116
+ export declare function setUserAttribute(userId: string, attributeDefinitionId: string, request: SetUserAttributeRequest, options?: UserAttributeOptions): Promise<UserAttributeDTO>;
117
+ /**
118
+ * Gets a user attribute value.
119
+ *
120
+ * @param userId - User ID
121
+ * @param attributeDefinitionId - Attribute definition ID
122
+ * @param options - Optional configuration
123
+ * @returns Promise resolving to user attribute
124
+ * @throws {ConfigurationError} When required environment variables are missing
125
+ * @throws {ApiError} When API request fails
126
+ * @throws {NetworkError} When network request fails
127
+ */
128
+ export declare function getUserAttribute(userId: string, attributeDefinitionId: string, options?: UserAttributeOptions): Promise<UserAttributeDTO>;
129
+ /**
130
+ * Deletes a user attribute value.
131
+ *
132
+ * @param userId - User ID
133
+ * @param attributeDefinitionId - Attribute definition ID
134
+ * @param options - Optional configuration
135
+ * @throws {ConfigurationError} When required environment variables are missing
136
+ * @throws {ApiError} When API request fails
137
+ * @throws {NetworkError} When network request fails
138
+ */
139
+ export declare function deleteUserAttribute(userId: string, attributeDefinitionId: string, options?: UserAttributeOptions): Promise<void>;
140
+ /**
141
+ * Gets all attributes for a specific user.
142
+ *
143
+ * @param userId - User ID
144
+ * @param options - Optional configuration
145
+ * @returns Promise resolving to array of user attributes
146
+ * @throws {ConfigurationError} When required environment variables are missing
147
+ * @throws {ApiError} When API request fails
148
+ * @throws {NetworkError} When network request fails
149
+ */
150
+ export declare function getUserAttributes(userId: string, options?: UserAttributeOptions): Promise<UserAttributeDTO[]>;
151
+ /**
152
+ * Lists user attributes with pagination.
153
+ *
154
+ * @param userId - User ID
155
+ * @param request - List request parameters
156
+ * @param options - Optional configuration
157
+ * @returns Promise resolving to paginated list of user attributes
158
+ * @throws {ConfigurationError} When required environment variables are missing
159
+ * @throws {ApiError} When API request fails
160
+ * @throws {NetworkError} When network request fails
161
+ */
162
+ export declare function listUserAttributes(userId: string, request?: ListUserAttributesRequest & UserAttributeOptions): Promise<{
163
+ content: UserAttributeDTO[];
164
+ totalElements: number;
165
+ }>;
166
+ /**
167
+ * Lists all users who have a specific attribute.
168
+ *
169
+ * @param attributeDefinitionId - Attribute definition ID
170
+ * @param request - List request parameters
171
+ * @param options - Optional configuration
172
+ * @returns Promise resolving to paginated list of user attributes
173
+ * @throws {ConfigurationError} When required environment variables are missing
174
+ * @throws {ApiError} When API request fails
175
+ * @throws {NetworkError} When network request fails
176
+ */
177
+ export declare function listAttributeUsers(attributeDefinitionId: string, request?: ListUserAttributesRequest & UserAttributeOptions): Promise<{
178
+ content: UserAttributeDTO[];
179
+ totalElements: number;
180
+ }>;
181
+ /**
182
+ * Lists all user attributes grouped by user with pagination.
183
+ *
184
+ * @param request - List request parameters
185
+ * @param options - Optional configuration
186
+ * @returns Promise resolving to paginated list of grouped user attributes
187
+ * @throws {ConfigurationError} When required environment variables are missing
188
+ * @throws {ApiError} When API request fails
189
+ * @throws {NetworkError} When network request fails
190
+ */
191
+ export declare function listAllUserAttributes(request?: ListAllUserAttributesRequest & UserAttributeOptions): Promise<{
192
+ content: UserAttributeGroupedDTO[];
193
+ totalElements: number;
194
+ }>;
@@ -0,0 +1,628 @@
1
+ import { getAppToken } from "../token.js";
2
+ import { ApiError, ConfigurationError, NetworkError } from "../errors.js";
3
+ // ==================== Helper Functions ====================
4
+ /**
5
+ * Parses standard API response format: { code, msg, data }
6
+ */
7
+ function parseApiResponse(json, errorMessage, statusCode) {
8
+ if (typeof json !== "object" || json === null) {
9
+ throw new ApiError(`Invalid response: ${errorMessage} - not an object`, statusCode);
10
+ }
11
+ const response = json;
12
+ if (response.code !== 200) {
13
+ const errorMsg = typeof response.msg === "string" ? response.msg : errorMessage;
14
+ throw new ApiError(errorMsg, statusCode, response.code);
15
+ }
16
+ if (!response.data) {
17
+ throw new ApiError(`Invalid response: ${errorMessage} - missing data`, statusCode);
18
+ }
19
+ return response.data;
20
+ }
21
+ // ==================== Attribute Definition Management ====================
22
+ /**
23
+ * Creates a new user attribute definition.
24
+ *
25
+ * @param request - Attribute definition creation request
26
+ * @param options - Optional configuration
27
+ * @returns Promise resolving to created attribute definition
28
+ * @throws {ConfigurationError} When required environment variables are missing
29
+ * @throws {ApiError} When API request fails
30
+ * @throws {NetworkError} When network request fails
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * const definition = await createUserAttributeDefinition({
35
+ * attribute_name: "department",
36
+ * description: "User's department",
37
+ * schema_definition: { type: "string" },
38
+ * is_enabled: true,
39
+ * });
40
+ * ```
41
+ */
42
+ export async function createUserAttributeDefinition(request, options) {
43
+ const token = options?.appToken ?? (await getAppToken(options));
44
+ const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
45
+ const base = options?.baseUrl ?? env?.TALE_BASE_URL ?? undefined;
46
+ if (!base) {
47
+ throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
48
+ }
49
+ const url = new URL(String(base).replace(/\/+$/, "") + "/user-attribute/v1/definition");
50
+ let response;
51
+ try {
52
+ response = await globalThis.fetch(url.toString(), {
53
+ method: "POST",
54
+ headers: {
55
+ "Content-Type": "application/json",
56
+ "x-t-token": token,
57
+ },
58
+ body: JSON.stringify(request),
59
+ });
60
+ }
61
+ catch (error) {
62
+ throw new NetworkError(`Failed to create user attribute definition: ${error instanceof Error ? error.message : "Unknown error"}`);
63
+ }
64
+ const json = await response.json();
65
+ return parseApiResponse(json, "Failed to create user attribute definition", response.status);
66
+ }
67
+ /**
68
+ * Updates an existing user attribute definition.
69
+ *
70
+ * @param openId - Attribute definition open ID
71
+ * @param request - Attribute definition update request
72
+ * @param options - Optional configuration
73
+ * @returns Promise resolving to updated attribute definition
74
+ * @throws {ConfigurationError} When required environment variables are missing
75
+ * @throws {ApiError} When API request fails
76
+ * @throws {NetworkError} When network request fails
77
+ */
78
+ export async function updateUserAttributeDefinition(openId, request, options) {
79
+ const token = options?.appToken ?? (await getAppToken(options));
80
+ const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
81
+ const base = options?.baseUrl ?? env?.TALE_BASE_URL ?? undefined;
82
+ if (!base) {
83
+ throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
84
+ }
85
+ const url = new URL(String(base).replace(/\/+$/, "") +
86
+ `/user-attribute/v1/definition/${encodeURIComponent(openId)}`);
87
+ let response;
88
+ try {
89
+ response = await globalThis.fetch(url.toString(), {
90
+ method: "PUT",
91
+ headers: {
92
+ "Content-Type": "application/json",
93
+ "x-t-token": token,
94
+ },
95
+ body: JSON.stringify(request),
96
+ });
97
+ }
98
+ catch (error) {
99
+ throw new NetworkError(`Failed to update user attribute definition: ${error instanceof Error ? error.message : "Unknown error"}`);
100
+ }
101
+ const json = await response.json();
102
+ return parseApiResponse(json, "Failed to update user attribute definition", response.status);
103
+ }
104
+ /**
105
+ * Deletes a user attribute definition.
106
+ *
107
+ * @param openId - Attribute definition open ID
108
+ * @param options - Optional configuration
109
+ * @throws {ConfigurationError} When required environment variables are missing
110
+ * @throws {ApiError} When API request fails
111
+ * @throws {NetworkError} When network request fails
112
+ */
113
+ export async function deleteUserAttributeDefinition(openId, options) {
114
+ const token = options?.appToken ?? (await getAppToken(options));
115
+ const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
116
+ const base = options?.baseUrl ?? env?.TALE_BASE_URL ?? undefined;
117
+ if (!base) {
118
+ throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
119
+ }
120
+ const url = new URL(String(base).replace(/\/+$/, "") +
121
+ `/user-attribute/v1/definition/${encodeURIComponent(openId)}`);
122
+ let response;
123
+ try {
124
+ response = await globalThis.fetch(url.toString(), {
125
+ method: "DELETE",
126
+ headers: {
127
+ "Content-Type": "application/json",
128
+ "x-t-token": token,
129
+ },
130
+ });
131
+ }
132
+ catch (error) {
133
+ throw new NetworkError(`Failed to delete user attribute definition: ${error instanceof Error ? error.message : "Unknown error"}`);
134
+ }
135
+ const json = await response.json();
136
+ if (typeof json !== "object" || json === null) {
137
+ throw new ApiError("Invalid user attribute definition deletion response", response.status);
138
+ }
139
+ const apiResponse = json;
140
+ if (apiResponse.code !== 200) {
141
+ const errorMsg = typeof apiResponse.msg === "string"
142
+ ? apiResponse.msg
143
+ : "Failed to delete user attribute definition";
144
+ throw new ApiError(errorMsg, response.status, apiResponse.code);
145
+ }
146
+ }
147
+ /**
148
+ * Gets a user attribute definition by open ID.
149
+ *
150
+ * @param openId - Attribute definition open ID
151
+ * @param options - Optional configuration
152
+ * @returns Promise resolving to attribute definition
153
+ * @throws {ConfigurationError} When required environment variables are missing
154
+ * @throws {ApiError} When API request fails
155
+ * @throws {NetworkError} When network request fails
156
+ */
157
+ export async function getUserAttributeDefinition(openId, options) {
158
+ const token = options?.appToken ?? (await getAppToken(options));
159
+ const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
160
+ const base = options?.baseUrl ?? env?.TALE_BASE_URL ?? undefined;
161
+ if (!base) {
162
+ throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
163
+ }
164
+ const url = new URL(String(base).replace(/\/+$/, "") +
165
+ `/user-attribute/v1/definition/${encodeURIComponent(openId)}`);
166
+ let response;
167
+ try {
168
+ response = await globalThis.fetch(url.toString(), {
169
+ method: "GET",
170
+ headers: {
171
+ "Content-Type": "application/json",
172
+ "x-t-token": token,
173
+ },
174
+ });
175
+ }
176
+ catch (error) {
177
+ throw new NetworkError(`Failed to get user attribute definition: ${error instanceof Error ? error.message : "Unknown error"}`);
178
+ }
179
+ const json = await response.json();
180
+ return parseApiResponse(json, "Failed to get user attribute definition", response.status);
181
+ }
182
+ /**
183
+ * Lists user attribute definitions with pagination and optional filtering.
184
+ *
185
+ * @param request - List request parameters
186
+ * @param options - Optional configuration
187
+ * @returns Promise resolving to paginated list of attribute definitions
188
+ * @throws {ConfigurationError} When required environment variables are missing
189
+ * @throws {ApiError} When API request fails
190
+ * @throws {NetworkError} When network request fails
191
+ *
192
+ * @example
193
+ * ```typescript
194
+ * const result = await listUserAttributeDefinitions({
195
+ * page: 0,
196
+ * size: 20,
197
+ * keyword: "department",
198
+ * });
199
+ * console.log(result.content); // Array of definitions
200
+ * console.log(result.totalElements); // Total count
201
+ * ```
202
+ */
203
+ export async function listUserAttributeDefinitions(request) {
204
+ const token = request?.appToken ?? (await getAppToken(request));
205
+ const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
206
+ const base = request?.baseUrl ?? env?.TALE_BASE_URL ?? undefined;
207
+ if (!base) {
208
+ throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
209
+ }
210
+ const url = new URL(String(base).replace(/\/+$/, "") + "/user-attribute/v1/definition");
211
+ const { appToken, baseUrl, ...requestParams } = request || {};
212
+ const queryParams = {
213
+ page: 0,
214
+ size: 20,
215
+ ...requestParams,
216
+ };
217
+ Object.entries(queryParams).forEach(([key, value]) => {
218
+ if (value !== undefined) {
219
+ url.searchParams.append(key, String(value));
220
+ }
221
+ });
222
+ let response;
223
+ try {
224
+ response = await globalThis.fetch(url.toString(), {
225
+ method: "GET",
226
+ headers: {
227
+ "Content-Type": "application/json",
228
+ "x-t-token": token,
229
+ },
230
+ });
231
+ }
232
+ catch (error) {
233
+ throw new NetworkError(`Failed to list user attribute definitions: ${error instanceof Error ? error.message : "Unknown error"}`);
234
+ }
235
+ const json = await response.json();
236
+ const data = parseApiResponse(json, "Failed to list user attribute definitions", response.status);
237
+ if (!Array.isArray(data.content)) {
238
+ throw new ApiError("Invalid user attribute definitions response: content is not an array", response.status);
239
+ }
240
+ return data;
241
+ }
242
+ /**
243
+ * Lists all enabled user attribute definitions.
244
+ *
245
+ * @param options - Optional configuration
246
+ * @returns Promise resolving to array of enabled attribute definitions
247
+ * @throws {ConfigurationError} When required environment variables are missing
248
+ * @throws {ApiError} When API request fails
249
+ * @throws {NetworkError} When network request fails
250
+ */
251
+ export async function listEnabledUserAttributeDefinitions(options) {
252
+ const token = options?.appToken ?? (await getAppToken(options));
253
+ const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
254
+ const base = options?.baseUrl ?? env?.TALE_BASE_URL ?? undefined;
255
+ if (!base) {
256
+ throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
257
+ }
258
+ const url = new URL(String(base).replace(/\/+$/, "") +
259
+ "/user-attribute/v1/definition/enabled");
260
+ let response;
261
+ try {
262
+ response = await globalThis.fetch(url.toString(), {
263
+ method: "GET",
264
+ headers: {
265
+ "Content-Type": "application/json",
266
+ "x-t-token": token,
267
+ },
268
+ });
269
+ }
270
+ catch (error) {
271
+ throw new NetworkError(`Failed to list enabled user attribute definitions: ${error instanceof Error ? error.message : "Unknown error"}`);
272
+ }
273
+ const json = await response.json();
274
+ const result = parseApiResponse(json, "Failed to list enabled user attribute definitions", response.status);
275
+ if (!Array.isArray(result)) {
276
+ throw new ApiError("Invalid enabled user attribute definitions response: not an array", response.status);
277
+ }
278
+ return result;
279
+ }
280
+ /**
281
+ * Toggles the enabled status of a user attribute definition.
282
+ *
283
+ * @param openId - Attribute definition open ID
284
+ * @param isEnabled - Whether the definition should be enabled
285
+ * @param options - Optional configuration
286
+ * @returns Promise resolving to updated attribute definition
287
+ * @throws {ConfigurationError} When required environment variables are missing
288
+ * @throws {ApiError} When API request fails
289
+ * @throws {NetworkError} When network request fails
290
+ */
291
+ export async function toggleUserAttributeDefinitionStatus(openId, isEnabled, options) {
292
+ const token = options?.appToken ?? (await getAppToken(options));
293
+ const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
294
+ const base = options?.baseUrl ?? env?.TALE_BASE_URL ?? undefined;
295
+ if (!base) {
296
+ throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
297
+ }
298
+ const url = new URL(String(base).replace(/\/+$/, "") +
299
+ `/user-attribute/v1/definition/${encodeURIComponent(openId)}/status`);
300
+ url.searchParams.append("enabled", String(isEnabled));
301
+ let response;
302
+ try {
303
+ response = await globalThis.fetch(url.toString(), {
304
+ method: "PUT",
305
+ headers: {
306
+ "Content-Type": "application/json",
307
+ "x-t-token": token,
308
+ },
309
+ });
310
+ }
311
+ catch (error) {
312
+ throw new NetworkError(`Failed to toggle user attribute definition status: ${error instanceof Error ? error.message : "Unknown error"}`);
313
+ }
314
+ const json = await response.json();
315
+ return parseApiResponse(json, "Failed to toggle user attribute definition status", response.status);
316
+ }
317
+ // ==================== User Attribute Value Management ====================
318
+ /**
319
+ * Sets a user attribute value.
320
+ *
321
+ * @param userId - User ID
322
+ * @param attributeDefinitionId - Attribute definition ID
323
+ * @param request - Attribute value to set
324
+ * @param options - Optional configuration
325
+ * @returns Promise resolving to updated user attribute
326
+ * @throws {ConfigurationError} When required environment variables are missing
327
+ * @throws {ApiError} When API request fails
328
+ * @throws {NetworkError} When network request fails
329
+ */
330
+ export async function setUserAttribute(userId, attributeDefinitionId, request, options) {
331
+ const token = options?.appToken ?? (await getAppToken(options));
332
+ const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
333
+ const base = options?.baseUrl ?? env?.TALE_BASE_URL ?? undefined;
334
+ if (!base) {
335
+ throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
336
+ }
337
+ const url = new URL(String(base).replace(/\/+$/, "") +
338
+ `/user-attribute/v1/user/${encodeURIComponent(userId)}/attribute/${encodeURIComponent(attributeDefinitionId)}`);
339
+ let response;
340
+ try {
341
+ response = await globalThis.fetch(url.toString(), {
342
+ method: "PUT",
343
+ headers: {
344
+ "Content-Type": "application/json",
345
+ "x-t-token": token,
346
+ },
347
+ body: JSON.stringify(request),
348
+ });
349
+ }
350
+ catch (error) {
351
+ throw new NetworkError(`Failed to set user attribute: ${error instanceof Error ? error.message : "Unknown error"}`);
352
+ }
353
+ const json = await response.json();
354
+ return parseApiResponse(json, "Failed to set user attribute", response.status);
355
+ }
356
+ /**
357
+ * Gets a user attribute value.
358
+ *
359
+ * @param userId - User ID
360
+ * @param attributeDefinitionId - Attribute definition ID
361
+ * @param options - Optional configuration
362
+ * @returns Promise resolving to user attribute
363
+ * @throws {ConfigurationError} When required environment variables are missing
364
+ * @throws {ApiError} When API request fails
365
+ * @throws {NetworkError} When network request fails
366
+ */
367
+ export async function getUserAttribute(userId, attributeDefinitionId, options) {
368
+ const token = options?.appToken ?? (await getAppToken(options));
369
+ const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
370
+ const base = options?.baseUrl ?? env?.TALE_BASE_URL ?? undefined;
371
+ if (!base) {
372
+ throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
373
+ }
374
+ const url = new URL(String(base).replace(/\/+$/, "") +
375
+ `/user-attribute/v1/user/${encodeURIComponent(userId)}/attribute/${encodeURIComponent(attributeDefinitionId)}`);
376
+ let response;
377
+ try {
378
+ response = await globalThis.fetch(url.toString(), {
379
+ method: "GET",
380
+ headers: {
381
+ "Content-Type": "application/json",
382
+ "x-t-token": token,
383
+ },
384
+ });
385
+ }
386
+ catch (error) {
387
+ throw new NetworkError(`Failed to get user attribute: ${error instanceof Error ? error.message : "Unknown error"}`);
388
+ }
389
+ const json = await response.json();
390
+ return parseApiResponse(json, "Failed to get user attribute", response.status);
391
+ }
392
+ /**
393
+ * Deletes a user attribute value.
394
+ *
395
+ * @param userId - User ID
396
+ * @param attributeDefinitionId - Attribute definition ID
397
+ * @param options - Optional configuration
398
+ * @throws {ConfigurationError} When required environment variables are missing
399
+ * @throws {ApiError} When API request fails
400
+ * @throws {NetworkError} When network request fails
401
+ */
402
+ export async function deleteUserAttribute(userId, attributeDefinitionId, options) {
403
+ const token = options?.appToken ?? (await getAppToken(options));
404
+ const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
405
+ const base = options?.baseUrl ?? env?.TALE_BASE_URL ?? undefined;
406
+ if (!base) {
407
+ throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
408
+ }
409
+ const url = new URL(String(base).replace(/\/+$/, "") +
410
+ `/user-attribute/v1/user/${encodeURIComponent(userId)}/attribute/${encodeURIComponent(attributeDefinitionId)}`);
411
+ let response;
412
+ try {
413
+ response = await globalThis.fetch(url.toString(), {
414
+ method: "DELETE",
415
+ headers: {
416
+ "Content-Type": "application/json",
417
+ "x-t-token": token,
418
+ },
419
+ });
420
+ }
421
+ catch (error) {
422
+ throw new NetworkError(`Failed to delete user attribute: ${error instanceof Error ? error.message : "Unknown error"}`);
423
+ }
424
+ const json = await response.json();
425
+ if (typeof json !== "object" || json === null) {
426
+ throw new ApiError("Invalid user attribute deletion response", response.status);
427
+ }
428
+ const apiResponse = json;
429
+ if (apiResponse.code !== 200) {
430
+ const errorMsg = typeof apiResponse.msg === "string"
431
+ ? apiResponse.msg
432
+ : "Failed to delete user attribute";
433
+ throw new ApiError(errorMsg, response.status, apiResponse.code);
434
+ }
435
+ }
436
+ /**
437
+ * Gets all attributes for a specific user.
438
+ *
439
+ * @param userId - User ID
440
+ * @param options - Optional configuration
441
+ * @returns Promise resolving to array of user attributes
442
+ * @throws {ConfigurationError} When required environment variables are missing
443
+ * @throws {ApiError} When API request fails
444
+ * @throws {NetworkError} When network request fails
445
+ */
446
+ export async function getUserAttributes(userId, options) {
447
+ const token = options?.appToken ?? (await getAppToken(options));
448
+ const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
449
+ const base = options?.baseUrl ?? env?.TALE_BASE_URL ?? undefined;
450
+ if (!base) {
451
+ throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
452
+ }
453
+ const url = new URL(String(base).replace(/\/+$/, "") +
454
+ `/user-attribute/v1/user/${encodeURIComponent(userId)}/attribute`);
455
+ let response;
456
+ try {
457
+ response = await globalThis.fetch(url.toString(), {
458
+ method: "GET",
459
+ headers: {
460
+ "Content-Type": "application/json",
461
+ "x-t-token": token,
462
+ },
463
+ });
464
+ }
465
+ catch (error) {
466
+ throw new NetworkError(`Failed to get user attributes: ${error instanceof Error ? error.message : "Unknown error"}`);
467
+ }
468
+ const json = await response.json();
469
+ const result = parseApiResponse(json, "Failed to get user attributes", response.status);
470
+ if (!Array.isArray(result)) {
471
+ throw new ApiError("Invalid user attributes response: not an array", response.status);
472
+ }
473
+ return result;
474
+ }
475
+ /**
476
+ * Lists user attributes with pagination.
477
+ *
478
+ * @param userId - User ID
479
+ * @param request - List request parameters
480
+ * @param options - Optional configuration
481
+ * @returns Promise resolving to paginated list of user attributes
482
+ * @throws {ConfigurationError} When required environment variables are missing
483
+ * @throws {ApiError} When API request fails
484
+ * @throws {NetworkError} When network request fails
485
+ */
486
+ export async function listUserAttributes(userId, request) {
487
+ const token = request?.appToken ?? (await getAppToken(request));
488
+ const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
489
+ const base = request?.baseUrl ?? env?.TALE_BASE_URL ?? undefined;
490
+ if (!base) {
491
+ throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
492
+ }
493
+ const url = new URL(String(base).replace(/\/+$/, "") +
494
+ `/user-attribute/v1/user/${encodeURIComponent(userId)}/attribute/page`);
495
+ const { appToken, baseUrl, ...requestParams } = request || {};
496
+ const queryParams = {
497
+ page: 0,
498
+ size: 20,
499
+ ...requestParams,
500
+ };
501
+ Object.entries(queryParams).forEach(([key, value]) => {
502
+ if (value !== undefined) {
503
+ url.searchParams.append(key, String(value));
504
+ }
505
+ });
506
+ let response;
507
+ try {
508
+ response = await globalThis.fetch(url.toString(), {
509
+ method: "GET",
510
+ headers: {
511
+ "Content-Type": "application/json",
512
+ "x-t-token": token,
513
+ },
514
+ });
515
+ }
516
+ catch (error) {
517
+ throw new NetworkError(`Failed to list user attributes: ${error instanceof Error ? error.message : "Unknown error"}`);
518
+ }
519
+ const json = await response.json();
520
+ const data = parseApiResponse(json, "Failed to list user attributes", response.status);
521
+ if (!Array.isArray(data.content)) {
522
+ throw new ApiError("Invalid user attributes response: content is not an array", response.status);
523
+ }
524
+ return data;
525
+ }
526
+ /**
527
+ * Lists all users who have a specific attribute.
528
+ *
529
+ * @param attributeDefinitionId - Attribute definition ID
530
+ * @param request - List request parameters
531
+ * @param options - Optional configuration
532
+ * @returns Promise resolving to paginated list of user attributes
533
+ * @throws {ConfigurationError} When required environment variables are missing
534
+ * @throws {ApiError} When API request fails
535
+ * @throws {NetworkError} When network request fails
536
+ */
537
+ export async function listAttributeUsers(attributeDefinitionId, request) {
538
+ const token = request?.appToken ?? (await getAppToken(request));
539
+ const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
540
+ const base = request?.baseUrl ?? env?.TALE_BASE_URL ?? undefined;
541
+ if (!base) {
542
+ throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
543
+ }
544
+ const url = new URL(String(base).replace(/\/+$/, "") +
545
+ `/user-attribute/v1/definition/${encodeURIComponent(attributeDefinitionId)}/users`);
546
+ const { appToken, baseUrl, ...requestParams } = request || {};
547
+ const queryParams = {
548
+ page: 0,
549
+ size: 20,
550
+ ...requestParams,
551
+ };
552
+ Object.entries(queryParams).forEach(([key, value]) => {
553
+ if (value !== undefined) {
554
+ url.searchParams.append(key, String(value));
555
+ }
556
+ });
557
+ let response;
558
+ try {
559
+ response = await globalThis.fetch(url.toString(), {
560
+ method: "GET",
561
+ headers: {
562
+ "Content-Type": "application/json",
563
+ "x-t-token": token,
564
+ },
565
+ });
566
+ }
567
+ catch (error) {
568
+ throw new NetworkError(`Failed to list attribute users: ${error instanceof Error ? error.message : "Unknown error"}`);
569
+ }
570
+ const json = await response.json();
571
+ const data = parseApiResponse(json, "Failed to list attribute users", response.status);
572
+ if (!Array.isArray(data.content)) {
573
+ throw new ApiError("Invalid attribute users response: content is not an array", response.status);
574
+ }
575
+ return data;
576
+ }
577
+ /**
578
+ * Lists all user attributes grouped by user with pagination.
579
+ *
580
+ * @param request - List request parameters
581
+ * @param options - Optional configuration
582
+ * @returns Promise resolving to paginated list of grouped user attributes
583
+ * @throws {ConfigurationError} When required environment variables are missing
584
+ * @throws {ApiError} When API request fails
585
+ * @throws {NetworkError} When network request fails
586
+ */
587
+ export async function listAllUserAttributes(request) {
588
+ const token = request?.appToken ?? (await getAppToken(request));
589
+ const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
590
+ const base = request?.baseUrl ?? env?.TALE_BASE_URL ?? undefined;
591
+ if (!base) {
592
+ throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
593
+ }
594
+ const url = new URL(String(base).replace(/\/+$/, "") +
595
+ "/user-attribute/v1/user/attribute/page");
596
+ const { appToken, baseUrl, ...requestParams } = request || {};
597
+ const queryParams = {
598
+ page: 0,
599
+ size: 20,
600
+ sort_by: "createdAt",
601
+ sort_direction: "desc",
602
+ ...requestParams,
603
+ };
604
+ Object.entries(queryParams).forEach(([key, value]) => {
605
+ if (value !== undefined) {
606
+ url.searchParams.append(key, String(value));
607
+ }
608
+ });
609
+ let response;
610
+ try {
611
+ response = await globalThis.fetch(url.toString(), {
612
+ method: "GET",
613
+ headers: {
614
+ "Content-Type": "application/json",
615
+ "x-t-token": token,
616
+ },
617
+ });
618
+ }
619
+ catch (error) {
620
+ throw new NetworkError(`Failed to list all user attributes: ${error instanceof Error ? error.message : "Unknown error"}`);
621
+ }
622
+ const json = await response.json();
623
+ const data = parseApiResponse(json, "Failed to list all user attributes", response.status);
624
+ if (!Array.isArray(data.content)) {
625
+ throw new ApiError("Invalid all user attributes response: content is not an array", response.status);
626
+ }
627
+ return data;
628
+ }
@@ -0,0 +1,108 @@
1
+ import type { CommonOptions } from "../common/types.js";
2
+ /**
3
+ * User attribute definition
4
+ */
5
+ export interface UserAttributeDefinition {
6
+ open_id: string;
7
+ attribute_name: string;
8
+ description?: string;
9
+ schema_definition: Record<string, unknown>;
10
+ is_enabled: boolean;
11
+ created_at: string;
12
+ updated_at: string;
13
+ remark?: string;
14
+ }
15
+ /**
16
+ * User attribute value (matches backend UserAttributeDTO)
17
+ */
18
+ export interface UserAttributeDTO {
19
+ user_id: string;
20
+ attribute_definition_id: string;
21
+ attribute_name: string;
22
+ attribute_value: Record<string, unknown>;
23
+ created_at: string;
24
+ updated_at: string;
25
+ remark?: string;
26
+ }
27
+ /**
28
+ * User attribute item (without user_id, matches backend UserAttributeItemDTO)
29
+ */
30
+ export interface UserAttributeItemDTO {
31
+ attribute_definition_id: string;
32
+ attribute_name: string;
33
+ attribute_value: Record<string, unknown>;
34
+ created_at: string;
35
+ updated_at: string;
36
+ remark?: string;
37
+ }
38
+ /**
39
+ * User attribute grouped by user (matches backend UserAttributeGroupedDTO)
40
+ */
41
+ export interface UserAttributeGroupedDTO {
42
+ user_id: string;
43
+ username: string;
44
+ nickname: string;
45
+ email: string;
46
+ phone: string;
47
+ avatar_url?: string;
48
+ remark?: string;
49
+ is_frozen: boolean;
50
+ registered_at: string;
51
+ attributes: UserAttributeItemDTO[];
52
+ }
53
+ /**
54
+ * Request for creating a user attribute definition
55
+ */
56
+ export interface CreateUserAttributeDefinitionRequest {
57
+ attribute_name: string;
58
+ description?: string;
59
+ schema_definition: Record<string, unknown>;
60
+ is_enabled?: boolean;
61
+ remark?: string;
62
+ }
63
+ /**
64
+ * Request for updating a user attribute definition
65
+ */
66
+ export interface UpdateUserAttributeDefinitionRequest {
67
+ attribute_name?: string;
68
+ description?: string;
69
+ schema_definition?: Record<string, unknown>;
70
+ is_enabled?: boolean;
71
+ remark?: string;
72
+ }
73
+ /**
74
+ * Request for setting a user attribute value
75
+ */
76
+ export interface SetUserAttributeRequest {
77
+ attribute_value: Record<string, unknown>;
78
+ remark?: string;
79
+ }
80
+ /**
81
+ * Request for listing user attribute definitions
82
+ */
83
+ export interface ListUserAttributeDefinitionsRequest {
84
+ page?: number;
85
+ size?: number;
86
+ keyword?: string;
87
+ }
88
+ /**
89
+ * Request for listing user attributes
90
+ */
91
+ export interface ListUserAttributesRequest {
92
+ page?: number;
93
+ size?: number;
94
+ }
95
+ /**
96
+ * Request for listing all user attributes (grouped)
97
+ */
98
+ export interface ListAllUserAttributesRequest {
99
+ page?: number;
100
+ size?: number;
101
+ sort_by?: string;
102
+ sort_direction?: "asc" | "desc";
103
+ }
104
+ /**
105
+ * Options for user attribute operations
106
+ */
107
+ export interface UserAttributeOptions extends CommonOptions {
108
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tale-js-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Official TypeScript SDK for Tale backend services",
5
5
  "keywords": [
6
6
  "tale",