tuturuuu 0.2.0 → 0.2.1
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/package.json +15 -25
- package/src/epm.ts +0 -711
- package/src/errors.ts +0 -202
- package/src/external-projects.ts +0 -11
- package/src/index.ts +0 -138
- package/src/storage.ts +0 -1082
- package/src/types.ts +0 -202
package/src/epm.ts
DELETED
|
@@ -1,711 +0,0 @@
|
|
|
1
|
-
import packageJson from '../package.json';
|
|
2
|
-
import {
|
|
3
|
-
createErrorFromResponse,
|
|
4
|
-
isApiErrorResponse,
|
|
5
|
-
NetworkError,
|
|
6
|
-
ValidationError,
|
|
7
|
-
} from './errors';
|
|
8
|
-
import type {
|
|
9
|
-
EpmAssetPayload,
|
|
10
|
-
EpmAssetUpdatePayload,
|
|
11
|
-
EpmAssetUploadOptions,
|
|
12
|
-
EpmBlockPayload,
|
|
13
|
-
EpmBlockUpdatePayload,
|
|
14
|
-
EpmCollectionNavigationConfig,
|
|
15
|
-
EpmCollectionPayload,
|
|
16
|
-
EpmCollectionUpdatePayload,
|
|
17
|
-
EpmEntryListOptions,
|
|
18
|
-
EpmEntryPayload,
|
|
19
|
-
EpmEntryUpdatePayload,
|
|
20
|
-
EpmPublishEventKind,
|
|
21
|
-
ExternalProjectBulkUpdatePayload,
|
|
22
|
-
ExternalProjectCollection,
|
|
23
|
-
ExternalProjectDeliveryOptions,
|
|
24
|
-
ExternalProjectDeliveryPayload,
|
|
25
|
-
ExternalProjectLoadingData,
|
|
26
|
-
ExternalProjectStudioData,
|
|
27
|
-
ExternalProjectSummary,
|
|
28
|
-
WorkspaceExternalProjectBinding,
|
|
29
|
-
YoolaExternalProjectLoadingData,
|
|
30
|
-
} from './types';
|
|
31
|
-
import { externalProjectDeliveryOptionsSchema } from './types';
|
|
32
|
-
|
|
33
|
-
function absolutizeUrl(baseUrl: string, value: string | null | undefined) {
|
|
34
|
-
if (!value) {
|
|
35
|
-
return value ?? null;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (/^https?:\/\//i.test(value)) {
|
|
39
|
-
return value;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const parsedBaseUrl = new URL(baseUrl);
|
|
43
|
-
|
|
44
|
-
if (value.startsWith('/')) {
|
|
45
|
-
return new URL(value, parsedBaseUrl.origin).toString();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return new URL(value, `${baseUrl.replace(/\/$/, '')}/`).toString();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function normalizeDeliveryPayloadUrls(
|
|
52
|
-
payload: ExternalProjectDeliveryPayload,
|
|
53
|
-
apiBaseUrl: string
|
|
54
|
-
) {
|
|
55
|
-
const normalizedCollections = payload.collections.map((collection) => ({
|
|
56
|
-
...collection,
|
|
57
|
-
entries: collection.entries.map((entry) => ({
|
|
58
|
-
...entry,
|
|
59
|
-
assets: entry.assets.map((asset) => ({
|
|
60
|
-
...asset,
|
|
61
|
-
assetUrl: absolutizeUrl(apiBaseUrl, asset.assetUrl),
|
|
62
|
-
})),
|
|
63
|
-
})),
|
|
64
|
-
}));
|
|
65
|
-
|
|
66
|
-
const loadingData =
|
|
67
|
-
payload.loadingData?.adapter === 'yoola'
|
|
68
|
-
? {
|
|
69
|
-
...payload.loadingData,
|
|
70
|
-
artworks: payload.loadingData.artworks.map((artwork) => ({
|
|
71
|
-
...artwork,
|
|
72
|
-
assetUrl: absolutizeUrl(apiBaseUrl, artwork.assetUrl),
|
|
73
|
-
})),
|
|
74
|
-
artworksByCategory: Object.fromEntries(
|
|
75
|
-
Object.entries(payload.loadingData.artworksByCategory).map(
|
|
76
|
-
([category, artworks]) => [
|
|
77
|
-
category,
|
|
78
|
-
artworks.map((artwork) => ({
|
|
79
|
-
...artwork,
|
|
80
|
-
assetUrl: absolutizeUrl(apiBaseUrl, artwork.assetUrl),
|
|
81
|
-
})),
|
|
82
|
-
]
|
|
83
|
-
)
|
|
84
|
-
),
|
|
85
|
-
featuredArtwork: payload.loadingData.featuredArtwork
|
|
86
|
-
? {
|
|
87
|
-
...payload.loadingData.featuredArtwork,
|
|
88
|
-
assetUrl: absolutizeUrl(
|
|
89
|
-
apiBaseUrl,
|
|
90
|
-
payload.loadingData.featuredArtwork.assetUrl
|
|
91
|
-
),
|
|
92
|
-
}
|
|
93
|
-
: null,
|
|
94
|
-
loreCapsules: payload.loadingData.loreCapsules.map((capsule) => ({
|
|
95
|
-
...capsule,
|
|
96
|
-
artworkAssetUrl: absolutizeUrl(apiBaseUrl, capsule.artworkAssetUrl),
|
|
97
|
-
})),
|
|
98
|
-
}
|
|
99
|
-
: payload.loadingData;
|
|
100
|
-
|
|
101
|
-
return {
|
|
102
|
-
...payload,
|
|
103
|
-
collections: normalizedCollections,
|
|
104
|
-
loadingData,
|
|
105
|
-
} satisfies ExternalProjectDeliveryPayload;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function normalizeStudioPayloadUrls(
|
|
109
|
-
payload: {
|
|
110
|
-
binding: WorkspaceExternalProjectBinding;
|
|
111
|
-
} & ExternalProjectStudioData,
|
|
112
|
-
apiBaseUrl: string
|
|
113
|
-
) {
|
|
114
|
-
return {
|
|
115
|
-
...payload,
|
|
116
|
-
assets: payload.assets.map((asset) => ({
|
|
117
|
-
...asset,
|
|
118
|
-
asset_url: absolutizeUrl(apiBaseUrl, asset.asset_url),
|
|
119
|
-
preview_url: absolutizeUrl(apiBaseUrl, asset.preview_url),
|
|
120
|
-
})),
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export function getEpmCollectionNavigationConfig(
|
|
125
|
-
config: unknown
|
|
126
|
-
): EpmCollectionNavigationConfig | null {
|
|
127
|
-
if (!config || typeof config !== 'object' || Array.isArray(config)) {
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const navigation = (config as Record<string, unknown>).navigation;
|
|
132
|
-
if (
|
|
133
|
-
!navigation ||
|
|
134
|
-
typeof navigation !== 'object' ||
|
|
135
|
-
Array.isArray(navigation)
|
|
136
|
-
) {
|
|
137
|
-
return null;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
return navigation as EpmCollectionNavigationConfig;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export function getEpmCollectionNavigationTitle(
|
|
144
|
-
collection: Pick<ExternalProjectCollection, 'config' | 'title'>
|
|
145
|
-
) {
|
|
146
|
-
const navigation = getEpmCollectionNavigationConfig(collection.config);
|
|
147
|
-
return navigation?.title?.trim() ? navigation.title.trim() : collection.title;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export function buildEpmNavigationItems(
|
|
151
|
-
collections: ExternalProjectCollection[]
|
|
152
|
-
) {
|
|
153
|
-
return collections
|
|
154
|
-
.filter((collection) => collection.is_enabled)
|
|
155
|
-
.map((collection) => {
|
|
156
|
-
const navigation = getEpmCollectionNavigationConfig(collection.config);
|
|
157
|
-
|
|
158
|
-
return {
|
|
159
|
-
collectionId: collection.id,
|
|
160
|
-
href: navigation?.href ?? null,
|
|
161
|
-
navigation: navigation ?? null,
|
|
162
|
-
slug: collection.slug,
|
|
163
|
-
title: getEpmCollectionNavigationTitle(collection),
|
|
164
|
-
visible: navigation?.visible !== false,
|
|
165
|
-
};
|
|
166
|
-
})
|
|
167
|
-
.filter((item) => item.visible);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export function isYoolaExternalProjectLoadingData(
|
|
171
|
-
value: ExternalProjectLoadingData | null | undefined
|
|
172
|
-
): value is YoolaExternalProjectLoadingData {
|
|
173
|
-
return value?.adapter === 'yoola';
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export interface EpmClientConfig {
|
|
177
|
-
apiKey?: string;
|
|
178
|
-
baseUrl?: string;
|
|
179
|
-
fetch?: typeof fetch;
|
|
180
|
-
timeout?: number;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
type ExternalProjectUploadUrlResponse = {
|
|
184
|
-
signedUrl?: string;
|
|
185
|
-
token?: string;
|
|
186
|
-
path?: string;
|
|
187
|
-
fullPath?: string | null;
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
type ExternalProjectUploadUrlPayload = {
|
|
191
|
-
signedUrl: string;
|
|
192
|
-
token: string;
|
|
193
|
-
path: string;
|
|
194
|
-
fullPath: string | null;
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
function parseExternalProjectUploadPayload(
|
|
198
|
-
payload: ExternalProjectUploadUrlResponse
|
|
199
|
-
) {
|
|
200
|
-
if (!payload.signedUrl || !payload.token || !payload.path) {
|
|
201
|
-
throw new Error('Missing upload URL payload');
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return {
|
|
205
|
-
signedUrl: payload.signedUrl,
|
|
206
|
-
token: payload.token,
|
|
207
|
-
path: payload.path,
|
|
208
|
-
fullPath: payload.fullPath ?? null,
|
|
209
|
-
} satisfies ExternalProjectUploadUrlPayload;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
async function uploadExternalProjectFileWithSignedUrl(
|
|
213
|
-
file: File,
|
|
214
|
-
uploadUrlResult: ExternalProjectUploadUrlPayload,
|
|
215
|
-
fetchImpl: typeof fetch
|
|
216
|
-
) {
|
|
217
|
-
let uploadResponse = await fetchImpl(uploadUrlResult.signedUrl, {
|
|
218
|
-
method: 'PUT',
|
|
219
|
-
cache: 'no-store',
|
|
220
|
-
headers: {
|
|
221
|
-
Authorization: `Bearer ${uploadUrlResult.token}`,
|
|
222
|
-
'Content-Type': file.type || 'application/octet-stream',
|
|
223
|
-
},
|
|
224
|
-
body: file,
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
if (!uploadResponse.ok) {
|
|
228
|
-
uploadResponse = await fetchImpl(uploadUrlResult.signedUrl, {
|
|
229
|
-
method: 'PUT',
|
|
230
|
-
cache: 'no-store',
|
|
231
|
-
headers: {
|
|
232
|
-
Authorization: `Bearer ${uploadUrlResult.token}`,
|
|
233
|
-
},
|
|
234
|
-
body: file,
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
if (!uploadResponse.ok) {
|
|
239
|
-
const message = await uploadResponse.text().catch(() => '');
|
|
240
|
-
throw new Error(
|
|
241
|
-
`Failed to upload file (${uploadResponse.status})${message ? `: ${message}` : ''}`
|
|
242
|
-
);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
return {
|
|
246
|
-
fullPath: uploadUrlResult.fullPath,
|
|
247
|
-
path: uploadUrlResult.path,
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
export class EpmClient {
|
|
252
|
-
protected readonly apiKey?: string;
|
|
253
|
-
protected readonly baseUrl: string;
|
|
254
|
-
protected readonly fetchImpl: typeof fetch;
|
|
255
|
-
protected readonly timeout: number;
|
|
256
|
-
|
|
257
|
-
constructor(config: EpmClientConfig = {}) {
|
|
258
|
-
this.apiKey = config.apiKey;
|
|
259
|
-
this.baseUrl = config.baseUrl || 'https://tuturuuu.com/api/v1';
|
|
260
|
-
this.fetchImpl = config.fetch || globalThis.fetch;
|
|
261
|
-
this.timeout = config.timeout || 30000;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
private requireApiKey() {
|
|
265
|
-
if (!this.apiKey) {
|
|
266
|
-
throw new ValidationError(
|
|
267
|
-
'API key is required for EPM management operations'
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
protected async request<T>(
|
|
273
|
-
endpoint: string,
|
|
274
|
-
options: {
|
|
275
|
-
body?: BodyInit;
|
|
276
|
-
headers?: HeadersInit;
|
|
277
|
-
method?: string;
|
|
278
|
-
requiresAuth?: boolean;
|
|
279
|
-
} = {}
|
|
280
|
-
): Promise<T> {
|
|
281
|
-
const {
|
|
282
|
-
body,
|
|
283
|
-
headers: headerOverrides,
|
|
284
|
-
method = 'GET',
|
|
285
|
-
requiresAuth,
|
|
286
|
-
} = options;
|
|
287
|
-
|
|
288
|
-
if (requiresAuth) {
|
|
289
|
-
this.requireApiKey();
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
const headers = new Headers({
|
|
293
|
-
Accept: 'application/json',
|
|
294
|
-
'X-SDK-Client': `tuturuuu/${packageJson.version || '0.0.1'}`,
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
if (this.apiKey) {
|
|
298
|
-
headers.set('Authorization', `Bearer ${this.apiKey}`);
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
if (headerOverrides) {
|
|
302
|
-
const normalized = new Headers(headerOverrides);
|
|
303
|
-
for (const [key, value] of normalized.entries()) {
|
|
304
|
-
headers.set(key, value);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
const controller = new AbortController();
|
|
309
|
-
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
310
|
-
|
|
311
|
-
try {
|
|
312
|
-
const response = await this.fetchImpl(
|
|
313
|
-
`${this.baseUrl.replace(/\/$/, '')}${endpoint}`,
|
|
314
|
-
{
|
|
315
|
-
body,
|
|
316
|
-
headers,
|
|
317
|
-
method,
|
|
318
|
-
signal: controller.signal,
|
|
319
|
-
}
|
|
320
|
-
);
|
|
321
|
-
|
|
322
|
-
clearTimeout(timeoutId);
|
|
323
|
-
|
|
324
|
-
if (!response.ok) {
|
|
325
|
-
const contentType = response.headers.get('content-type');
|
|
326
|
-
if (contentType?.toLowerCase().includes('application/json')) {
|
|
327
|
-
const errorData = await response.json();
|
|
328
|
-
if (isApiErrorResponse(errorData)) {
|
|
329
|
-
throw createErrorFromResponse(errorData, response.status);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
const text = await response.text().catch(() => '');
|
|
334
|
-
throw new NetworkError(
|
|
335
|
-
`HTTP ${response.status}: ${response.statusText}${text ? ` - ${text.substring(0, 200)}` : ''}`
|
|
336
|
-
);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
if (response.status === 204) {
|
|
340
|
-
return undefined as T;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
return (await response.json()) as T;
|
|
344
|
-
} catch (error) {
|
|
345
|
-
if (error instanceof Error && error.name === 'AbortError') {
|
|
346
|
-
throw new NetworkError(`Request timeout after ${this.timeout}ms`);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
throw error;
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
async getStudio(workspaceId: string): Promise<
|
|
354
|
-
{
|
|
355
|
-
binding: WorkspaceExternalProjectBinding;
|
|
356
|
-
} & ExternalProjectStudioData
|
|
357
|
-
> {
|
|
358
|
-
this.requireApiKey();
|
|
359
|
-
const payload = await this.request<
|
|
360
|
-
{
|
|
361
|
-
binding: WorkspaceExternalProjectBinding;
|
|
362
|
-
} & ExternalProjectStudioData
|
|
363
|
-
>(`/workspaces/${encodeURIComponent(workspaceId)}/external-projects`, {
|
|
364
|
-
requiresAuth: true,
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
return normalizeStudioPayloadUrls(payload, this.baseUrl);
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
async getSummary(workspaceId: string): Promise<ExternalProjectSummary> {
|
|
371
|
-
return this.request(
|
|
372
|
-
`/workspaces/${encodeURIComponent(workspaceId)}/external-projects/summary`,
|
|
373
|
-
{
|
|
374
|
-
requiresAuth: true,
|
|
375
|
-
}
|
|
376
|
-
);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
async listCollections(workspaceId: string) {
|
|
380
|
-
return this.request(
|
|
381
|
-
`/workspaces/${encodeURIComponent(workspaceId)}/external-projects/collections`,
|
|
382
|
-
{
|
|
383
|
-
requiresAuth: true,
|
|
384
|
-
}
|
|
385
|
-
);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
async createCollection(workspaceId: string, payload: EpmCollectionPayload) {
|
|
389
|
-
return this.request(
|
|
390
|
-
`/workspaces/${encodeURIComponent(workspaceId)}/external-projects/collections`,
|
|
391
|
-
{
|
|
392
|
-
body: JSON.stringify(payload),
|
|
393
|
-
headers: { 'Content-Type': 'application/json' },
|
|
394
|
-
method: 'POST',
|
|
395
|
-
requiresAuth: true,
|
|
396
|
-
}
|
|
397
|
-
);
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
async updateCollection(
|
|
401
|
-
workspaceId: string,
|
|
402
|
-
collectionId: string,
|
|
403
|
-
payload: EpmCollectionUpdatePayload
|
|
404
|
-
) {
|
|
405
|
-
return this.request(
|
|
406
|
-
`/workspaces/${encodeURIComponent(workspaceId)}/external-projects/collections/${encodeURIComponent(collectionId)}`,
|
|
407
|
-
{
|
|
408
|
-
body: JSON.stringify(payload),
|
|
409
|
-
headers: { 'Content-Type': 'application/json' },
|
|
410
|
-
method: 'PATCH',
|
|
411
|
-
requiresAuth: true,
|
|
412
|
-
}
|
|
413
|
-
);
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
async deleteCollection(workspaceId: string, collectionId: string) {
|
|
417
|
-
return this.request(
|
|
418
|
-
`/workspaces/${encodeURIComponent(workspaceId)}/external-projects/collections/${encodeURIComponent(collectionId)}`,
|
|
419
|
-
{
|
|
420
|
-
method: 'DELETE',
|
|
421
|
-
requiresAuth: true,
|
|
422
|
-
}
|
|
423
|
-
);
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
async listEntries(workspaceId: string, options: EpmEntryListOptions = {}) {
|
|
427
|
-
const params = new URLSearchParams();
|
|
428
|
-
if (options.collectionId) {
|
|
429
|
-
params.set('collectionId', options.collectionId);
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
const suffix = params.size > 0 ? `?${params.toString()}` : '';
|
|
433
|
-
return this.request(
|
|
434
|
-
`/workspaces/${encodeURIComponent(workspaceId)}/external-projects/entries${suffix}`,
|
|
435
|
-
{
|
|
436
|
-
requiresAuth: true,
|
|
437
|
-
}
|
|
438
|
-
);
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
async createEntry(workspaceId: string, payload: EpmEntryPayload) {
|
|
442
|
-
return this.request(
|
|
443
|
-
`/workspaces/${encodeURIComponent(workspaceId)}/external-projects/entries`,
|
|
444
|
-
{
|
|
445
|
-
body: JSON.stringify(payload),
|
|
446
|
-
headers: { 'Content-Type': 'application/json' },
|
|
447
|
-
method: 'POST',
|
|
448
|
-
requiresAuth: true,
|
|
449
|
-
}
|
|
450
|
-
);
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
async updateEntry(
|
|
454
|
-
workspaceId: string,
|
|
455
|
-
entryId: string,
|
|
456
|
-
payload: EpmEntryUpdatePayload
|
|
457
|
-
) {
|
|
458
|
-
return this.request(
|
|
459
|
-
`/workspaces/${encodeURIComponent(workspaceId)}/external-projects/entries/${encodeURIComponent(entryId)}`,
|
|
460
|
-
{
|
|
461
|
-
body: JSON.stringify(payload),
|
|
462
|
-
headers: { 'Content-Type': 'application/json' },
|
|
463
|
-
method: 'PATCH',
|
|
464
|
-
requiresAuth: true,
|
|
465
|
-
}
|
|
466
|
-
);
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
async deleteEntry(workspaceId: string, entryId: string) {
|
|
470
|
-
return this.request(
|
|
471
|
-
`/workspaces/${encodeURIComponent(workspaceId)}/external-projects/entries/${encodeURIComponent(entryId)}`,
|
|
472
|
-
{
|
|
473
|
-
method: 'DELETE',
|
|
474
|
-
requiresAuth: true,
|
|
475
|
-
}
|
|
476
|
-
);
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
async duplicateEntry(workspaceId: string, entryId: string) {
|
|
480
|
-
return this.request(
|
|
481
|
-
`/workspaces/${encodeURIComponent(workspaceId)}/external-projects/entries/${encodeURIComponent(entryId)}/duplicate`,
|
|
482
|
-
{
|
|
483
|
-
method: 'POST',
|
|
484
|
-
requiresAuth: true,
|
|
485
|
-
}
|
|
486
|
-
);
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
async bulkUpdateEntries(
|
|
490
|
-
workspaceId: string,
|
|
491
|
-
payload: ExternalProjectBulkUpdatePayload
|
|
492
|
-
) {
|
|
493
|
-
return this.request(
|
|
494
|
-
`/workspaces/${encodeURIComponent(workspaceId)}/external-projects/entries/bulk`,
|
|
495
|
-
{
|
|
496
|
-
body: JSON.stringify(payload),
|
|
497
|
-
headers: { 'Content-Type': 'application/json' },
|
|
498
|
-
method: 'POST',
|
|
499
|
-
requiresAuth: true,
|
|
500
|
-
}
|
|
501
|
-
);
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
async createBlock(workspaceId: string, payload: EpmBlockPayload) {
|
|
505
|
-
return this.request(
|
|
506
|
-
`/workspaces/${encodeURIComponent(workspaceId)}/external-projects/blocks`,
|
|
507
|
-
{
|
|
508
|
-
body: JSON.stringify(payload),
|
|
509
|
-
headers: { 'Content-Type': 'application/json' },
|
|
510
|
-
method: 'POST',
|
|
511
|
-
requiresAuth: true,
|
|
512
|
-
}
|
|
513
|
-
);
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
async updateBlock(
|
|
517
|
-
workspaceId: string,
|
|
518
|
-
blockId: string,
|
|
519
|
-
payload: EpmBlockUpdatePayload
|
|
520
|
-
) {
|
|
521
|
-
return this.request(
|
|
522
|
-
`/workspaces/${encodeURIComponent(workspaceId)}/external-projects/blocks/${encodeURIComponent(blockId)}`,
|
|
523
|
-
{
|
|
524
|
-
body: JSON.stringify(payload),
|
|
525
|
-
headers: { 'Content-Type': 'application/json' },
|
|
526
|
-
method: 'PATCH',
|
|
527
|
-
requiresAuth: true,
|
|
528
|
-
}
|
|
529
|
-
);
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
async createAsset(workspaceId: string, payload: EpmAssetPayload) {
|
|
533
|
-
return this.request(
|
|
534
|
-
`/workspaces/${encodeURIComponent(workspaceId)}/external-projects/assets`,
|
|
535
|
-
{
|
|
536
|
-
body: JSON.stringify(payload),
|
|
537
|
-
headers: { 'Content-Type': 'application/json' },
|
|
538
|
-
method: 'POST',
|
|
539
|
-
requiresAuth: true,
|
|
540
|
-
}
|
|
541
|
-
);
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
async updateAsset(
|
|
545
|
-
workspaceId: string,
|
|
546
|
-
assetId: string,
|
|
547
|
-
payload: EpmAssetUpdatePayload
|
|
548
|
-
) {
|
|
549
|
-
return this.request(
|
|
550
|
-
`/workspaces/${encodeURIComponent(workspaceId)}/external-projects/assets/${encodeURIComponent(assetId)}`,
|
|
551
|
-
{
|
|
552
|
-
body: JSON.stringify(payload),
|
|
553
|
-
headers: { 'Content-Type': 'application/json' },
|
|
554
|
-
method: 'PATCH',
|
|
555
|
-
requiresAuth: true,
|
|
556
|
-
}
|
|
557
|
-
);
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
async deleteAsset(workspaceId: string, assetId: string) {
|
|
561
|
-
return this.request(
|
|
562
|
-
`/workspaces/${encodeURIComponent(workspaceId)}/external-projects/assets/${encodeURIComponent(assetId)}`,
|
|
563
|
-
{
|
|
564
|
-
method: 'DELETE',
|
|
565
|
-
requiresAuth: true,
|
|
566
|
-
}
|
|
567
|
-
);
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
async createAssetUploadUrl(
|
|
571
|
-
workspaceId: string,
|
|
572
|
-
payload: EpmAssetUploadOptions & {
|
|
573
|
-
filename: string;
|
|
574
|
-
}
|
|
575
|
-
) {
|
|
576
|
-
const response = await this.request<ExternalProjectUploadUrlResponse>(
|
|
577
|
-
`/workspaces/${encodeURIComponent(workspaceId)}/external-projects/assets/upload-url`,
|
|
578
|
-
{
|
|
579
|
-
body: JSON.stringify(payload),
|
|
580
|
-
headers: { 'Content-Type': 'application/json' },
|
|
581
|
-
method: 'POST',
|
|
582
|
-
requiresAuth: true,
|
|
583
|
-
}
|
|
584
|
-
);
|
|
585
|
-
|
|
586
|
-
return parseExternalProjectUploadPayload(response);
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
async uploadAssetFile(
|
|
590
|
-
workspaceId: string,
|
|
591
|
-
file: File,
|
|
592
|
-
options: EpmAssetUploadOptions
|
|
593
|
-
) {
|
|
594
|
-
const uploadUrl = await this.createAssetUploadUrl(workspaceId, {
|
|
595
|
-
...options,
|
|
596
|
-
filename: file.name,
|
|
597
|
-
});
|
|
598
|
-
|
|
599
|
-
return uploadExternalProjectFileWithSignedUrl(
|
|
600
|
-
file,
|
|
601
|
-
uploadUrl,
|
|
602
|
-
this.fetchImpl
|
|
603
|
-
);
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
async importContent(workspaceId: string) {
|
|
607
|
-
return this.request(
|
|
608
|
-
`/workspaces/${encodeURIComponent(workspaceId)}/external-projects/import`,
|
|
609
|
-
{
|
|
610
|
-
method: 'POST',
|
|
611
|
-
requiresAuth: true,
|
|
612
|
-
}
|
|
613
|
-
);
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
async publishEntry(
|
|
617
|
-
workspaceId: string,
|
|
618
|
-
entryId: string,
|
|
619
|
-
eventKind: EpmPublishEventKind
|
|
620
|
-
) {
|
|
621
|
-
return this.request(
|
|
622
|
-
`/workspaces/${encodeURIComponent(workspaceId)}/external-projects/entries/${encodeURIComponent(entryId)}/publish`,
|
|
623
|
-
{
|
|
624
|
-
body: JSON.stringify({ eventKind }),
|
|
625
|
-
headers: { 'Content-Type': 'application/json' },
|
|
626
|
-
method: 'POST',
|
|
627
|
-
requiresAuth: true,
|
|
628
|
-
}
|
|
629
|
-
);
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
async getDelivery(
|
|
633
|
-
workspaceId: string,
|
|
634
|
-
options: ExternalProjectDeliveryOptions = {}
|
|
635
|
-
): Promise<ExternalProjectDeliveryPayload> {
|
|
636
|
-
if (!workspaceId.trim()) {
|
|
637
|
-
throw new ValidationError('Workspace ID is required');
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
const validatedOptions =
|
|
641
|
-
externalProjectDeliveryOptionsSchema.parse(options);
|
|
642
|
-
|
|
643
|
-
if (validatedOptions.preview && !this.apiKey) {
|
|
644
|
-
throw new ValidationError(
|
|
645
|
-
'API key is required to load preview external project delivery'
|
|
646
|
-
);
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
const query = new URLSearchParams();
|
|
650
|
-
if (validatedOptions.preview) {
|
|
651
|
-
query.set('preview', 'true');
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
const suffix = query.size > 0 ? `?${query.toString()}` : '';
|
|
655
|
-
const payload = await this.request<ExternalProjectDeliveryPayload>(
|
|
656
|
-
`/workspaces/${encodeURIComponent(workspaceId)}/external-projects/delivery${suffix}`,
|
|
657
|
-
{
|
|
658
|
-
requiresAuth: validatedOptions.preview === true,
|
|
659
|
-
}
|
|
660
|
-
);
|
|
661
|
-
|
|
662
|
-
return normalizeDeliveryPayloadUrls(payload, this.baseUrl);
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
async load(
|
|
666
|
-
workspaceId: string,
|
|
667
|
-
options: ExternalProjectDeliveryOptions = {}
|
|
668
|
-
) {
|
|
669
|
-
return this.getDelivery(workspaceId, options);
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
async getLoadingData(
|
|
673
|
-
workspaceId: string,
|
|
674
|
-
options: ExternalProjectDeliveryOptions = {}
|
|
675
|
-
) {
|
|
676
|
-
const payload = await this.getDelivery(workspaceId, options);
|
|
677
|
-
return payload.loadingData;
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
async loadLoadingData(
|
|
681
|
-
workspaceId: string,
|
|
682
|
-
options: ExternalProjectDeliveryOptions = {}
|
|
683
|
-
) {
|
|
684
|
-
return this.getLoadingData(workspaceId, options);
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
async getYoolaLoadingData(
|
|
688
|
-
workspaceId: string,
|
|
689
|
-
options: ExternalProjectDeliveryOptions = {}
|
|
690
|
-
) {
|
|
691
|
-
const loadingData = await this.getLoadingData(workspaceId, options);
|
|
692
|
-
|
|
693
|
-
if (!isYoolaExternalProjectLoadingData(loadingData)) {
|
|
694
|
-
throw new ValidationError(
|
|
695
|
-
'External project delivery is not using the yoola adapter'
|
|
696
|
-
);
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
return loadingData;
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
getAssetUrl(workspaceId: string, assetId: string) {
|
|
703
|
-
if (!workspaceId.trim() || !assetId.trim()) {
|
|
704
|
-
throw new ValidationError('Workspace ID and asset ID are required');
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
return `${this.baseUrl.replace(/\/$/, '')}/workspaces/${encodeURIComponent(
|
|
708
|
-
workspaceId
|
|
709
|
-
)}/external-projects/assets/${encodeURIComponent(assetId)}`;
|
|
710
|
-
}
|
|
711
|
-
}
|