@vertesia/client 0.57.0 → 0.58.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/lib/cjs/store/FilesApi.js +29 -19
- package/lib/cjs/store/FilesApi.js.map +1 -1
- package/lib/cjs/store/ObjectsApi.js +20 -17
- package/lib/cjs/store/ObjectsApi.js.map +1 -1
- package/lib/esm/store/FilesApi.js +29 -19
- package/lib/esm/store/FilesApi.js.map +1 -1
- package/lib/esm/store/ObjectsApi.js +20 -17
- package/lib/esm/store/ObjectsApi.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/AccountApi.d.ts +1 -0
- package/lib/types/AccountsApi.d.ts +1 -0
- package/lib/types/AnalyticsApi.d.ts +1 -0
- package/lib/types/ApiKeysApi.d.ts +1 -0
- package/lib/types/CommandsApi.d.ts +1 -0
- package/lib/types/EnvironmentsApi.d.ts +1 -0
- package/lib/types/IamApi.d.ts +1 -0
- package/lib/types/InteractionBase.d.ts +1 -0
- package/lib/types/InteractionsApi.d.ts +1 -0
- package/lib/types/PluginsApi.d.ts +1 -0
- package/lib/types/ProjectsApi.d.ts +1 -0
- package/lib/types/PromptsApi.d.ts +1 -0
- package/lib/types/RefsApi.d.ts +1 -0
- package/lib/types/RunsApi.d.ts +1 -0
- package/lib/types/StreamSource.d.ts +1 -0
- package/lib/types/TrainingApi.d.ts +1 -0
- package/lib/types/UsersApi.d.ts +1 -0
- package/lib/types/client.d.ts +1 -0
- package/lib/types/execute.d.ts +1 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/nodejs/NodeStreamSource.d.ts +1 -0
- package/lib/types/nodejs/index.d.ts +1 -0
- package/lib/types/store/AgentsApi.d.ts +1 -0
- package/lib/types/store/AnalyzeDocApi.d.ts +1 -0
- package/lib/types/store/CollectionsApi.d.ts +1 -0
- package/lib/types/store/CommandsApi.d.ts +1 -0
- package/lib/types/store/EmbeddingsApi.d.ts +1 -0
- package/lib/types/store/FilesApi.d.ts +2 -0
- package/lib/types/store/FilesApi.d.ts.map +1 -1
- package/lib/types/store/ObjectsApi.d.ts +2 -7
- package/lib/types/store/ObjectsApi.d.ts.map +1 -1
- package/lib/types/store/TypesApi.d.ts +1 -0
- package/lib/types/store/WorkflowsApi.d.ts +1 -0
- package/lib/types/store/client.d.ts +1 -0
- package/lib/types/store/errors.d.ts +1 -0
- package/lib/types/store/index.d.ts +1 -0
- package/lib/vertesia-client.js +1 -1
- package/lib/vertesia-client.js.map +1 -1
- package/package.json +4 -4
- package/src/store/FilesApi.ts +83 -55
- package/src/store/ObjectsApi.ts +311 -296
package/src/store/ObjectsApi.ts
CHANGED
|
@@ -1,31 +1,33 @@
|
|
|
1
1
|
import { ApiTopic, ClientBase } from "@vertesia/api-fetch-client";
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
3
|
+
ComplexSearchPayload,
|
|
4
|
+
ComputeObjectFacetPayload,
|
|
5
|
+
ContentObject,
|
|
6
|
+
ContentObjectItem,
|
|
7
|
+
ContentSource,
|
|
8
|
+
CreateContentObjectPayload,
|
|
9
|
+
Embedding,
|
|
10
|
+
ExportPropertiesPayload,
|
|
11
|
+
ExportPropertiesResponse,
|
|
12
|
+
FindPayload,
|
|
13
|
+
GetFileUrlPayload,
|
|
14
|
+
GetFileUrlResponse,
|
|
15
|
+
GetRenditionParams,
|
|
16
|
+
GetRenditionResponse,
|
|
17
|
+
GetUploadUrlPayload,
|
|
18
|
+
ListWorkflowRunsResponse,
|
|
19
|
+
ObjectSearchPayload,
|
|
20
|
+
ObjectSearchQuery,
|
|
21
|
+
SupportedEmbeddingTypes,
|
|
21
22
|
} from "@vertesia/common";
|
|
22
23
|
|
|
23
24
|
import { StreamSource } from "../StreamSource.js";
|
|
24
25
|
import { AnalyzeDocApi } from "./AnalyzeDocApi.js";
|
|
25
26
|
import { ZenoClient } from "./client.js";
|
|
26
27
|
|
|
27
|
-
export interface UploadContentObjectPayload
|
|
28
|
-
|
|
28
|
+
export interface UploadContentObjectPayload
|
|
29
|
+
extends Omit<CreateContentObjectPayload, "content"> {
|
|
30
|
+
content?:
|
|
29
31
|
| StreamSource
|
|
30
32
|
| File
|
|
31
33
|
| {
|
|
@@ -38,123 +40,127 @@ export interface UploadContentObjectPayload extends Omit<CreateContentObjectPayl
|
|
|
38
40
|
|
|
39
41
|
// the target id in the content store
|
|
40
42
|
id?: string;
|
|
41
|
-
|
|
43
|
+
};
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
export interface ComputeFacetsResponse {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
type?: { _id: string; count: number }[];
|
|
48
|
+
location?: { _id: string; count: number }[];
|
|
49
|
+
status?: { _id: string; count: number }[];
|
|
50
|
+
total?: { count: number }[];
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
export class ObjectsApi extends ApiTopic {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
54
|
+
constructor(parent: ClientBase) {
|
|
55
|
+
super(parent, "/api/v1/objects");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
analyze(objectId: string) {
|
|
59
|
+
return new AnalyzeDocApi(this, objectId);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
getUploadUrl(payload: GetUploadUrlPayload): Promise<GetFileUrlResponse> {
|
|
63
|
+
return this.post("/upload-url", {
|
|
64
|
+
payload,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
getDownloadUrl(fileUri: string): Promise<{ url: string }> {
|
|
69
|
+
return this.post("/download-url", {
|
|
70
|
+
payload: {
|
|
71
|
+
file: fileUri,
|
|
72
|
+
} satisfies GetFileUrlPayload,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
getContentSource(objectId: string): Promise<ContentSource> {
|
|
77
|
+
return this.get(`/${objectId}/content-source`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* List objects with revision filtering options
|
|
82
|
+
*
|
|
83
|
+
* @param payload Search/filter parameters
|
|
84
|
+
* @returns Matching content objects
|
|
85
|
+
*/
|
|
86
|
+
list<T = any>(
|
|
87
|
+
payload: ObjectSearchPayload = {},
|
|
88
|
+
): Promise<ContentObjectItem<T>[]> {
|
|
89
|
+
const limit = payload.limit || 100;
|
|
90
|
+
const offset = payload.offset || 0;
|
|
91
|
+
const query = payload.query || ({} as ObjectSearchQuery);
|
|
92
|
+
|
|
93
|
+
// Add revision filtering options
|
|
94
|
+
const showAllRevisions = payload.all_revisions === true;
|
|
95
|
+
const revisionRoot = payload.from_root;
|
|
96
|
+
|
|
97
|
+
return this.get("/", {
|
|
98
|
+
query: {
|
|
99
|
+
limit,
|
|
100
|
+
offset,
|
|
101
|
+
...query,
|
|
102
|
+
all_revisions: showAllRevisions ? "true" : undefined,
|
|
103
|
+
from_root: revisionRoot,
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
computeFacets(
|
|
109
|
+
query: ComputeObjectFacetPayload,
|
|
110
|
+
): Promise<ComputeFacetsResponse> {
|
|
111
|
+
return this.post("/facets", {
|
|
112
|
+
payload: query,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
listFolders(path: string = "/") {
|
|
117
|
+
path; //TODO
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Find object based on query */
|
|
121
|
+
find(payload: FindPayload): Promise<ContentObject[]> {
|
|
122
|
+
return this.post("/find", {
|
|
123
|
+
payload,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Count number of objects matching this query */
|
|
128
|
+
count(payload: FindPayload): Promise<{ count: number }> {
|
|
129
|
+
return this.post("/count", {
|
|
130
|
+
payload,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Search object — different from find because allow full text search */
|
|
135
|
+
search(payload: ComplexSearchPayload): Promise<ContentObjectItem[]> {
|
|
136
|
+
return this.post("/search", {
|
|
137
|
+
payload,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
retrieve(id: string, select?: string): Promise<ContentObject> {
|
|
142
|
+
return this.get(`/${id}`, {
|
|
143
|
+
query: {
|
|
144
|
+
select,
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
getObjectText(id: string): Promise<{ text: string }> {
|
|
150
|
+
return this.get(`/${id}/text`);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async upload(source: StreamSource | File) {
|
|
154
|
+
const isStream = source instanceof StreamSource;
|
|
155
|
+
// get a signed URL to upload the file a computed mimeType and the file object id.
|
|
156
|
+
const { url, id, mime_type } = await this.getUploadUrl({
|
|
157
|
+
id: isStream ? source.id : undefined,
|
|
158
|
+
name: source.name,
|
|
159
|
+
mime_type: source.type,
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// upload the file content to the signed URL
|
|
163
|
+
/*const res = await this.fetch(url, {
|
|
158
164
|
method: 'PUT',
|
|
159
165
|
//@ts-ignore: duplex is not in the types. See https://github.com/node-fetch/node-fetch/issues/1769
|
|
160
166
|
duplex: isStream ? "half" : undefined,
|
|
@@ -171,177 +177,186 @@ export class ObjectsApi extends ApiTopic {
|
|
|
171
177
|
}
|
|
172
178
|
});*/
|
|
173
179
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
} else {
|
|
187
|
-
console.log(res);
|
|
188
|
-
throw new Error(`Failed to upload file: ${res.statusText}`);
|
|
189
|
-
}
|
|
190
|
-
})
|
|
191
|
-
.catch((err) => {
|
|
192
|
-
console.error("Failed to upload file", err);
|
|
193
|
-
throw err;
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
//Etag need to be unquoted
|
|
197
|
-
//When a server returns an ETag header, it includes the quotes around the actual hash value.
|
|
198
|
-
//This is part of the HTTP specification (RFC 7232), which states that ETags should be
|
|
199
|
-
//enclosed in double quotes.
|
|
200
|
-
const etag = res.headers.get("etag")?.replace(/^"(.*)"$/, "$1");
|
|
201
|
-
|
|
202
|
-
return {
|
|
203
|
-
source: id,
|
|
204
|
-
name: source.name,
|
|
205
|
-
type: mime_type,
|
|
206
|
-
etag,
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
async create(
|
|
211
|
-
payload: UploadContentObjectPayload,
|
|
212
|
-
options?: {
|
|
213
|
-
collection_id?: string;
|
|
214
|
-
},
|
|
215
|
-
): Promise<ContentObject> {
|
|
216
|
-
const createPayload: CreateContentObjectPayload = {
|
|
217
|
-
...payload,
|
|
218
|
-
};
|
|
219
|
-
if (payload.content instanceof StreamSource || payload.content instanceof File) {
|
|
220
|
-
createPayload.content = await this.upload(payload.content);
|
|
221
|
-
}
|
|
222
|
-
return await this.post("/", {
|
|
223
|
-
payload: createPayload,
|
|
224
|
-
query: options || {},
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Create an object which holds a reference to an external blob (i.e. not in the project bucket)
|
|
230
|
-
* The uri should starts either with gs:// or s3://. Not other protocols are supported yet.
|
|
231
|
-
* For the s3 blobs you must use a hash with the blob #region. Ex: s3://bucket/path/to/file#us-east-1
|
|
232
|
-
* @param uri
|
|
233
|
-
* @param payload
|
|
234
|
-
* @returns
|
|
235
|
-
*/
|
|
236
|
-
async createFromExternalSource(uri: string, payload: CreateContentObjectPayload = {}): Promise<ContentObject> {
|
|
237
|
-
const metadata = await (this.client as ZenoClient).files.getMetadata(uri);
|
|
238
|
-
const createPayload: CreateContentObjectPayload = {
|
|
239
|
-
...payload,
|
|
240
|
-
content: {
|
|
241
|
-
source: uri,
|
|
242
|
-
name: metadata.name,
|
|
243
|
-
type: metadata.contentType,
|
|
244
|
-
etag: metadata.etag,
|
|
245
|
-
},
|
|
246
|
-
};
|
|
247
|
-
return await this.post("/", {
|
|
248
|
-
payload: createPayload,
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Updates an existing object or creates a new revision
|
|
254
|
-
* Handles file uploads similar to the create method
|
|
255
|
-
*
|
|
256
|
-
* @param id The ID of the object to update
|
|
257
|
-
* @param payload The changes to apply
|
|
258
|
-
* @param options Additional options
|
|
259
|
-
* @param options.createRevision Whether to create a new revision instead of updating in place
|
|
260
|
-
* @param options.revisionLabel Optional label for the revision (e.g., "v1.2")
|
|
261
|
-
* @returns The updated object or newly created revision
|
|
262
|
-
*/
|
|
263
|
-
async update(
|
|
264
|
-
id: string,
|
|
265
|
-
payload: Partial<CreateContentObjectPayload>,
|
|
266
|
-
options?: {
|
|
267
|
-
createRevision?: boolean;
|
|
268
|
-
revisionLabel?: string;
|
|
269
|
-
},
|
|
270
|
-
): Promise<ContentObject> {
|
|
271
|
-
const updatePayload: Partial<CreateContentObjectPayload> = {
|
|
272
|
-
...payload,
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
// Handle file upload if content is provided as File or StreamSource
|
|
276
|
-
if (payload.content instanceof StreamSource || payload.content instanceof File) {
|
|
277
|
-
updatePayload.content = await this.upload(payload.content);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
if (options?.createRevision) {
|
|
281
|
-
return this.put(`/${id}`, {
|
|
282
|
-
payload: updatePayload,
|
|
283
|
-
headers: {
|
|
284
|
-
"x-create-revision": "true",
|
|
285
|
-
"x-revision-label": options.revisionLabel || "",
|
|
286
|
-
},
|
|
287
|
-
});
|
|
180
|
+
const res = await fetch(url, {
|
|
181
|
+
method: "PUT",
|
|
182
|
+
body: isStream ? source.stream : source,
|
|
183
|
+
//@ts-ignore: duplex is not in the types. See https://github.com/node-fetch/node-fetch/issues/1769
|
|
184
|
+
duplex: isStream ? "half" : undefined,
|
|
185
|
+
headers: {
|
|
186
|
+
"Content-Type": mime_type || "application/octet-stream",
|
|
187
|
+
},
|
|
188
|
+
})
|
|
189
|
+
.then((res: Response) => {
|
|
190
|
+
if (res.ok) {
|
|
191
|
+
return res;
|
|
288
192
|
} else {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
});
|
|
193
|
+
console.log(res);
|
|
194
|
+
throw new Error(`Failed to upload file: ${res.statusText}`);
|
|
292
195
|
}
|
|
196
|
+
})
|
|
197
|
+
.catch((err) => {
|
|
198
|
+
console.error("Failed to upload file", err);
|
|
199
|
+
throw err;
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
//Etag need to be unquoted
|
|
203
|
+
//When a server returns an ETag header, it includes the quotes around the actual hash value.
|
|
204
|
+
//This is part of the HTTP specification (RFC 7232), which states that ETags should be
|
|
205
|
+
//enclosed in double quotes.
|
|
206
|
+
const etag = res.headers.get("etag")?.replace(/^"(.*)"$/, "$1");
|
|
207
|
+
|
|
208
|
+
return {
|
|
209
|
+
source: id,
|
|
210
|
+
name: source.name,
|
|
211
|
+
type: mime_type,
|
|
212
|
+
etag,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
async create(
|
|
217
|
+
payload: UploadContentObjectPayload,
|
|
218
|
+
options?: {
|
|
219
|
+
collection_id?: string;
|
|
220
|
+
},
|
|
221
|
+
): Promise<ContentObject> {
|
|
222
|
+
const createPayload: CreateContentObjectPayload = {
|
|
223
|
+
...payload,
|
|
224
|
+
};
|
|
225
|
+
if (
|
|
226
|
+
payload.content instanceof StreamSource ||
|
|
227
|
+
payload.content instanceof File
|
|
228
|
+
) {
|
|
229
|
+
createPayload.content = await this.upload(payload.content);
|
|
293
230
|
}
|
|
231
|
+
return await this.post("/", {
|
|
232
|
+
payload: createPayload,
|
|
233
|
+
query: options || {},
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Create an object which holds a reference to an external blob (i.e. not in the project bucket)
|
|
239
|
+
* The uri should starts either with gs:// or s3://. Not other protocols are supported yet.
|
|
240
|
+
* For the s3 blobs you must use a hash with the blob #region. Ex: s3://bucket/path/to/file#us-east-1
|
|
241
|
+
* @param uri
|
|
242
|
+
* @param payload
|
|
243
|
+
* @returns
|
|
244
|
+
*/
|
|
245
|
+
async createFromExternalSource(
|
|
246
|
+
uri: string,
|
|
247
|
+
payload: CreateContentObjectPayload = {},
|
|
248
|
+
): Promise<ContentObject> {
|
|
249
|
+
const metadata = await (this.client as ZenoClient).files.getMetadata(uri);
|
|
250
|
+
const createPayload: CreateContentObjectPayload = {
|
|
251
|
+
...payload,
|
|
252
|
+
content: {
|
|
253
|
+
source: uri,
|
|
254
|
+
name: metadata.name,
|
|
255
|
+
type: metadata.contentType,
|
|
256
|
+
etag: metadata.etag,
|
|
257
|
+
},
|
|
258
|
+
};
|
|
259
|
+
return await this.post("/", {
|
|
260
|
+
payload: createPayload,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Updates an existing object or creates a new revision
|
|
266
|
+
* Handles file uploads similar to the create method
|
|
267
|
+
*
|
|
268
|
+
* @param id The ID of the object to update
|
|
269
|
+
* @param payload The changes to apply
|
|
270
|
+
* @param options Additional options
|
|
271
|
+
* @param options.createRevision Whether to create a new revision instead of updating in place
|
|
272
|
+
* @param options.revisionLabel Optional label for the revision (e.g., "v1.2")
|
|
273
|
+
* @returns The updated object or newly created revision
|
|
274
|
+
*/
|
|
275
|
+
async update(
|
|
276
|
+
id: string,
|
|
277
|
+
payload: Partial<CreateContentObjectPayload>,
|
|
278
|
+
options?: {
|
|
279
|
+
createRevision?: boolean;
|
|
280
|
+
revisionLabel?: string;
|
|
281
|
+
},
|
|
282
|
+
): Promise<ContentObject> {
|
|
283
|
+
const updatePayload: Partial<CreateContentObjectPayload> = {
|
|
284
|
+
...payload,
|
|
285
|
+
};
|
|
294
286
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
getRevisions(id: string): Promise<ContentObjectItem[]> {
|
|
302
|
-
return this.get(`/${id}/revisions`);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
delete(id: string): Promise<{ id: string }> {
|
|
306
|
-
return this.del(`/${id}`);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
listWorkflowRuns(documentId: string): Promise<ListWorkflowRunsResponse> {
|
|
310
|
-
return this.get(`/${documentId}/workflow-runs`);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
listRenditions(documentId: string): Promise<ContentObjectItem[]> {
|
|
314
|
-
return this.get(`/${documentId}/renditions`);
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
getRendition(documentId: string, options: GetRenditionParams): Promise<GetRenditionResponse> {
|
|
318
|
-
const query = {
|
|
319
|
-
max_hw: options.max_hw,
|
|
320
|
-
generate_if_missing: options.generate_if_missing,
|
|
321
|
-
};
|
|
322
|
-
|
|
323
|
-
return this.get(`/${documentId}/renditions/${options.format}`, { query });
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
exportProperties(payload: ExportPropertiesPayload): Promise<ExportPropertiesResponse> {
|
|
327
|
-
return this.post("/export", {
|
|
328
|
-
payload,
|
|
329
|
-
});
|
|
287
|
+
// Handle file upload if content is provided as File or StreamSource
|
|
288
|
+
if (
|
|
289
|
+
payload.content instanceof StreamSource ||
|
|
290
|
+
payload.content instanceof File
|
|
291
|
+
) {
|
|
292
|
+
updatePayload.content = await this.upload(payload.content);
|
|
330
293
|
}
|
|
331
294
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
295
|
+
if (options?.createRevision) {
|
|
296
|
+
return this.put(`/${id}`, {
|
|
297
|
+
payload: updatePayload,
|
|
298
|
+
headers: {
|
|
299
|
+
"x-create-revision": "true",
|
|
300
|
+
"x-revision-label": options.revisionLabel || "",
|
|
301
|
+
},
|
|
302
|
+
});
|
|
303
|
+
} else {
|
|
304
|
+
return this.put(`/${id}`, {
|
|
305
|
+
payload: updatePayload,
|
|
306
|
+
});
|
|
340
307
|
}
|
|
341
|
-
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Retrieves all revisions of a content object
|
|
312
|
+
*
|
|
313
|
+
* @param id The ID of any revision in the object's history
|
|
314
|
+
* @returns Array of all revisions sharing the same root
|
|
315
|
+
*/
|
|
316
|
+
getRevisions(id: string): Promise<ContentObjectItem[]> {
|
|
317
|
+
return this.get(`/${id}/revisions`);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
delete(id: string): Promise<{ id: string }> {
|
|
321
|
+
return this.del(`/${id}`);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
listWorkflowRuns(documentId: string): Promise<ListWorkflowRunsResponse> {
|
|
325
|
+
return this.get(`/${documentId}/workflow-runs`);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
listRenditions(documentId: string): Promise<ContentObjectItem[]> {
|
|
329
|
+
return this.get(`/${documentId}/renditions`);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
getRendition(
|
|
333
|
+
documentId: string,
|
|
334
|
+
options: GetRenditionParams,
|
|
335
|
+
): Promise<GetRenditionResponse> {
|
|
336
|
+
const query = {
|
|
337
|
+
max_hw: options.max_hw,
|
|
338
|
+
generate_if_missing: options.generate_if_missing,
|
|
339
|
+
as_signed_url: options.sign_url,
|
|
340
|
+
};
|
|
342
341
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
342
|
+
return this.get(`/${documentId}/renditions/${options.format}`, { query });
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
exportProperties(
|
|
346
|
+
payload: ExportPropertiesPayload,
|
|
347
|
+
): Promise<ExportPropertiesResponse> {
|
|
348
|
+
return this.post("/export", {
|
|
349
|
+
payload,
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
setEmbedding(
|
|
354
|
+
id: string,
|
|
355
|
+
type: SupportedEmbeddingTypes,
|
|
356
|
+
payload: Embedding,
|
|
357
|
+
): Promise<Record<SupportedEmbeddingTypes, Embedding>> {
|
|
358
|
+
return this.put(`/${id}/embeddings/${type}`, {
|
|
359
|
+
payload,
|
|
360
|
+
});
|
|
361
|
+
}
|
|
347
362
|
}
|