@turinhub/tale-js-sdk 1.3.0 → 2.0.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 +6 -6
- 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/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/types.d.ts +47 -63
- package/dist/index.d.ts +4 -1
- package/dist/index.js +2 -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/acl/types.d.ts
CHANGED
|
@@ -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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
14
|
+
dataScope?: Record<string, unknown>;
|
|
19
15
|
description?: string;
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
createdAt: string;
|
|
17
|
+
updatedAt: string;
|
|
22
18
|
}
|
|
23
|
-
/**
|
|
24
|
-
* Request for creating an ACL record
|
|
25
|
-
*/
|
|
26
19
|
export interface CreateAclRecordRequest {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
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
|
-
|
|
44
|
-
|
|
33
|
+
templateId?: string;
|
|
34
|
+
effectType?: string;
|
|
45
35
|
priority?: number;
|
|
46
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
60
|
+
errorMessage: string;
|
|
80
61
|
}
|
|
81
|
-
/**
|
|
82
|
-
* ACL Template
|
|
83
|
-
* Represents a reusable ACL configuration template
|
|
84
|
-
*/
|
|
85
62
|
export interface AclTemplate {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
73
|
+
dataScope?: Record<string, unknown>;
|
|
97
74
|
description?: string;
|
|
98
|
-
|
|
99
|
-
|
|
75
|
+
createdAt: string;
|
|
76
|
+
updatedAt: string;
|
|
100
77
|
}
|
|
101
|
-
/**
|
|
102
|
-
* Request for creating an ACL template
|
|
103
|
-
*/
|
|
104
78
|
export interface CreateAclTemplateRequest {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
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
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
91
|
+
templateName?: string;
|
|
92
|
+
subjectFilter?: Record<string, unknown>;
|
|
93
|
+
resourceFilter?: Record<string, unknown>;
|
|
94
|
+
effectType?: string;
|
|
124
95
|
priority?: number;
|
|
125
|
-
|
|
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
|
-
|
|
136
|
-
|
|
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,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>;
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { getAppToken } from "../token.js";
|
|
2
|
+
import { ApiError, ConfigurationError, NetworkError } from "../errors.js";
|
|
3
|
+
function parseApiResponse(json, errorMessage, statusCode) {
|
|
4
|
+
if (typeof json !== "object" || json === null) {
|
|
5
|
+
throw new ApiError(`Invalid response: ${errorMessage} - not an object`, statusCode);
|
|
6
|
+
}
|
|
7
|
+
const response = json;
|
|
8
|
+
if (response.code !== 200) {
|
|
9
|
+
const errorMsg = typeof response.msg === "string" ? response.msg : errorMessage;
|
|
10
|
+
throw new ApiError(errorMsg, statusCode, response.code);
|
|
11
|
+
}
|
|
12
|
+
if (!response.data) {
|
|
13
|
+
throw new ApiError(`Invalid response: ${errorMessage} - missing data`, statusCode);
|
|
14
|
+
}
|
|
15
|
+
return response.data;
|
|
16
|
+
}
|
|
17
|
+
function assertRequiredString(value, fieldName) {
|
|
18
|
+
if (!value || value.trim() === "") {
|
|
19
|
+
throw new ApiError(`${fieldName} is required`, 400, "9400");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function getBaseUrl(options) {
|
|
23
|
+
const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
|
|
24
|
+
const base = options?.baseUrl ?? env?.TALE_BASE_URL ?? undefined;
|
|
25
|
+
if (!base) {
|
|
26
|
+
throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
|
|
27
|
+
}
|
|
28
|
+
return String(base).replace(/\/+$/, "");
|
|
29
|
+
}
|
|
30
|
+
/** Get attachment by ID */
|
|
31
|
+
export async function getAttachment(attachmentId, options) {
|
|
32
|
+
assertRequiredString(attachmentId, "attachmentId");
|
|
33
|
+
const token = options?.appToken ?? (await getAppToken(options));
|
|
34
|
+
const base = getBaseUrl(options);
|
|
35
|
+
const url = new URL(base + `/attachment/v2/attachments/${encodeURIComponent(attachmentId)}`);
|
|
36
|
+
let response;
|
|
37
|
+
try {
|
|
38
|
+
response = await globalThis.fetch(url.toString(), {
|
|
39
|
+
method: "GET",
|
|
40
|
+
headers: {
|
|
41
|
+
"Content-Type": "application/json",
|
|
42
|
+
"x-t-token": token,
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
throw new NetworkError(`Failed to get attachment: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
48
|
+
}
|
|
49
|
+
const json = await response.json();
|
|
50
|
+
return parseApiResponse(json, "Failed to get attachment", response.status);
|
|
51
|
+
}
|
|
52
|
+
/** List attachments by reference */
|
|
53
|
+
export async function listAttachmentsByRef(request) {
|
|
54
|
+
assertRequiredString(request?.refType, "refType");
|
|
55
|
+
assertRequiredString(request?.refId, "refId");
|
|
56
|
+
const token = request.appToken ?? (await getAppToken(request));
|
|
57
|
+
const base = getBaseUrl(request);
|
|
58
|
+
const url = new URL(base + "/attachment/v2/attachments/by-ref");
|
|
59
|
+
const { appToken, baseUrl, refType, refId, ...pagination } = request;
|
|
60
|
+
url.searchParams.append("refType", refType);
|
|
61
|
+
url.searchParams.append("refId", refId);
|
|
62
|
+
const queryParams = {
|
|
63
|
+
page: 0,
|
|
64
|
+
size: 20,
|
|
65
|
+
sort: "createdAt,desc",
|
|
66
|
+
...pagination,
|
|
67
|
+
};
|
|
68
|
+
Object.entries(queryParams).forEach(([key, value]) => {
|
|
69
|
+
if (value !== undefined) {
|
|
70
|
+
url.searchParams.append(key, String(value));
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
let response;
|
|
74
|
+
try {
|
|
75
|
+
response = await globalThis.fetch(url.toString(), {
|
|
76
|
+
method: "GET",
|
|
77
|
+
headers: {
|
|
78
|
+
"Content-Type": "application/json",
|
|
79
|
+
"x-t-token": token,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
throw new NetworkError(`Failed to list attachments: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
85
|
+
}
|
|
86
|
+
const json = await response.json();
|
|
87
|
+
return parseApiResponse(json, "Failed to list attachments", response.status);
|
|
88
|
+
}
|
|
89
|
+
/** Upload attachment directly (multipart) */
|
|
90
|
+
export async function uploadAttachment(request) {
|
|
91
|
+
assertRequiredString(request?.attachmentTypeId, "attachmentTypeId");
|
|
92
|
+
assertRequiredString(request?.refType, "refType");
|
|
93
|
+
assertRequiredString(request?.refId, "refId");
|
|
94
|
+
if (!request?.file) {
|
|
95
|
+
throw new ApiError("file is required", 400, "9400");
|
|
96
|
+
}
|
|
97
|
+
const { appToken, baseUrl, attachmentTypeId, refType, refId, file, remark } = request;
|
|
98
|
+
const token = appToken ?? (await getAppToken(request));
|
|
99
|
+
const base = getBaseUrl(request);
|
|
100
|
+
const url = new URL(base + "/attachment/v2/attachments");
|
|
101
|
+
const formData = new FormData();
|
|
102
|
+
formData.append("attachmentTypeId", attachmentTypeId);
|
|
103
|
+
formData.append("refType", refType);
|
|
104
|
+
formData.append("refId", refId);
|
|
105
|
+
if (remark) {
|
|
106
|
+
formData.append("remark", remark);
|
|
107
|
+
}
|
|
108
|
+
if (typeof File !== "undefined" && file instanceof File) {
|
|
109
|
+
formData.append("file", file, file.name);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
formData.append("file", file);
|
|
113
|
+
}
|
|
114
|
+
let response;
|
|
115
|
+
try {
|
|
116
|
+
response = await globalThis.fetch(url.toString(), {
|
|
117
|
+
method: "POST",
|
|
118
|
+
headers: {
|
|
119
|
+
"x-t-token": token,
|
|
120
|
+
},
|
|
121
|
+
body: formData,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
throw new NetworkError(`Failed to upload attachment: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
126
|
+
}
|
|
127
|
+
const json = await response.json();
|
|
128
|
+
return parseApiResponse(json, "Failed to upload attachment", response.status);
|
|
129
|
+
}
|
|
130
|
+
/** Delete attachment */
|
|
131
|
+
export async function deleteAttachment(request) {
|
|
132
|
+
assertRequiredString(request?.attachmentId, "attachmentId");
|
|
133
|
+
assertRequiredString(request?.refType, "refType");
|
|
134
|
+
assertRequiredString(request?.refId, "refId");
|
|
135
|
+
const { appToken, baseUrl, attachmentId, refType, refId } = request;
|
|
136
|
+
const token = appToken ?? (await getAppToken(request));
|
|
137
|
+
const base = getBaseUrl(request);
|
|
138
|
+
const url = new URL(base + `/attachment/v2/attachments/${encodeURIComponent(attachmentId)}`);
|
|
139
|
+
url.searchParams.append("refType", refType);
|
|
140
|
+
url.searchParams.append("refId", refId);
|
|
141
|
+
let response;
|
|
142
|
+
try {
|
|
143
|
+
response = await globalThis.fetch(url.toString(), {
|
|
144
|
+
method: "DELETE",
|
|
145
|
+
headers: {
|
|
146
|
+
"Content-Type": "application/json",
|
|
147
|
+
"x-t-token": token,
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
throw new NetworkError(`Failed to delete attachment: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
153
|
+
}
|
|
154
|
+
const json = (await response.json());
|
|
155
|
+
if (json.code !== 200) {
|
|
156
|
+
const errorMsg = typeof json.msg === "string" ? json.msg : "Failed to delete attachment";
|
|
157
|
+
throw new ApiError(errorMsg, response.status, json.code);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/** Get upload URL for two-phase upload */
|
|
161
|
+
export async function getAttachmentUploadUrl(request) {
|
|
162
|
+
assertRequiredString(request?.refType, "refType");
|
|
163
|
+
assertRequiredString(request?.attachmentTypeId, "attachmentTypeId");
|
|
164
|
+
assertRequiredString(request?.refId, "refId");
|
|
165
|
+
assertRequiredString(request?.fileName, "fileName");
|
|
166
|
+
assertRequiredString(request?.fileType, "fileType");
|
|
167
|
+
const { appToken, baseUrl, ...body } = request;
|
|
168
|
+
const token = appToken ?? (await getAppToken(request));
|
|
169
|
+
const base = getBaseUrl(request);
|
|
170
|
+
const url = new URL(base + "/attachment/v2/attachments/upload-url");
|
|
171
|
+
let response;
|
|
172
|
+
try {
|
|
173
|
+
response = await globalThis.fetch(url.toString(), {
|
|
174
|
+
method: "POST",
|
|
175
|
+
headers: {
|
|
176
|
+
"Content-Type": "application/json",
|
|
177
|
+
"x-t-token": token,
|
|
178
|
+
},
|
|
179
|
+
body: JSON.stringify(body),
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
throw new NetworkError(`Failed to get upload URL: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
184
|
+
}
|
|
185
|
+
const json = await response.json();
|
|
186
|
+
return parseApiResponse(json, "Failed to get upload URL", response.status);
|
|
187
|
+
}
|
|
188
|
+
/** Complete two-phase upload */
|
|
189
|
+
export async function completeAttachmentUpload(attachmentId, request, options) {
|
|
190
|
+
assertRequiredString(attachmentId, "attachmentId");
|
|
191
|
+
assertRequiredString(request?.refType, "refType");
|
|
192
|
+
assertRequiredString(request?.refId, "refId");
|
|
193
|
+
assertRequiredString(request?.ossKey, "ossKey");
|
|
194
|
+
if (!request || request.fileSize === undefined || request.fileSize === null) {
|
|
195
|
+
throw new ApiError("fileSize is required", 400, "9400");
|
|
196
|
+
}
|
|
197
|
+
assertRequiredString(request.etag, "etag");
|
|
198
|
+
const token = options?.appToken ?? (await getAppToken(options));
|
|
199
|
+
const base = getBaseUrl(options);
|
|
200
|
+
const url = new URL(base +
|
|
201
|
+
`/attachment/v2/attachments/${encodeURIComponent(attachmentId)}/complete`);
|
|
202
|
+
let response;
|
|
203
|
+
try {
|
|
204
|
+
response = await globalThis.fetch(url.toString(), {
|
|
205
|
+
method: "POST",
|
|
206
|
+
headers: {
|
|
207
|
+
"Content-Type": "application/json",
|
|
208
|
+
"x-t-token": token,
|
|
209
|
+
},
|
|
210
|
+
body: JSON.stringify(request),
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
throw new NetworkError(`Failed to complete upload: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
215
|
+
}
|
|
216
|
+
const json = await response.json();
|
|
217
|
+
return parseApiResponse(json, "Failed to complete upload", response.status);
|
|
218
|
+
}
|
|
219
|
+
/** Get download URL */
|
|
220
|
+
export async function getAttachmentDownloadUrl(request) {
|
|
221
|
+
assertRequiredString(request?.attachmentId, "attachmentId");
|
|
222
|
+
assertRequiredString(request?.refType, "refType");
|
|
223
|
+
assertRequiredString(request?.refId, "refId");
|
|
224
|
+
const { appToken, baseUrl, attachmentId, refType, refId, expiresInSeconds = 3600, } = request;
|
|
225
|
+
const token = appToken ?? (await getAppToken(request));
|
|
226
|
+
const base = getBaseUrl(request);
|
|
227
|
+
const url = new URL(base +
|
|
228
|
+
`/attachment/v2/attachments/${encodeURIComponent(attachmentId)}/download-url`);
|
|
229
|
+
url.searchParams.append("refType", refType);
|
|
230
|
+
url.searchParams.append("refId", refId);
|
|
231
|
+
url.searchParams.append("expiresInSeconds", String(expiresInSeconds));
|
|
232
|
+
let response;
|
|
233
|
+
try {
|
|
234
|
+
response = await globalThis.fetch(url.toString(), {
|
|
235
|
+
method: "GET",
|
|
236
|
+
headers: {
|
|
237
|
+
"Content-Type": "application/json",
|
|
238
|
+
"x-t-token": token,
|
|
239
|
+
},
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
catch (error) {
|
|
243
|
+
throw new NetworkError(`Failed to get download URL: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
244
|
+
}
|
|
245
|
+
const json = await response.json();
|
|
246
|
+
return parseApiResponse(json, "Failed to get download URL", response.status);
|
|
247
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { CommonOptions } from "../common/types.js";
|
|
2
|
+
/** Discriminator for the domain entity an attachment belongs to. */
|
|
3
|
+
export type AttachmentRefType = "task" | "cms_file" | "acl_record";
|
|
4
|
+
export interface Attachment {
|
|
5
|
+
attachmentId: string;
|
|
6
|
+
appId: string;
|
|
7
|
+
typeId: string;
|
|
8
|
+
refId: string;
|
|
9
|
+
refType: string;
|
|
10
|
+
fileName: string;
|
|
11
|
+
fileOriginalName: string;
|
|
12
|
+
fileExtension: string;
|
|
13
|
+
fileOssKey: string;
|
|
14
|
+
fileSize: number;
|
|
15
|
+
fileHash: string;
|
|
16
|
+
mimeType: string;
|
|
17
|
+
uploadStatus: string;
|
|
18
|
+
sortOrder: number;
|
|
19
|
+
remark?: string;
|
|
20
|
+
createdAt: string;
|
|
21
|
+
updatedAt: string;
|
|
22
|
+
}
|
|
23
|
+
export interface ListAttachmentsByRefRequest {
|
|
24
|
+
refType: AttachmentRefType;
|
|
25
|
+
refId: string;
|
|
26
|
+
page?: number;
|
|
27
|
+
size?: number;
|
|
28
|
+
sort?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface UploadAttachmentRequest {
|
|
31
|
+
attachmentTypeId: string;
|
|
32
|
+
refType: AttachmentRefType;
|
|
33
|
+
refId: string;
|
|
34
|
+
file: File | Blob;
|
|
35
|
+
remark?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface UploadAuthorizationRequest {
|
|
38
|
+
attachmentTypeId: string;
|
|
39
|
+
refType: AttachmentRefType;
|
|
40
|
+
refId: string;
|
|
41
|
+
fileName: string;
|
|
42
|
+
fileType: string;
|
|
43
|
+
mimeType?: string;
|
|
44
|
+
fileSize?: number;
|
|
45
|
+
remark?: string;
|
|
46
|
+
expireTimeInSeconds?: number;
|
|
47
|
+
}
|
|
48
|
+
export interface UploadAuthorizationResponse {
|
|
49
|
+
attachmentId: string;
|
|
50
|
+
ossKey: string;
|
|
51
|
+
uploadUrl: string;
|
|
52
|
+
fileName: string;
|
|
53
|
+
fileType: string;
|
|
54
|
+
expiresInSeconds: number;
|
|
55
|
+
}
|
|
56
|
+
export interface CompleteUploadRequest {
|
|
57
|
+
refType: AttachmentRefType;
|
|
58
|
+
refId: string;
|
|
59
|
+
ossKey: string;
|
|
60
|
+
fileSize: number;
|
|
61
|
+
etag: string;
|
|
62
|
+
}
|
|
63
|
+
export interface DeleteAttachmentRequest {
|
|
64
|
+
attachmentId: string;
|
|
65
|
+
refType: AttachmentRefType;
|
|
66
|
+
refId: string;
|
|
67
|
+
}
|
|
68
|
+
export interface DownloadAttachmentUrlRequest {
|
|
69
|
+
attachmentId: string;
|
|
70
|
+
refType: AttachmentRefType;
|
|
71
|
+
refId: string;
|
|
72
|
+
expiresInSeconds?: number;
|
|
73
|
+
}
|
|
74
|
+
export interface DownloadUrlResponse {
|
|
75
|
+
attachmentId: string;
|
|
76
|
+
fileName: string;
|
|
77
|
+
ossKey: string;
|
|
78
|
+
downloadUrl: string;
|
|
79
|
+
expiresInSeconds: number;
|
|
80
|
+
}
|
|
81
|
+
export interface AttachmentOptions extends CommonOptions {
|
|
82
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PageResponse } from "../common/types.js";
|
|
2
|
+
import type { AttachmentType, CreateAttachmentTypeRequest, UpdateAttachmentTypeRequest, ListAttachmentTypesRequest, ListAttachmentTypesByRefRequest, AttachmentTypeOptions } from "./types.js";
|
|
3
|
+
export type { AttachmentRefType, AttachmentType, CreateAttachmentTypeRequest, UpdateAttachmentTypeRequest, ListAttachmentTypesRequest, ListAttachmentTypesByRefRequest, AttachmentTypeOptions, } from "./types.js";
|
|
4
|
+
/** List attachment types */
|
|
5
|
+
export declare function listAttachmentTypes(request?: ListAttachmentTypesRequest & AttachmentTypeOptions): Promise<PageResponse<AttachmentType>>;
|
|
6
|
+
/** List attachment types by reference */
|
|
7
|
+
export declare function listAttachmentTypesByRef(request: ListAttachmentTypesByRefRequest & AttachmentTypeOptions): Promise<PageResponse<AttachmentType>>;
|
|
8
|
+
/** Get attachment type by ID */
|
|
9
|
+
export declare function getAttachmentType(typeId: string, options?: AttachmentTypeOptions): Promise<AttachmentType>;
|
|
10
|
+
/** Create attachment type */
|
|
11
|
+
export declare function createAttachmentType(request: CreateAttachmentTypeRequest, options?: AttachmentTypeOptions): Promise<AttachmentType>;
|
|
12
|
+
/** Update attachment type */
|
|
13
|
+
export declare function updateAttachmentType(typeId: string, request: UpdateAttachmentTypeRequest, options?: AttachmentTypeOptions): Promise<AttachmentType>;
|
|
14
|
+
/** Delete attachment type */
|
|
15
|
+
export declare function deleteAttachmentType(typeId: string, options?: AttachmentTypeOptions): Promise<void>;
|