@turinhub/tale-js-sdk 1.3.0 → 2.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/README.md +90 -13
- package/dist/acl/index.d.ts +62 -49
- package/dist/acl/index.js +262 -67
- package/dist/acl/types.d.ts +63 -98
- package/dist/app/index.d.ts +10 -0
- package/dist/app/index.js +198 -0
- package/dist/app/types.d.ts +101 -0
- package/dist/app/types.js +1 -0
- package/dist/app-token/index.d.ts +7 -0
- package/dist/app-token/index.js +58 -0
- package/dist/app-token/types.d.ts +25 -0
- package/dist/app-token/types.js +1 -0
- package/dist/attachment/index.d.ts +17 -0
- package/dist/attachment/index.js +247 -0
- package/dist/attachment/types.d.ts +82 -0
- package/dist/attachment/types.js +1 -0
- package/dist/attachment-type/index.d.ts +15 -0
- package/dist/attachment-type/index.js +203 -0
- package/dist/attachment-type/types.d.ts +60 -0
- package/dist/attachment-type/types.js +1 -0
- package/dist/auth/index.d.ts +21 -21
- package/dist/auth/index.js +66 -66
- package/dist/auth/types.d.ts +51 -51
- package/dist/cms/file.d.ts +88 -70
- package/dist/cms/file.js +228 -77
- package/dist/cms/folder.d.ts +9 -9
- package/dist/cms/folder.js +18 -18
- package/dist/cms/types.d.ts +58 -38
- package/dist/common/http.d.ts +17 -0
- package/dist/common/http.js +141 -0
- package/dist/common/types.d.ts +58 -63
- package/dist/index.d.ts +6 -1
- package/dist/index.js +4 -0
- package/dist/rbac/index.d.ts +37 -42
- package/dist/rbac/index.js +96 -98
- package/dist/rbac/types.d.ts +38 -40
- package/dist/status.d.ts +11 -11
- package/dist/status.js +30 -3
- package/dist/task/index.d.ts +15 -147
- package/dist/task/index.js +170 -161
- package/dist/task/types.d.ts +57 -81
- package/dist/task-type/index.d.ts +7 -7
- package/dist/task-type/index.js +12 -12
- package/dist/task-type/types.d.ts +18 -34
- package/dist/token.d.ts +3 -3
- package/dist/token.js +4 -4
- package/dist/user/index.d.ts +28 -29
- package/dist/user/index.js +69 -74
- package/dist/user/types.d.ts +32 -33
- package/dist/user-attribute/index.d.ts +4 -7
- package/dist/user-attribute/index.js +19 -22
- package/dist/user-attribute/types.d.ts +29 -29
- package/dist/user-group/index.d.ts +4 -223
- package/dist/user-group/index.js +61 -479
- package/dist/user-group/types.d.ts +1 -1
- package/package.json +1 -1
package/dist/task-type/index.js
CHANGED
|
@@ -37,18 +37,18 @@ function getBaseUrl(options) {
|
|
|
37
37
|
* @example
|
|
38
38
|
* ```typescript
|
|
39
39
|
* const taskType = await createTaskType({
|
|
40
|
-
*
|
|
41
|
-
*
|
|
40
|
+
* typeCode: "daily_review",
|
|
41
|
+
* typeName: "Daily Review",
|
|
42
42
|
* description: "Daily review tasks",
|
|
43
|
-
*
|
|
44
|
-
*
|
|
43
|
+
* allowMultiple: true,
|
|
44
|
+
* isEnabled: true,
|
|
45
45
|
* });
|
|
46
46
|
* ```
|
|
47
47
|
*/
|
|
48
48
|
export async function createTaskType(request, options) {
|
|
49
49
|
const token = options?.appToken ?? (await getAppToken(options));
|
|
50
50
|
const base = getBaseUrl(options);
|
|
51
|
-
const url = new URL(base + "/task-type/
|
|
51
|
+
const url = new URL(base + "/task-type/v2/types");
|
|
52
52
|
let response;
|
|
53
53
|
try {
|
|
54
54
|
response = await globalThis.fetch(url.toString(), {
|
|
@@ -80,7 +80,7 @@ export async function createTaskType(request, options) {
|
|
|
80
80
|
export async function updateTaskType(typeId, request, options) {
|
|
81
81
|
const token = options?.appToken ?? (await getAppToken(options));
|
|
82
82
|
const base = getBaseUrl(options);
|
|
83
|
-
const url = new URL(base + `/task-type/
|
|
83
|
+
const url = new URL(base + `/task-type/v2/types/${encodeURIComponent(typeId)}`);
|
|
84
84
|
let response;
|
|
85
85
|
try {
|
|
86
86
|
response = await globalThis.fetch(url.toString(), {
|
|
@@ -110,7 +110,7 @@ export async function updateTaskType(typeId, request, options) {
|
|
|
110
110
|
export async function deleteTaskType(typeId, options) {
|
|
111
111
|
const token = options?.appToken ?? (await getAppToken(options));
|
|
112
112
|
const base = getBaseUrl(options);
|
|
113
|
-
const url = new URL(base + `/task-type/
|
|
113
|
+
const url = new URL(base + `/task-type/v2/types/${encodeURIComponent(typeId)}`);
|
|
114
114
|
let response;
|
|
115
115
|
try {
|
|
116
116
|
response = await globalThis.fetch(url.toString(), {
|
|
@@ -149,7 +149,7 @@ export async function deleteTaskType(typeId, options) {
|
|
|
149
149
|
export async function getTaskType(typeId, options) {
|
|
150
150
|
const token = options?.appToken ?? (await getAppToken(options));
|
|
151
151
|
const base = getBaseUrl(options);
|
|
152
|
-
const url = new URL(base + `/task-type/
|
|
152
|
+
const url = new URL(base + `/task-type/v2/types/${encodeURIComponent(typeId)}`);
|
|
153
153
|
let response;
|
|
154
154
|
try {
|
|
155
155
|
response = await globalThis.fetch(url.toString(), {
|
|
@@ -181,9 +181,9 @@ export async function getTaskType(typeId, options) {
|
|
|
181
181
|
* const result = await listTaskTypes({
|
|
182
182
|
* page: 0,
|
|
183
183
|
* size: 20,
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
184
|
+
* isEnabled: true,
|
|
185
|
+
* sort: "createdAt",
|
|
186
|
+
* sortDirection: "desc",
|
|
187
187
|
* });
|
|
188
188
|
* console.log(result.content); // Array of task types
|
|
189
189
|
* console.log(result.total); // Total count
|
|
@@ -233,7 +233,7 @@ export async function listTaskTypes(request) {
|
|
|
233
233
|
export async function listEnabledTaskTypes(options) {
|
|
234
234
|
const token = options?.appToken ?? (await getAppToken(options));
|
|
235
235
|
const base = getBaseUrl(options);
|
|
236
|
-
const url = new URL(base + "/task-type/
|
|
236
|
+
const url = new URL(base + "/task-type/v2/types/enabled");
|
|
237
237
|
let response;
|
|
238
238
|
try {
|
|
239
239
|
response = await globalThis.fetch(url.toString(), {
|
|
@@ -1,54 +1,38 @@
|
|
|
1
1
|
import type { CommonOptions } from "../common/types.js";
|
|
2
|
-
/**
|
|
3
|
-
* TaskType entity (matches backend TaskTypeVO)
|
|
4
|
-
*/
|
|
5
2
|
export interface TaskType {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
typeId: string;
|
|
4
|
+
appId: string;
|
|
5
|
+
typeCode: string;
|
|
6
|
+
typeName: string;
|
|
10
7
|
description?: string;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
allowMultiple: boolean;
|
|
9
|
+
isEnabled: boolean;
|
|
10
|
+
parentTaskTypeId?: string;
|
|
11
|
+
createdAt: string;
|
|
12
|
+
updatedAt: string;
|
|
16
13
|
remark?: string;
|
|
17
14
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Request for creating a task type
|
|
20
|
-
* Note: type_code is auto-generated by the backend
|
|
21
|
-
*/
|
|
22
15
|
export interface CreateTaskTypeRequest {
|
|
23
|
-
|
|
16
|
+
typeName: string;
|
|
24
17
|
description?: string;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
allowMultiple?: boolean;
|
|
19
|
+
isEnabled?: boolean;
|
|
20
|
+
parentTaskTypeId?: string;
|
|
28
21
|
remark?: string;
|
|
29
22
|
}
|
|
30
|
-
/**
|
|
31
|
-
* Request for updating a task type
|
|
32
|
-
*/
|
|
33
23
|
export interface UpdateTaskTypeRequest {
|
|
34
|
-
|
|
24
|
+
typeName?: string;
|
|
35
25
|
description?: string;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
26
|
+
allowMultiple?: boolean;
|
|
27
|
+
isEnabled?: boolean;
|
|
28
|
+
parentTaskTypeId?: string;
|
|
39
29
|
remark?: string;
|
|
40
30
|
}
|
|
41
|
-
/**
|
|
42
|
-
* Request for listing task types
|
|
43
|
-
*/
|
|
44
31
|
export interface ListTaskTypesRequest {
|
|
45
32
|
page?: number;
|
|
46
33
|
size?: number;
|
|
47
34
|
sort?: string;
|
|
48
|
-
|
|
35
|
+
isEnabled?: boolean;
|
|
49
36
|
}
|
|
50
|
-
/**
|
|
51
|
-
* Options for task type operations
|
|
52
|
-
*/
|
|
53
37
|
export interface TaskTypeOptions extends CommonOptions {
|
|
54
38
|
}
|
package/dist/token.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ import { TaleSdkError, ConfigurationError, ApiError, EnvironmentError, TokenErro
|
|
|
2
2
|
export { TaleSdkError, ConfigurationError, ApiError, EnvironmentError, TokenError, NetworkError, ValidationError, isTaleSdkError, createErrorFromUnknown, };
|
|
3
3
|
export type AppTokenData = {
|
|
4
4
|
type: string;
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
appKey: string;
|
|
6
|
+
appName: string;
|
|
7
7
|
token: string;
|
|
8
8
|
status: string;
|
|
9
|
-
|
|
9
|
+
expiredAt: string;
|
|
10
10
|
};
|
|
11
11
|
export type AppTokenJson = {
|
|
12
12
|
data: AppTokenData;
|
package/dist/token.js
CHANGED
|
@@ -53,13 +53,13 @@ async function fetchAppToken(options) {
|
|
|
53
53
|
if (!base || !appKey || !appSecret) {
|
|
54
54
|
throw new ConfigurationError("Missing required environment variables: TALE_BASE_URL, TALE_APP_KEY, TALE_APP_SECRET");
|
|
55
55
|
}
|
|
56
|
-
const url = String(base).replace(/\/+$/, "") + "/app/
|
|
56
|
+
const url = String(base).replace(/\/+$/, "") + "/app/v2/token";
|
|
57
57
|
let response;
|
|
58
58
|
try {
|
|
59
59
|
response = await globalThis.fetch(url, {
|
|
60
60
|
method: "POST",
|
|
61
61
|
headers: { "Content-Type": "application/json" },
|
|
62
|
-
body: JSON.stringify({
|
|
62
|
+
body: JSON.stringify({ appKey, appSecret }),
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
catch (error) {
|
|
@@ -75,7 +75,7 @@ async function fetchAppToken(options) {
|
|
|
75
75
|
function isTokenValid(info) {
|
|
76
76
|
if (!info)
|
|
77
77
|
return false;
|
|
78
|
-
const t = new Date(info.
|
|
78
|
+
const t = new Date(info.expiredAt).getTime();
|
|
79
79
|
return Number.isFinite(t) && t > Date.now();
|
|
80
80
|
}
|
|
81
81
|
function isServerEnv() {
|
|
@@ -104,7 +104,7 @@ export async function getAppToken(options) {
|
|
|
104
104
|
try {
|
|
105
105
|
const json = await inFlight;
|
|
106
106
|
cached = json.data;
|
|
107
|
-
scheduleExpiry(cached.
|
|
107
|
+
scheduleExpiry(cached.expiredAt);
|
|
108
108
|
return cached.token;
|
|
109
109
|
}
|
|
110
110
|
finally {
|
package/dist/user/index.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export type { CreateUserRequest, AppInfo, User, Role, Privilege, UserGroup, User
|
|
|
20
20
|
* nickname: 'John Doe',
|
|
21
21
|
* email: 'john@example.com'
|
|
22
22
|
* });
|
|
23
|
-
* console.log('User created:', result.user.
|
|
23
|
+
* console.log('User created:', result.user.userId);
|
|
24
24
|
* } catch (error) {
|
|
25
25
|
* console.error('Failed to create user:', error.message);
|
|
26
26
|
* }
|
|
@@ -30,7 +30,7 @@ export declare function createUser(userData: CreateUserRequest, options?: Create
|
|
|
30
30
|
/**
|
|
31
31
|
* Retrieves user information by ID or open ID.
|
|
32
32
|
*
|
|
33
|
-
* @param userId - Optional user ID (
|
|
33
|
+
* @param userId - Optional user ID (openId) to query. If not provided, returns current user info
|
|
34
34
|
* @param options - Optional parameters for inclusion flags and configuration
|
|
35
35
|
* @returns Promise resolving to the user information
|
|
36
36
|
* @throws {ConfigurationError} When required environment variables are missing
|
|
@@ -42,7 +42,7 @@ export declare function createUser(userData: CreateUserRequest, options?: Create
|
|
|
42
42
|
* import { getUserById } from '@tale/client';
|
|
43
43
|
*
|
|
44
44
|
* try {
|
|
45
|
-
* const result = await getUserById('
|
|
45
|
+
* const result = await getUserById('userOpenId_here');
|
|
46
46
|
* console.log('User info:', result.user.username);
|
|
47
47
|
* } catch (error) {
|
|
48
48
|
* console.error('Failed to get user:', error.message);
|
|
@@ -53,7 +53,7 @@ export declare function getUserById(userId?: string, options?: GetUserRequest &
|
|
|
53
53
|
/**
|
|
54
54
|
* Deletes a user by ID or open ID.
|
|
55
55
|
*
|
|
56
|
-
* @param userId - User ID (
|
|
56
|
+
* @param userId - User ID (openId) to delete
|
|
57
57
|
* @param options - Optional configuration for the request
|
|
58
58
|
* @returns Promise resolving to the deletion result
|
|
59
59
|
* @throws {ConfigurationError} When required environment variables are missing
|
|
@@ -65,7 +65,7 @@ export declare function getUserById(userId?: string, options?: GetUserRequest &
|
|
|
65
65
|
* import { deleteUser } from '@tale/client';
|
|
66
66
|
*
|
|
67
67
|
* try {
|
|
68
|
-
* const result = await deleteUser('
|
|
68
|
+
* const result = await deleteUser('userOpenId_here');
|
|
69
69
|
* console.log('User deleted:', result.deleted);
|
|
70
70
|
* } catch (error) {
|
|
71
71
|
* console.error('Failed to delete user:', error.message);
|
|
@@ -91,10 +91,9 @@ export declare function deleteUser(userId: string, options?: CommonOptions): Pro
|
|
|
91
91
|
* page: 0,
|
|
92
92
|
* size: 20,
|
|
93
93
|
* keyword: 'john',
|
|
94
|
-
*
|
|
95
|
-
* sort_direction: 'asc'
|
|
94
|
+
* sort: 'username,asc'
|
|
96
95
|
* });
|
|
97
|
-
* console.log(`Found ${result.
|
|
96
|
+
* console.log(`Found ${result.total} users`);
|
|
98
97
|
* console.log('First user:', result.content[0].user.username);
|
|
99
98
|
* } catch (error) {
|
|
100
99
|
* console.error('Failed to list users:', error.message);
|
|
@@ -105,7 +104,7 @@ export declare function listUsers(options?: ListUsersRequest & CommonOptions): P
|
|
|
105
104
|
/**
|
|
106
105
|
* Updates user information by user ID or open ID.
|
|
107
106
|
*
|
|
108
|
-
* @param userId - User ID (
|
|
107
|
+
* @param userId - User ID (openId) to update
|
|
109
108
|
* @param userData - User data to update
|
|
110
109
|
* @param options - Optional configuration for the request
|
|
111
110
|
* @returns Promise resolving to the update result
|
|
@@ -118,8 +117,8 @@ export declare function listUsers(options?: ListUsersRequest & CommonOptions): P
|
|
|
118
117
|
* import { updateUser } from '@tale/client';
|
|
119
118
|
*
|
|
120
119
|
* try {
|
|
121
|
-
* const result = await updateUser('
|
|
122
|
-
*
|
|
120
|
+
* const result = await updateUser('userOpenId_here', {
|
|
121
|
+
* nickName: 'John Doe',
|
|
123
122
|
* email: 'john@example.com'
|
|
124
123
|
* });
|
|
125
124
|
* console.log('User updated:', result.success);
|
|
@@ -132,7 +131,7 @@ export declare function updateUser(userId: string, userData: UpdateUserRequest,
|
|
|
132
131
|
/**
|
|
133
132
|
* Updates user password.
|
|
134
133
|
*
|
|
135
|
-
* @param passwordData - Password data including
|
|
134
|
+
* @param passwordData - Password data including userId and encrypted password
|
|
136
135
|
* @param options - Optional configuration for the request
|
|
137
136
|
* @returns Promise resolving to the update result
|
|
138
137
|
* @throws {ConfigurationError} When required environment variables are missing
|
|
@@ -145,8 +144,8 @@ export declare function updateUser(userId: string, userData: UpdateUserRequest,
|
|
|
145
144
|
*
|
|
146
145
|
* try {
|
|
147
146
|
* const result = await updateUserPassword({
|
|
148
|
-
*
|
|
149
|
-
*
|
|
147
|
+
* userId: 'userOpenId_here',
|
|
148
|
+
* passwordEncrypted: 'encrypted_password_here'
|
|
150
149
|
* });
|
|
151
150
|
* console.log('Password updated:', result.success);
|
|
152
151
|
* } catch (error) {
|
|
@@ -159,7 +158,7 @@ export declare function updateUserPassword(passwordData: UpdateUserPasswordReque
|
|
|
159
158
|
* Uploads user avatar image.
|
|
160
159
|
*
|
|
161
160
|
* @param file - File object to upload as avatar
|
|
162
|
-
* @param userId - User ID (
|
|
161
|
+
* @param userId - User ID (openId) of the user
|
|
163
162
|
* @param options - Optional configuration for the request
|
|
164
163
|
* @returns Promise resolving to the upload result with avatar OSS key
|
|
165
164
|
* @throws {ConfigurationError} When required environment variables are missing
|
|
@@ -173,8 +172,8 @@ export declare function updateUserPassword(passwordData: UpdateUserPasswordReque
|
|
|
173
172
|
* try {
|
|
174
173
|
* const fileInput = document.querySelector('input[type="file"]');
|
|
175
174
|
* const file = fileInput.files[0];
|
|
176
|
-
* const result = await uploadAvatar(file, '
|
|
177
|
-
* console.log('Avatar uploaded:', result.
|
|
175
|
+
* const result = await uploadAvatar(file, 'userOpenId_here');
|
|
176
|
+
* console.log('Avatar uploaded:', result.avatarOssKey);
|
|
178
177
|
* } catch (error) {
|
|
179
178
|
* console.error('Failed to upload avatar:', error.message);
|
|
180
179
|
* }
|
|
@@ -208,8 +207,8 @@ export declare function getAvatarPresignedUrl(ossKey: string, options?: CommonOp
|
|
|
208
207
|
/**
|
|
209
208
|
* Updates user frozen status (freeze or unfreeze a user account).
|
|
210
209
|
*
|
|
211
|
-
* @param userId - User ID (
|
|
212
|
-
* @param frozenData - Frozen status data including
|
|
210
|
+
* @param userId - User ID (openId) to update frozen status
|
|
211
|
+
* @param frozenData - Frozen status data including isFrozen flag and optional remark
|
|
213
212
|
* @param options - Optional configuration for the request
|
|
214
213
|
* @returns Promise resolving to the updated frozen status information
|
|
215
214
|
* @throws {ConfigurationError} When required environment variables are missing
|
|
@@ -222,18 +221,18 @@ export declare function getAvatarPresignedUrl(ossKey: string, options?: CommonOp
|
|
|
222
221
|
*
|
|
223
222
|
* try {
|
|
224
223
|
* // Freeze a user account
|
|
225
|
-
* const result = await updateUserFrozenStatus('
|
|
226
|
-
*
|
|
224
|
+
* const result = await updateUserFrozenStatus('userOpenId_here', {
|
|
225
|
+
* isFrozen: true,
|
|
227
226
|
* remark: 'Violated community guidelines'
|
|
228
227
|
* });
|
|
229
|
-
* console.log('User frozen:', result.
|
|
228
|
+
* console.log('User frozen:', result.isFrozen);
|
|
230
229
|
*
|
|
231
230
|
* // Unfreeze a user account
|
|
232
|
-
* const unfrozenResult = await updateUserFrozenStatus('
|
|
233
|
-
*
|
|
231
|
+
* const unfrozenResult = await updateUserFrozenStatus('userOpenId_here', {
|
|
232
|
+
* isFrozen: false,
|
|
234
233
|
* remark: 'Account reactivated'
|
|
235
234
|
* });
|
|
236
|
-
* console.log('User unfrozen:', !unfrozenResult.
|
|
235
|
+
* console.log('User unfrozen:', !unfrozenResult.isFrozen);
|
|
237
236
|
* } catch (error) {
|
|
238
237
|
* console.error('Failed to update frozen status:', error.message);
|
|
239
238
|
* }
|
|
@@ -243,7 +242,7 @@ export declare function updateUserFrozenStatus(userId: string, frozenData: Updat
|
|
|
243
242
|
/**
|
|
244
243
|
* Gets user frozen status by user ID.
|
|
245
244
|
*
|
|
246
|
-
* @param userId - User ID (
|
|
245
|
+
* @param userId - User ID (openId) to query frozen status
|
|
247
246
|
* @param options - Optional configuration for the request
|
|
248
247
|
* @returns Promise resolving to the user frozen status information
|
|
249
248
|
* @throws {ConfigurationError} When required environment variables are missing
|
|
@@ -255,10 +254,10 @@ export declare function updateUserFrozenStatus(userId: string, frozenData: Updat
|
|
|
255
254
|
* import { getUserFrozenStatus } from '@tale/client';
|
|
256
255
|
*
|
|
257
256
|
* try {
|
|
258
|
-
* const status = await getUserFrozenStatus('
|
|
259
|
-
* console.log('User is frozen:', status.
|
|
257
|
+
* const status = await getUserFrozenStatus('userOpenId_here');
|
|
258
|
+
* console.log('User is frozen:', status.isFrozen);
|
|
260
259
|
* console.log('Remark:', status.remark);
|
|
261
|
-
* console.log('Last updated:', status.
|
|
260
|
+
* console.log('Last updated:', status.updatedAt);
|
|
262
261
|
* } catch (error) {
|
|
263
262
|
* console.error('Failed to get frozen status:', error.message);
|
|
264
263
|
* }
|