@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
@@ -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>;
@@ -0,0 +1,203 @@
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
+ /** List attachment types */
31
+ export async function listAttachmentTypes(request) {
32
+ const token = request?.appToken ?? (await getAppToken(request));
33
+ const base = getBaseUrl(request);
34
+ const url = new URL(base + "/attachment-type/v2/types");
35
+ const { appToken, baseUrl, ...requestParams } = request || {};
36
+ const queryParams = {
37
+ page: 0,
38
+ size: 20,
39
+ sort: "createdAt,desc",
40
+ ...requestParams,
41
+ };
42
+ Object.entries(queryParams).forEach(([key, value]) => {
43
+ if (value !== undefined) {
44
+ url.searchParams.append(key, String(value));
45
+ }
46
+ });
47
+ let response;
48
+ try {
49
+ response = await globalThis.fetch(url.toString(), {
50
+ method: "GET",
51
+ headers: {
52
+ "Content-Type": "application/json",
53
+ "x-t-token": token,
54
+ },
55
+ });
56
+ }
57
+ catch (error) {
58
+ throw new NetworkError(`Failed to list attachment types: ${error instanceof Error ? error.message : "Unknown error"}`);
59
+ }
60
+ const json = await response.json();
61
+ return parseApiResponse(json, "Failed to list attachment types", response.status);
62
+ }
63
+ /** List attachment types by reference */
64
+ export async function listAttachmentTypesByRef(request) {
65
+ const refTypeId = request?.refTypeId?.trim();
66
+ const refType = request?.refType?.trim();
67
+ if (!refTypeId && !refType) {
68
+ throw new ApiError("At least one of refTypeId or refType is required", 400, "9400");
69
+ }
70
+ const token = request.appToken ?? (await getAppToken(request));
71
+ const base = getBaseUrl(request);
72
+ const url = new URL(base + "/attachment-type/v2/types/by-ref");
73
+ const { appToken, baseUrl, refTypeId: _refTypeId, refType: _refType, ...pagination } = request;
74
+ if (refTypeId) {
75
+ url.searchParams.append("refTypeId", refTypeId);
76
+ }
77
+ if (refType) {
78
+ url.searchParams.append("refType", refType);
79
+ }
80
+ const queryParams = {
81
+ page: 0,
82
+ size: 20,
83
+ sort: "createdAt,desc",
84
+ ...pagination,
85
+ };
86
+ Object.entries(queryParams).forEach(([key, value]) => {
87
+ if (value !== undefined) {
88
+ url.searchParams.append(key, String(value));
89
+ }
90
+ });
91
+ let response;
92
+ try {
93
+ response = await globalThis.fetch(url.toString(), {
94
+ method: "GET",
95
+ headers: {
96
+ "Content-Type": "application/json",
97
+ "x-t-token": token,
98
+ },
99
+ });
100
+ }
101
+ catch (error) {
102
+ throw new NetworkError(`Failed to list attachment types by ref: ${error instanceof Error ? error.message : "Unknown error"}`);
103
+ }
104
+ const json = await response.json();
105
+ return parseApiResponse(json, "Failed to list attachment types by ref", response.status);
106
+ }
107
+ /** Get attachment type by ID */
108
+ export async function getAttachmentType(typeId, options) {
109
+ assertRequiredString(typeId, "typeId");
110
+ const token = options?.appToken ?? (await getAppToken(options));
111
+ const base = getBaseUrl(options);
112
+ const url = new URL(base + `/attachment-type/v2/types/${encodeURIComponent(typeId)}`);
113
+ let response;
114
+ try {
115
+ response = await globalThis.fetch(url.toString(), {
116
+ method: "GET",
117
+ headers: {
118
+ "Content-Type": "application/json",
119
+ "x-t-token": token,
120
+ },
121
+ });
122
+ }
123
+ catch (error) {
124
+ throw new NetworkError(`Failed to get attachment type: ${error instanceof Error ? error.message : "Unknown error"}`);
125
+ }
126
+ const json = await response.json();
127
+ return parseApiResponse(json, "Failed to get attachment type", response.status);
128
+ }
129
+ /** Create attachment type */
130
+ export async function createAttachmentType(request, options) {
131
+ assertRequiredString(request?.refType, "refType");
132
+ assertRequiredString(request?.typeCode, "typeCode");
133
+ assertRequiredString(request?.typeName, "typeName");
134
+ const token = options?.appToken ?? (await getAppToken(options));
135
+ const base = getBaseUrl(options);
136
+ const url = new URL(base + "/attachment-type/v2/types");
137
+ let response;
138
+ try {
139
+ response = await globalThis.fetch(url.toString(), {
140
+ method: "POST",
141
+ headers: {
142
+ "Content-Type": "application/json",
143
+ "x-t-token": token,
144
+ },
145
+ body: JSON.stringify(request),
146
+ });
147
+ }
148
+ catch (error) {
149
+ throw new NetworkError(`Failed to create attachment type: ${error instanceof Error ? error.message : "Unknown error"}`);
150
+ }
151
+ const json = await response.json();
152
+ return parseApiResponse(json, "Failed to create attachment type", response.status);
153
+ }
154
+ /** Update attachment type */
155
+ export async function updateAttachmentType(typeId, request, options) {
156
+ assertRequiredString(typeId, "typeId");
157
+ const token = options?.appToken ?? (await getAppToken(options));
158
+ const base = getBaseUrl(options);
159
+ const url = new URL(base + `/attachment-type/v2/types/${encodeURIComponent(typeId)}`);
160
+ let response;
161
+ try {
162
+ response = await globalThis.fetch(url.toString(), {
163
+ method: "PUT",
164
+ headers: {
165
+ "Content-Type": "application/json",
166
+ "x-t-token": token,
167
+ },
168
+ body: JSON.stringify(request),
169
+ });
170
+ }
171
+ catch (error) {
172
+ throw new NetworkError(`Failed to update attachment type: ${error instanceof Error ? error.message : "Unknown error"}`);
173
+ }
174
+ const json = await response.json();
175
+ return parseApiResponse(json, "Failed to update attachment type", response.status);
176
+ }
177
+ /** Delete attachment type */
178
+ export async function deleteAttachmentType(typeId, options) {
179
+ assertRequiredString(typeId, "typeId");
180
+ const token = options?.appToken ?? (await getAppToken(options));
181
+ const base = getBaseUrl(options);
182
+ const url = new URL(base + `/attachment-type/v2/types/${encodeURIComponent(typeId)}`);
183
+ let response;
184
+ try {
185
+ response = await globalThis.fetch(url.toString(), {
186
+ method: "DELETE",
187
+ headers: {
188
+ "Content-Type": "application/json",
189
+ "x-t-token": token,
190
+ },
191
+ });
192
+ }
193
+ catch (error) {
194
+ throw new NetworkError(`Failed to delete attachment type: ${error instanceof Error ? error.message : "Unknown error"}`);
195
+ }
196
+ const json = (await response.json());
197
+ if (json.code !== 200) {
198
+ const errorMsg = typeof json.msg === "string"
199
+ ? json.msg
200
+ : "Failed to delete attachment type";
201
+ throw new ApiError(errorMsg, response.status, json.code);
202
+ }
203
+ }
@@ -0,0 +1,60 @@
1
+ import type { CommonOptions } from "../common/types.js";
2
+ export type { AttachmentRefType } from "../attachment/types.js";
3
+ type AttachmentRefType = import("../attachment/types.js").AttachmentRefType;
4
+ export interface AttachmentType {
5
+ typeId: string;
6
+ appId: string;
7
+ refType: string;
8
+ refTypeId?: string | null;
9
+ typeCode: string;
10
+ typeName: string;
11
+ description?: string;
12
+ allowedExtensions: string[];
13
+ allowedMimeTypes: string[];
14
+ maxFileSize: number;
15
+ isUnique: boolean;
16
+ isEnabled: boolean;
17
+ createdAt: string;
18
+ updatedAt: string;
19
+ remark?: string;
20
+ }
21
+ export interface CreateAttachmentTypeRequest {
22
+ refType: AttachmentRefType;
23
+ refTypeId?: string;
24
+ typeCode: string;
25
+ typeName: string;
26
+ description?: string;
27
+ allowedExtensions?: string[];
28
+ allowedMimeTypes?: string[];
29
+ maxFileSize?: number;
30
+ isUnique?: boolean;
31
+ isEnabled?: boolean;
32
+ remark?: string;
33
+ }
34
+ export interface UpdateAttachmentTypeRequest {
35
+ refType?: AttachmentRefType;
36
+ refTypeId?: string;
37
+ typeCode?: string;
38
+ typeName?: string;
39
+ description?: string;
40
+ allowedExtensions?: string[];
41
+ allowedMimeTypes?: string[];
42
+ maxFileSize?: number;
43
+ isUnique?: boolean;
44
+ isEnabled?: boolean;
45
+ remark?: string;
46
+ }
47
+ export interface ListAttachmentTypesRequest {
48
+ page?: number;
49
+ size?: number;
50
+ sort?: string;
51
+ }
52
+ export interface ListAttachmentTypesByRefRequest {
53
+ refTypeId?: string;
54
+ refType?: AttachmentRefType;
55
+ page?: number;
56
+ size?: number;
57
+ sort?: string;
58
+ }
59
+ export interface AttachmentTypeOptions extends CommonOptions {
60
+ }
@@ -0,0 +1 @@
1
+ export {};