@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.
Files changed (56) hide show
  1. package/README.md +90 -13
  2. package/dist/acl/index.d.ts +62 -49
  3. package/dist/acl/index.js +262 -67
  4. package/dist/acl/types.d.ts +63 -98
  5. package/dist/app/index.d.ts +10 -0
  6. package/dist/app/index.js +198 -0
  7. package/dist/app/types.d.ts +101 -0
  8. package/dist/app/types.js +1 -0
  9. package/dist/app-token/index.d.ts +7 -0
  10. package/dist/app-token/index.js +58 -0
  11. package/dist/app-token/types.d.ts +25 -0
  12. package/dist/app-token/types.js +1 -0
  13. package/dist/attachment/index.d.ts +17 -0
  14. package/dist/attachment/index.js +247 -0
  15. package/dist/attachment/types.d.ts +82 -0
  16. package/dist/attachment/types.js +1 -0
  17. package/dist/attachment-type/index.d.ts +15 -0
  18. package/dist/attachment-type/index.js +203 -0
  19. package/dist/attachment-type/types.d.ts +60 -0
  20. package/dist/attachment-type/types.js +1 -0
  21. package/dist/auth/index.d.ts +21 -21
  22. package/dist/auth/index.js +66 -66
  23. package/dist/auth/types.d.ts +51 -51
  24. package/dist/cms/file.d.ts +88 -70
  25. package/dist/cms/file.js +228 -77
  26. package/dist/cms/folder.d.ts +9 -9
  27. package/dist/cms/folder.js +18 -18
  28. package/dist/cms/types.d.ts +58 -38
  29. package/dist/common/http.d.ts +17 -0
  30. package/dist/common/http.js +141 -0
  31. package/dist/common/types.d.ts +58 -63
  32. package/dist/index.d.ts +6 -1
  33. package/dist/index.js +4 -0
  34. package/dist/rbac/index.d.ts +37 -42
  35. package/dist/rbac/index.js +96 -98
  36. package/dist/rbac/types.d.ts +38 -40
  37. package/dist/status.d.ts +11 -11
  38. package/dist/status.js +30 -3
  39. package/dist/task/index.d.ts +15 -147
  40. package/dist/task/index.js +170 -161
  41. package/dist/task/types.d.ts +57 -81
  42. package/dist/task-type/index.d.ts +7 -7
  43. package/dist/task-type/index.js +12 -12
  44. package/dist/task-type/types.d.ts +18 -34
  45. package/dist/token.d.ts +3 -3
  46. package/dist/token.js +4 -4
  47. package/dist/user/index.d.ts +28 -29
  48. package/dist/user/index.js +69 -74
  49. package/dist/user/types.d.ts +32 -33
  50. package/dist/user-attribute/index.d.ts +4 -7
  51. package/dist/user-attribute/index.js +19 -22
  52. package/dist/user-attribute/types.d.ts +29 -29
  53. package/dist/user-group/index.d.ts +4 -223
  54. package/dist/user-group/index.js +61 -479
  55. package/dist/user-group/types.d.ts +1 -1
  56. package/package.json +1 -1
@@ -1,142 +1,107 @@
1
1
  import type { CommonOptions } from "../common/types.js";
2
- /**
3
- * ACL Record (Access Control List Record)
4
- * Represents a single access control rule
5
- */
6
2
  export interface AclRecord {
7
- record_id: string;
8
- app_id: string;
9
- template_id?: string;
10
- subject_type: string;
11
- subject_id?: string;
12
- subject_identifier?: string;
13
- resource_type: string;
14
- resource_id?: string;
15
- resource_identifier?: string;
16
- effect_type: string;
3
+ recordId: string;
4
+ appId: string;
5
+ templateId?: string;
6
+ subjectType: string;
7
+ subjectId?: string;
8
+ subjectIdentifier?: string;
9
+ resourceType: string;
10
+ resourceId?: string;
11
+ resourceIdentifier?: string;
12
+ effectType: string;
17
13
  priority?: number;
18
- data_scope?: Record<string, unknown>;
14
+ dataScope?: Record<string, unknown>;
19
15
  description?: string;
20
- created_at: string;
21
- updated_at: string;
16
+ createdAt: string;
17
+ updatedAt: string;
22
18
  }
23
- /**
24
- * Request for creating an ACL record
25
- */
26
19
  export interface CreateAclRecordRequest {
27
- template_id?: string;
28
- subject_type: string;
29
- subject_id?: string;
30
- subject_identifier?: string;
31
- resource_type: string;
32
- resource_id?: string;
33
- resource_identifier?: string;
34
- effect_type: string;
20
+ templateId?: string;
21
+ subjectType: string;
22
+ subjectId?: string;
23
+ subjectIdentifier?: string;
24
+ resourceType: string;
25
+ resourceId?: string;
26
+ resourceIdentifier?: string;
27
+ effectType: string;
35
28
  priority?: number;
36
- data_scope?: Record<string, unknown>;
29
+ dataScope?: Record<string, unknown>;
37
30
  description?: string;
38
31
  }
39
- /**
40
- * Request for updating an ACL record
41
- */
42
32
  export interface UpdateAclRecordRequest {
43
- template_id?: string;
44
- effect_type?: string;
33
+ templateId?: string;
34
+ effectType?: string;
45
35
  priority?: number;
46
- data_scope?: Record<string, unknown>;
36
+ dataScope?: Record<string, unknown>;
47
37
  description?: string;
48
38
  }
49
- /**
50
- * Request for listing ACL records
51
- */
52
39
  export interface ListAclRecordsRequest {
53
40
  page?: number;
54
41
  size?: number;
55
42
  sort?: string;
56
- template_id?: string;
57
- subject_type?: string;
58
- subject_id?: string;
59
- subject_identifier?: string;
60
- resource_type?: string;
61
- resource_id?: string;
62
- resource_identifier?: string;
43
+ templateId?: string;
44
+ subjectType?: string;
45
+ subjectId?: string;
46
+ subjectIdentifier?: string;
47
+ resourceType?: string;
48
+ resourceId?: string;
49
+ resourceIdentifier?: string;
63
50
  }
64
- /**
65
- * Batch creation response for ACL records
66
- */
67
51
  export interface AclBatchCreateResponse {
68
- success_count: number;
69
- failure_count: number;
70
- success_records: AclRecord[];
52
+ successCount: number;
53
+ failureCount: number;
54
+ successRecords: AclRecord[];
71
55
  failures: AclBatchFailure[];
72
56
  }
73
- /**
74
- * Failure details for batch creation
75
- */
76
57
  export interface AclBatchFailure {
77
58
  index: number;
78
59
  request: CreateAclRecordRequest;
79
- error_message: string;
60
+ errorMessage: string;
80
61
  }
81
- /**
82
- * ACL Template
83
- * Represents a reusable ACL configuration template
84
- */
85
62
  export interface AclTemplate {
86
- template_id: string;
87
- app_id: string;
88
- template_name: string;
89
- template_code: string;
90
- subject_type?: string;
91
- subject_filter?: Record<string, unknown>;
92
- resource_type?: string;
93
- resource_filter?: Record<string, unknown>;
94
- effect_type?: string;
63
+ templateId: string;
64
+ appId: string;
65
+ templateName: string;
66
+ templateCode: string;
67
+ subjectType?: string;
68
+ subjectFilter?: Record<string, unknown>;
69
+ resourceType?: string;
70
+ resourceFilter?: Record<string, unknown>;
71
+ effectType?: string;
95
72
  priority?: number;
96
- data_scope?: Record<string, unknown>;
73
+ dataScope?: Record<string, unknown>;
97
74
  description?: string;
98
- created_at: string;
99
- updated_at: string;
75
+ createdAt: string;
76
+ updatedAt: string;
100
77
  }
101
- /**
102
- * Request for creating an ACL template
103
- */
104
78
  export interface CreateAclTemplateRequest {
105
- template_name: string;
106
- template_code: string;
107
- subject_type?: string;
108
- subject_filter?: Record<string, unknown>;
109
- resource_type?: string;
110
- resource_filter?: Record<string, unknown>;
111
- effect_type?: string;
79
+ templateName: string;
80
+ templateCode: string;
81
+ subjectType?: string;
82
+ subjectFilter?: Record<string, unknown>;
83
+ resourceType?: string;
84
+ resourceFilter?: Record<string, unknown>;
85
+ effectType?: string;
112
86
  priority?: number;
113
- data_scope?: Record<string, unknown>;
87
+ dataScope?: Record<string, unknown>;
114
88
  description?: string;
115
89
  }
116
- /**
117
- * Request for updating an ACL template
118
- */
119
90
  export interface UpdateAclTemplateRequest {
120
- template_name?: string;
121
- subject_filter?: Record<string, unknown>;
122
- resource_filter?: Record<string, unknown>;
123
- effect_type?: string;
91
+ templateName?: string;
92
+ subjectFilter?: Record<string, unknown>;
93
+ resourceFilter?: Record<string, unknown>;
94
+ effectType?: string;
124
95
  priority?: number;
125
- data_scope?: Record<string, unknown>;
96
+ dataScope?: Record<string, unknown>;
126
97
  description?: string;
127
98
  }
128
- /**
129
- * Request for listing ACL templates
130
- */
131
99
  export interface ListAclTemplatesRequest {
132
100
  page?: number;
133
101
  size?: number;
134
102
  sort?: string;
135
- resource_type?: string;
136
- subject_type?: string;
103
+ resourceType?: string;
104
+ subjectType?: string;
137
105
  }
138
- /**
139
- * Options for ACL operations
140
- */
141
106
  export interface AclOptions extends CommonOptions {
142
107
  }
@@ -0,0 +1,10 @@
1
+ import type { AppDetail, AppInfo, AppUserLike, CommonOptions, CreateAppRequest, CreateAppResponse, CurrentAppUser, UpdateAppRequest } from "./types.js";
2
+ export type { AppDetail, AppDetailResponse, AppInfo, AppPrivilege, AppRole, AppUserLike, CommonOptions, CreateAppRequest, CreateAppResponse, CurrentAppUser, UpdateAppRequest, } from "./types.js";
3
+ export declare function normalizeAppInfo(value: unknown): AppInfo;
4
+ export declare function normalizeAppDetail(value: unknown): AppDetail;
5
+ export declare function normalizeCurrentAppUser(value: unknown): CurrentAppUser;
6
+ export declare function getCurrentUser(options?: CommonOptions): Promise<AppUserLike>;
7
+ export declare function listAppsByOrg(orgId: string, options?: CommonOptions): Promise<AppInfo[]>;
8
+ export declare function createApp(request: CreateAppRequest, options?: CommonOptions): Promise<CreateAppResponse>;
9
+ export declare function getAppDetail(appKey: string, options?: CommonOptions): Promise<AppDetail>;
10
+ export declare function updateApp(request: UpdateAppRequest, options?: CommonOptions): Promise<AppDetail>;
@@ -0,0 +1,198 @@
1
+ import { assertRequiredString, pickBoolean, pickString, requestJson, toRecord, } from "../common/http.js";
2
+ function normalizeRole(value) {
3
+ const role = toRecord(value);
4
+ return {
5
+ roleId: pickString(role.roleId),
6
+ roleName: pickString(role.roleName),
7
+ roleType: pickString(role.roleType) || undefined,
8
+ roleProperty: toRecord(role.roleProperty),
9
+ roleConfig: toRecord(role.roleConfig),
10
+ rolePrivileges: Array.isArray(role.rolePrivileges)
11
+ ? role.rolePrivileges.map(normalizePrivilege)
12
+ : undefined,
13
+ privilegeIds: Array.isArray(role.privilegeIds)
14
+ ? role.privilegeIds.map(String)
15
+ : undefined,
16
+ resourceIds: Array.isArray(role.resourceIds)
17
+ ? role.resourceIds.map(String)
18
+ : undefined,
19
+ expiredAt: pickString(role.expiredAt) || undefined,
20
+ remark: pickString(role.remark) || undefined,
21
+ };
22
+ }
23
+ function normalizePrivilege(value) {
24
+ const privilege = toRecord(value);
25
+ return {
26
+ privilegeId: pickString(privilege.privilegeId),
27
+ privilegeName: pickString(privilege.privilegeName),
28
+ privilegeType: pickString(privilege.privilegeType) || undefined,
29
+ privilegeProperty: toRecord(privilege.privilegeProperty),
30
+ privilegeConfig: toRecord(privilege.privilegeConfig),
31
+ resourceIds: Array.isArray(privilege.resourceIds)
32
+ ? privilege.resourceIds.map(String)
33
+ : undefined,
34
+ expiredAt: pickString(privilege.expiredAt) || undefined,
35
+ remark: pickString(privilege.remark) || undefined,
36
+ };
37
+ }
38
+ function normalizeUserGroup(value) {
39
+ const group = toRecord(value);
40
+ return {
41
+ groupId: pickString(group.groupId),
42
+ name: pickString(group.name, group.groupName),
43
+ description: pickString(group.description) || undefined,
44
+ type: pickString(group.type) || undefined,
45
+ remark: pickString(group.remark) || undefined,
46
+ };
47
+ }
48
+ export function normalizeAppInfo(value) {
49
+ const app = toRecord(value);
50
+ const appKey = pickString(app.appKey);
51
+ const appName = pickString(app.appName, app.name);
52
+ const appId = pickString(app.appId, app.id);
53
+ return {
54
+ appId,
55
+ appKey,
56
+ appName,
57
+ id: pickString(app.id, appId, appKey),
58
+ name: pickString(app.name, appName, appKey),
59
+ description: pickString(app.description, app.remark) || undefined,
60
+ icon: pickString(app.icon) || undefined,
61
+ plan: pickString(app.plan) || undefined,
62
+ orgId: pickString(app.orgId) || undefined,
63
+ appProperty: toRecord(app.appProperty),
64
+ appConfig: toRecord(app.appConfig),
65
+ appAdmins: toRecord(app.appAdmins),
66
+ roleConfig: toRecord(app.roleConfig),
67
+ userGroupConfig: toRecord(app.userGroupConfig),
68
+ createdAt: pickString(app.createdAt) || undefined,
69
+ updatedAt: pickString(app.updatedAt) || undefined,
70
+ remark: pickString(app.remark) || undefined,
71
+ };
72
+ }
73
+ function normalizeAppRole(value) {
74
+ return normalizeRole(value);
75
+ }
76
+ function normalizeAppPrivilege(value) {
77
+ return normalizePrivilege(value);
78
+ }
79
+ export function normalizeAppDetail(value) {
80
+ const app = toRecord(value);
81
+ const info = normalizeAppInfo(app);
82
+ return {
83
+ ...info,
84
+ appRoles: Array.isArray(app.appRoles)
85
+ ? app.appRoles.map(normalizeAppRole)
86
+ : [],
87
+ appPrivileges: Array.isArray(app.appPrivileges)
88
+ ? app.appPrivileges.map(normalizeAppPrivilege)
89
+ : [],
90
+ wechatConfig: toRecord(app.wechatConfig),
91
+ feishuConfig: toRecord(app.feishuConfig),
92
+ openaiConfig: toRecord(app.openaiConfig),
93
+ };
94
+ }
95
+ export function normalizeCurrentAppUser(value) {
96
+ const payload = toRecord(value);
97
+ const app = toRecord(payload.app);
98
+ const user = toRecord(payload.user);
99
+ return {
100
+ app: {
101
+ appName: pickString(app.appName),
102
+ appKey: pickString(app.appKey),
103
+ orgId: pickString(app.orgId, payload.orgId),
104
+ appId: pickString(app.appId),
105
+ },
106
+ user: {
107
+ latestLoginTime: pickString(user.latestLoginTime) || undefined,
108
+ registeredAt: pickString(user.registeredAt) || undefined,
109
+ isFrozen: pickBoolean(user.isFrozen),
110
+ userId: pickString(user.userId, payload.userId),
111
+ phone: pickString(user.phone) || undefined,
112
+ username: pickString(user.username) || undefined,
113
+ email: pickString(user.email) || undefined,
114
+ nickname: pickString(user.nickname) || undefined,
115
+ remark: pickString(user.remark) || undefined,
116
+ avatarUrl: pickString(user.avatarUrl) || undefined,
117
+ },
118
+ thirdParty: toRecord(payload.thirdParty),
119
+ userRoles: Array.isArray(payload.userRoles)
120
+ ? payload.userRoles.map(normalizeRole)
121
+ : [],
122
+ userPrivileges: Array.isArray(payload.userPrivileges)
123
+ ? payload.userPrivileges.map(normalizePrivilege)
124
+ : [],
125
+ userGroups: Array.isArray(payload.userGroups)
126
+ ? payload.userGroups.map(normalizeUserGroup)
127
+ : [],
128
+ };
129
+ }
130
+ function normalizeCreateAppResponse(value) {
131
+ const app = toRecord(value);
132
+ return {
133
+ appId: pickString(app.appId, app.id),
134
+ appName: pickString(app.appName, app.name),
135
+ orgId: pickString(app.orgId),
136
+ appKey: pickString(app.appKey),
137
+ createdAt: pickString(app.createdAt) || undefined,
138
+ };
139
+ }
140
+ function toUpdateAppPayload(request) {
141
+ return {
142
+ appId: request.appId,
143
+ appName: request.appName,
144
+ remark: request.remark,
145
+ appProperty: request.appProperty,
146
+ appConfig: request.appConfig,
147
+ wechatConfig: request.wechatConfig,
148
+ appAdmins: request.appAdmins,
149
+ roleConfig: request.roleConfig,
150
+ userGroupConfig: request.userGroupConfig,
151
+ feishuConfig: request.feishuConfig,
152
+ openaiConfig: request.openaiConfig,
153
+ };
154
+ }
155
+ export async function getCurrentUser(options) {
156
+ const payload = await requestJson("/account/v2/user", options, {
157
+ authMode: "taleToken",
158
+ errorMessage: "Failed to get current user",
159
+ });
160
+ return normalizeCurrentAppUser(payload);
161
+ }
162
+ export async function listAppsByOrg(orgId, options) {
163
+ assertRequiredString(orgId, "orgId");
164
+ const payload = await requestJson(`/app/v2/org/${encodeURIComponent(orgId)}/apps`, options, {
165
+ authMode: "taleToken",
166
+ errorMessage: "Failed to list apps",
167
+ });
168
+ return Array.isArray(payload) ? payload.map(normalizeAppInfo) : [];
169
+ }
170
+ export async function createApp(request, options) {
171
+ assertRequiredString(request?.appName, "appName");
172
+ assertRequiredString(request?.orgId, "orgId");
173
+ const payload = await requestJson("/app/v2/app", options, {
174
+ method: "POST",
175
+ body: request,
176
+ authMode: "taleToken",
177
+ errorMessage: "Failed to create app",
178
+ });
179
+ return normalizeCreateAppResponse(payload);
180
+ }
181
+ export async function getAppDetail(appKey, options) {
182
+ assertRequiredString(appKey, "appKey");
183
+ const payload = await requestJson(`/app/v2/app/${encodeURIComponent(appKey)}`, options, {
184
+ authMode: "taleToken",
185
+ errorMessage: "Failed to get app detail",
186
+ });
187
+ return normalizeAppDetail(payload);
188
+ }
189
+ export async function updateApp(request, options) {
190
+ assertRequiredString(request?.appId, "appId");
191
+ const payload = await requestJson("/app/v2/app", options, {
192
+ method: "PUT",
193
+ body: toUpdateAppPayload(request),
194
+ authMode: "taleToken",
195
+ errorMessage: "Failed to update app",
196
+ });
197
+ return normalizeAppDetail(payload);
198
+ }
@@ -0,0 +1,101 @@
1
+ import type { CommonOptions, Privilege, Role, UserGroup } from "../common/types.js";
2
+ export type { CommonOptions, Privilege, Role, UserGroup };
3
+ export interface AppInfo {
4
+ appId: string;
5
+ appKey: string;
6
+ appName: string;
7
+ id: string;
8
+ name: string;
9
+ description?: string;
10
+ icon?: string;
11
+ plan?: string;
12
+ orgId?: string;
13
+ appProperty?: Record<string, unknown>;
14
+ appConfig?: Record<string, unknown>;
15
+ appAdmins?: Record<string, unknown>;
16
+ roleConfig?: Record<string, unknown>;
17
+ userGroupConfig?: Record<string, unknown>;
18
+ createdAt?: string;
19
+ updatedAt?: string;
20
+ remark?: string;
21
+ }
22
+ export interface CreateAppRequest {
23
+ appName: string;
24
+ orgId: string;
25
+ remark?: string;
26
+ }
27
+ export interface CreateAppResponse {
28
+ appId: string;
29
+ appName: string;
30
+ orgId: string;
31
+ appKey: string;
32
+ createdAt?: string;
33
+ }
34
+ export interface UpdateAppRequest {
35
+ appId: string;
36
+ appName?: string;
37
+ remark?: string;
38
+ appProperty?: Record<string, unknown>;
39
+ appConfig?: Record<string, unknown>;
40
+ wechatConfig?: Record<string, unknown>;
41
+ appAdmins?: Record<string, unknown>;
42
+ roleConfig?: Record<string, unknown>;
43
+ userGroupConfig?: Record<string, unknown>;
44
+ feishuConfig?: Record<string, unknown>;
45
+ openaiConfig?: Record<string, unknown>;
46
+ }
47
+ export interface AppRole {
48
+ roleId: string;
49
+ roleName: string;
50
+ roleType?: string;
51
+ roleProperty?: Record<string, unknown>;
52
+ roleConfig?: Record<string, unknown>;
53
+ expiredAt?: string;
54
+ remark?: string;
55
+ }
56
+ export interface AppPrivilege {
57
+ privilegeId: string;
58
+ privilegeName: string;
59
+ privilegeType?: string;
60
+ privilegeProperty?: Record<string, unknown>;
61
+ privilegeConfig?: Record<string, unknown>;
62
+ expiredAt?: string;
63
+ remark?: string;
64
+ }
65
+ export interface AppDetail extends AppInfo {
66
+ appRoles: AppRole[];
67
+ appPrivileges: AppPrivilege[];
68
+ wechatConfig?: Record<string, unknown>;
69
+ feishuConfig?: Record<string, unknown>;
70
+ openaiConfig?: Record<string, unknown>;
71
+ }
72
+ export interface AppDetailResponse {
73
+ data: AppDetail;
74
+ code: number;
75
+ msg: string;
76
+ }
77
+ export interface CurrentAppUser {
78
+ app: {
79
+ appName: string;
80
+ appKey: string;
81
+ orgId: string;
82
+ appId: string;
83
+ };
84
+ user: {
85
+ latestLoginTime?: string;
86
+ registeredAt?: string;
87
+ isFrozen?: boolean;
88
+ userId: string;
89
+ phone?: string;
90
+ username?: string;
91
+ email?: string;
92
+ nickname?: string;
93
+ remark?: string;
94
+ avatarUrl?: string;
95
+ };
96
+ thirdParty: Record<string, unknown>;
97
+ userRoles: Role[];
98
+ userPrivileges: Privilege[];
99
+ userGroups: UserGroup[];
100
+ }
101
+ export type AppUserLike = CurrentAppUser;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { PageResponse } from "../common/types.js";
2
+ import type { AppToken, CommonOptions, IssueAppTokenRequest, IssueAppTokenResponse, ListAppTokensRequest } from "./types.js";
3
+ export type { AppSecretResponse, AppToken, CommonOptions, IssueAppTokenRequest, IssueAppTokenResponse, ListAppTokensRequest, PageResponse, } from "./types.js";
4
+ export declare function normalizeAppToken(value: unknown): AppToken;
5
+ export declare function listAppTokens(request?: ListAppTokensRequest & CommonOptions): Promise<PageResponse<AppToken>>;
6
+ export declare function getAppSecret(appKey: string, options?: CommonOptions): Promise<string>;
7
+ export declare function issueAppToken(request: IssueAppTokenRequest): Promise<IssueAppTokenResponse>;
@@ -0,0 +1,58 @@
1
+ import { assertRequiredString, normalizePageResponse, pickString, requestJson, toRecord, } from "../common/http.js";
2
+ export function normalizeAppToken(value) {
3
+ const token = toRecord(value);
4
+ return {
5
+ type: pickString(token.type),
6
+ appKey: pickString(token.appKey),
7
+ token: pickString(token.token),
8
+ status: pickString(token.status),
9
+ expiredAt: pickString(token.expiredAt),
10
+ };
11
+ }
12
+ function toListQuery(request) {
13
+ if (!request) {
14
+ return undefined;
15
+ }
16
+ const sortProperty = request.sort === "expiredAt" ? "expiredTime" : request.sort;
17
+ const sort = sortProperty && request.sortDirection
18
+ ? `${sortProperty},${request.sortDirection}`
19
+ : sortProperty;
20
+ return {
21
+ page: request.page,
22
+ size: request.size,
23
+ isValid: request.isValid,
24
+ sort,
25
+ search: request.search,
26
+ };
27
+ }
28
+ export async function listAppTokens(request) {
29
+ const { appToken, taleToken, baseUrl, ...listRequest } = request ?? {};
30
+ const payload = await requestJson("/app/v2/app/tokens", request, {
31
+ query: toListQuery(listRequest),
32
+ errorMessage: "Failed to list app tokens",
33
+ });
34
+ return normalizePageResponse(payload, normalizeAppToken);
35
+ }
36
+ export async function getAppSecret(appKey, options) {
37
+ assertRequiredString(appKey, "appKey");
38
+ const payload = await requestJson(`/app/v2/app/${encodeURIComponent(appKey)}/secret`, options, {
39
+ authMode: "taleToken",
40
+ errorMessage: "Failed to get app secret",
41
+ });
42
+ const response = toRecord(payload);
43
+ const appSecret = pickString(response.appSecret);
44
+ if (!appSecret) {
45
+ return pickString(payload);
46
+ }
47
+ return appSecret;
48
+ }
49
+ export async function issueAppToken(request) {
50
+ assertRequiredString(request?.appKey, "appKey");
51
+ const { appKey, ...options } = request;
52
+ const payload = await requestJson("/app/v2/token/by-appkey", options, {
53
+ query: { appKey },
54
+ authMode: "taleToken",
55
+ errorMessage: "Failed to issue app token",
56
+ });
57
+ return normalizeAppToken(payload);
58
+ }
@@ -0,0 +1,25 @@
1
+ import type { CommonOptions } from "../common/types.js";
2
+ export type { CommonOptions, PageResponse } from "../common/types.js";
3
+ export interface AppToken {
4
+ type: string;
5
+ appKey: string;
6
+ token: string;
7
+ status: string;
8
+ expiredAt: string;
9
+ }
10
+ export interface ListAppTokensRequest {
11
+ page?: number;
12
+ size?: number;
13
+ isValid?: boolean;
14
+ sort?: string;
15
+ sortDirection?: "asc" | "desc" | "ASC" | "DESC";
16
+ search?: string;
17
+ }
18
+ export interface AppSecretResponse {
19
+ appSecret: string;
20
+ }
21
+ export interface IssueAppTokenRequest extends CommonOptions {
22
+ appKey: string;
23
+ }
24
+ export interface IssueAppTokenResponse extends AppToken {
25
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ import type { PageResponse } from "../common/types.js";
2
+ import type { Attachment, ListAttachmentsByRefRequest, UploadAttachmentRequest, UploadAuthorizationRequest, UploadAuthorizationResponse, CompleteUploadRequest, DeleteAttachmentRequest, DownloadAttachmentUrlRequest, DownloadUrlResponse, AttachmentOptions } from "./types.js";
3
+ export type { AttachmentRefType, Attachment, ListAttachmentsByRefRequest, UploadAttachmentRequest, UploadAuthorizationRequest, UploadAuthorizationResponse, CompleteUploadRequest, DeleteAttachmentRequest, DownloadAttachmentUrlRequest, DownloadUrlResponse, AttachmentOptions, } from "./types.js";
4
+ /** Get attachment by ID */
5
+ export declare function getAttachment(attachmentId: string, options?: AttachmentOptions): Promise<Attachment>;
6
+ /** List attachments by reference */
7
+ export declare function listAttachmentsByRef(request: ListAttachmentsByRefRequest & AttachmentOptions): Promise<PageResponse<Attachment>>;
8
+ /** Upload attachment directly (multipart) */
9
+ export declare function uploadAttachment(request: UploadAttachmentRequest & AttachmentOptions): Promise<Attachment>;
10
+ /** Delete attachment */
11
+ export declare function deleteAttachment(request: DeleteAttachmentRequest & AttachmentOptions): Promise<void>;
12
+ /** Get upload URL for two-phase upload */
13
+ export declare function getAttachmentUploadUrl(request: UploadAuthorizationRequest & AttachmentOptions): Promise<UploadAuthorizationResponse>;
14
+ /** Complete two-phase upload */
15
+ export declare function completeAttachmentUpload(attachmentId: string, request: CompleteUploadRequest, options?: AttachmentOptions): Promise<Attachment>;
16
+ /** Get download URL */
17
+ export declare function getAttachmentDownloadUrl(request: DownloadAttachmentUrlRequest & AttachmentOptions): Promise<DownloadUrlResponse>;