@playdrop/playdrop-cli 0.3.4-build.1 → 0.3.5-build.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/README.md +60 -23
- package/config/client-meta.json +5 -5
- package/dist/apps/upload.js +5 -3
- package/dist/assets/model-artifacts.js +1 -1
- package/dist/catalogue.d.ts +6 -0
- package/dist/catalogue.js +38 -1
- package/dist/commandContext.d.ts +1 -0
- package/dist/commandContext.js +45 -15
- package/dist/commands/browse.d.ts +16 -0
- package/dist/commands/browse.js +370 -0
- package/dist/commands/build.js +4 -9
- package/dist/commands/capture.js +24 -24
- package/dist/commands/captureRemote.d.ts +11 -0
- package/dist/commands/captureRemote.js +90 -0
- package/dist/commands/comments.d.ts +14 -0
- package/dist/commands/comments.js +189 -0
- package/dist/commands/create.js +112 -72
- package/dist/commands/creations.d.ts +49 -0
- package/dist/commands/creations.js +657 -0
- package/dist/commands/credits.d.ts +10 -0
- package/dist/commands/credits.js +91 -0
- package/dist/commands/detail.d.ts +2 -2
- package/dist/commands/detail.js +148 -290
- package/dist/commands/dev.js +24 -24
- package/dist/commands/devShared.js +2 -2
- package/dist/commands/documentation.d.ts +4 -1
- package/dist/commands/documentation.js +79 -104
- package/dist/commands/feedback.d.ts +12 -9
- package/dist/commands/feedback.js +125 -257
- package/dist/commands/format.js +6 -13
- package/dist/commands/generation.d.ts +11 -0
- package/dist/commands/generation.js +204 -42
- package/dist/commands/gettingStarted.d.ts +1 -0
- package/dist/commands/gettingStarted.js +26 -0
- package/dist/commands/init.js +26 -24
- package/dist/commands/login.js +9 -8
- package/dist/commands/logout.js +2 -1
- package/dist/commands/notifications.d.ts +14 -0
- package/dist/commands/notifications.js +179 -0
- package/dist/commands/search.d.ts +13 -0
- package/dist/commands/search.js +198 -0
- package/dist/commands/upload.js +20 -17
- package/dist/commands/validate.js +15 -1
- package/dist/commands/versionsBrowse.d.ts +7 -0
- package/dist/commands/versionsBrowse.js +209 -0
- package/dist/commands/whoami.js +9 -8
- package/dist/errors.d.ts +9 -0
- package/dist/errors.js +52 -0
- package/dist/externalAssetPackValidation.d.ts +2 -0
- package/dist/externalAssetPackValidation.js +115 -0
- package/dist/http.js +1 -1
- package/dist/index.js +570 -630
- package/dist/messages.js +11 -11
- package/dist/output.d.ts +5 -0
- package/dist/output.js +45 -0
- package/dist/playwright.js +1 -1
- package/dist/refs.d.ts +18 -0
- package/dist/refs.js +105 -0
- package/node_modules/@playdrop/ai-client/dist/index.d.ts +42 -15
- package/node_modules/@playdrop/ai-client/dist/index.d.ts.map +1 -1
- package/node_modules/@playdrop/ai-client/package.json +1 -0
- package/node_modules/@playdrop/api-client/dist/client.d.ts +39 -27
- package/node_modules/@playdrop/api-client/dist/client.d.ts.map +1 -1
- package/node_modules/@playdrop/api-client/dist/client.js +280 -1669
- package/node_modules/@playdrop/api-client/dist/core/errors.d.ts +9 -0
- package/node_modules/@playdrop/api-client/dist/core/errors.d.ts.map +1 -0
- package/node_modules/@playdrop/api-client/dist/core/errors.js +46 -0
- package/node_modules/@playdrop/api-client/dist/core/request.d.ts +27 -0
- package/node_modules/@playdrop/api-client/dist/core/request.d.ts.map +1 -0
- package/node_modules/@playdrop/api-client/dist/core/request.js +122 -0
- package/node_modules/@playdrop/api-client/dist/domains/admin.d.ts +75 -0
- package/node_modules/@playdrop/api-client/dist/domains/admin.d.ts.map +1 -0
- package/node_modules/@playdrop/api-client/dist/domains/admin.js +282 -0
- package/node_modules/@playdrop/api-client/dist/domains/ai.d.ts +22 -0
- package/node_modules/@playdrop/api-client/dist/domains/ai.d.ts.map +1 -0
- package/node_modules/@playdrop/api-client/dist/domains/ai.js +15 -0
- package/node_modules/@playdrop/api-client/dist/domains/apps.d.ts +60 -0
- package/node_modules/@playdrop/api-client/dist/domains/apps.d.ts.map +1 -0
- package/node_modules/@playdrop/api-client/dist/domains/apps.js +301 -0
- package/node_modules/@playdrop/api-client/dist/domains/asset-packs.d.ts +59 -0
- package/node_modules/@playdrop/api-client/dist/domains/asset-packs.d.ts.map +1 -0
- package/node_modules/@playdrop/api-client/dist/domains/asset-packs.js +297 -0
- package/node_modules/@playdrop/api-client/dist/domains/assets.d.ts +62 -0
- package/node_modules/@playdrop/api-client/dist/domains/assets.d.ts.map +1 -0
- package/node_modules/@playdrop/api-client/dist/domains/assets.js +297 -0
- package/node_modules/@playdrop/api-client/dist/domains/auth.d.ts +28 -0
- package/node_modules/@playdrop/api-client/dist/domains/auth.d.ts.map +1 -0
- package/node_modules/@playdrop/api-client/dist/domains/auth.js +78 -0
- package/node_modules/@playdrop/api-client/dist/domains/comments.d.ts +29 -0
- package/node_modules/@playdrop/api-client/dist/domains/comments.d.ts.map +1 -0
- package/node_modules/@playdrop/api-client/dist/domains/comments.js +65 -0
- package/node_modules/@playdrop/api-client/dist/domains/me.d.ts +24 -0
- package/node_modules/@playdrop/api-client/dist/domains/me.d.ts.map +1 -0
- package/node_modules/@playdrop/api-client/dist/domains/me.js +35 -0
- package/node_modules/@playdrop/api-client/dist/domains/payments.d.ts +37 -0
- package/node_modules/@playdrop/api-client/dist/domains/payments.d.ts.map +1 -0
- package/node_modules/@playdrop/api-client/dist/domains/payments.js +148 -0
- package/node_modules/@playdrop/api-client/dist/domains/search.d.ts +27 -0
- package/node_modules/@playdrop/api-client/dist/domains/search.d.ts.map +1 -0
- package/node_modules/@playdrop/api-client/dist/domains/search.js +65 -0
- package/node_modules/@playdrop/api-client/dist/index.d.ts +33 -56
- package/node_modules/@playdrop/api-client/dist/index.d.ts.map +1 -1
- package/node_modules/@playdrop/api-client/dist/index.js +103 -44
- package/node_modules/@playdrop/api-client/package.json +3 -2
- package/node_modules/@playdrop/boxel-core/package.json +1 -1
- package/node_modules/@playdrop/boxel-three/dist/test/glb-skinned.test.js +1 -1
- package/node_modules/@playdrop/boxel-three/dist/test/instantiate.test.js +1 -1
- package/node_modules/@playdrop/boxel-three/dist/test/skinned-mesh.test.js +1 -1
- package/node_modules/@playdrop/boxel-three/package.json +2 -1
- package/node_modules/@playdrop/config/client-meta.json +5 -5
- package/node_modules/@playdrop/config/dist/src/constants.d.ts +5 -0
- package/node_modules/@playdrop/config/dist/src/constants.d.ts.map +1 -1
- package/node_modules/@playdrop/config/dist/src/constants.js +5 -1
- package/node_modules/@playdrop/config/dist/tsconfig.tsbuildinfo +1 -1
- package/node_modules/@playdrop/config/package.json +1 -1
- package/node_modules/@playdrop/types/dist/api.d.ts +178 -17
- package/node_modules/@playdrop/types/dist/api.d.ts.map +1 -1
- package/node_modules/@playdrop/types/dist/api.js +30 -1
- package/node_modules/@playdrop/types/dist/app.d.ts +0 -14
- package/node_modules/@playdrop/types/dist/app.d.ts.map +1 -1
- package/node_modules/@playdrop/types/dist/app.js +0 -10
- package/node_modules/@playdrop/types/dist/asset-pack.d.ts +11 -1
- package/node_modules/@playdrop/types/dist/asset-pack.d.ts.map +1 -1
- package/node_modules/@playdrop/types/dist/asset.d.ts +65 -0
- package/node_modules/@playdrop/types/dist/asset.d.ts.map +1 -1
- package/node_modules/@playdrop/types/dist/realtime.d.ts +26 -26
- package/node_modules/@playdrop/types/dist/realtime.d.ts.map +1 -1
- package/node_modules/@playdrop/types/dist/version.d.ts +5 -0
- package/node_modules/@playdrop/types/dist/version.d.ts.map +1 -1
- package/package.json +2 -3
- package/bin/playdrop-cli +0 -2
- package/dist/commands/asset-packs.d.ts +0 -27
- package/dist/commands/asset-packs.js +0 -508
- package/dist/commands/assets.d.ts +0 -35
- package/dist/commands/assets.js +0 -668
- package/dist/commands/list.d.ts +0 -7
- package/dist/commands/list.js +0 -347
- package/dist/commands/migrateCatalogueV2.d.ts +0 -1
- package/dist/commands/migrateCatalogueV2.js +0 -142
- package/dist/commands/versions.d.ts +0 -17
- package/dist/commands/versions.js +0 -384
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
export function buildAssetPacksApiClientMethods(input) {
|
|
2
|
+
const { request, handleApiError, fetchImpl, resolveBaseUrl, resolveUrl, parseResponseBody, resolveToken, getClientHeaders, buildCreatorAssetPackMutationPath, normalizeSemverInput, parseContentDispositionFilename, } = input;
|
|
3
|
+
return {
|
|
4
|
+
async createAssetPackVersion(creatorUsername, name, body) {
|
|
5
|
+
const packName = typeof name === 'string' ? name.trim() : '';
|
|
6
|
+
if (!packName) {
|
|
7
|
+
throw new Error('invalid_pack_name');
|
|
8
|
+
}
|
|
9
|
+
const response = await request({
|
|
10
|
+
method: 'POST',
|
|
11
|
+
path: `${buildCreatorAssetPackMutationPath(creatorUsername, packName)}/versions`,
|
|
12
|
+
body,
|
|
13
|
+
});
|
|
14
|
+
if (response.status !== 201 && response.status !== 200) {
|
|
15
|
+
handleApiError(response, 'create_asset_pack_version');
|
|
16
|
+
}
|
|
17
|
+
return response.body;
|
|
18
|
+
},
|
|
19
|
+
async uploadAssetPackVersion(creatorUsername, name, options) {
|
|
20
|
+
const packName = typeof name === 'string' ? name.trim() : '';
|
|
21
|
+
if (!packName) {
|
|
22
|
+
throw new Error('invalid_pack_name');
|
|
23
|
+
}
|
|
24
|
+
if (!options || !options.request) {
|
|
25
|
+
throw new Error('invalid_pack_upload_request');
|
|
26
|
+
}
|
|
27
|
+
const requestBody = options.request;
|
|
28
|
+
const form = new FormData();
|
|
29
|
+
form.append('version', requestBody.version);
|
|
30
|
+
if (requestBody.visibility !== undefined) {
|
|
31
|
+
form.append('visibility', requestBody.visibility);
|
|
32
|
+
}
|
|
33
|
+
if (requestBody.hostingMode !== undefined) {
|
|
34
|
+
form.append('hostingMode', requestBody.hostingMode);
|
|
35
|
+
}
|
|
36
|
+
if (requestBody.externalUrl !== undefined) {
|
|
37
|
+
form.append('externalUrl', requestBody.externalUrl);
|
|
38
|
+
}
|
|
39
|
+
if (requestBody.downloadUrl !== undefined) {
|
|
40
|
+
form.append('downloadUrl', requestBody.downloadUrl);
|
|
41
|
+
}
|
|
42
|
+
if (requestBody.releaseNotes !== undefined) {
|
|
43
|
+
form.append('releaseNotes', requestBody.releaseNotes);
|
|
44
|
+
}
|
|
45
|
+
if (requestBody.displayName !== undefined) {
|
|
46
|
+
form.append('displayName', requestBody.displayName);
|
|
47
|
+
}
|
|
48
|
+
if (requestBody.description !== undefined) {
|
|
49
|
+
form.append('description', requestBody.description);
|
|
50
|
+
}
|
|
51
|
+
if (requestBody.previewAppVersionId !== undefined) {
|
|
52
|
+
form.append('previewAppVersionId', String(requestBody.previewAppVersionId));
|
|
53
|
+
}
|
|
54
|
+
form.append('assets', JSON.stringify(requestBody.assets ?? []));
|
|
55
|
+
const relations = requestBody.relations;
|
|
56
|
+
if (Array.isArray(relations) && relations.length > 0) {
|
|
57
|
+
form.append('relations', JSON.stringify(relations));
|
|
58
|
+
}
|
|
59
|
+
if (options.icon) {
|
|
60
|
+
form.append('icon', options.icon);
|
|
61
|
+
}
|
|
62
|
+
if (options.heroPortrait) {
|
|
63
|
+
form.append('heroPortrait', options.heroPortrait);
|
|
64
|
+
}
|
|
65
|
+
if (options.heroLandscape) {
|
|
66
|
+
form.append('heroLandscape', options.heroLandscape);
|
|
67
|
+
}
|
|
68
|
+
if (options.screenshotsPortrait) {
|
|
69
|
+
for (const screenshot of options.screenshotsPortrait) {
|
|
70
|
+
form.append('screenshotsPortrait', screenshot);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (options.screenshotsLandscape) {
|
|
74
|
+
for (const screenshot of options.screenshotsLandscape) {
|
|
75
|
+
form.append('screenshotsLandscape', screenshot);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (options.videosPortrait) {
|
|
79
|
+
for (const video of options.videosPortrait) {
|
|
80
|
+
form.append('videosPortrait', video);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (options.videosLandscape) {
|
|
84
|
+
for (const video of options.videosLandscape) {
|
|
85
|
+
form.append('videosLandscape', video);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const path = `${buildCreatorAssetPackMutationPath(creatorUsername, packName)}/versions`;
|
|
89
|
+
const base = resolveBaseUrl();
|
|
90
|
+
const headers = new Headers();
|
|
91
|
+
for (const [key, value] of Object.entries(getClientHeaders())) {
|
|
92
|
+
headers.set(key, value);
|
|
93
|
+
}
|
|
94
|
+
const token = await resolveToken();
|
|
95
|
+
if (token) {
|
|
96
|
+
headers.set('authorization', `Bearer ${token}`);
|
|
97
|
+
}
|
|
98
|
+
const response = await fetchImpl(resolveUrl(base, path), {
|
|
99
|
+
method: 'POST',
|
|
100
|
+
headers,
|
|
101
|
+
body: form,
|
|
102
|
+
});
|
|
103
|
+
const parsed = await parseResponseBody(response);
|
|
104
|
+
const apiResponse = { status: response.status, body: parsed, headers: response.headers };
|
|
105
|
+
if (response.status !== 201 && response.status !== 200) {
|
|
106
|
+
handleApiError(apiResponse, 'upload_asset_pack_version');
|
|
107
|
+
}
|
|
108
|
+
return parsed;
|
|
109
|
+
},
|
|
110
|
+
async listAssetPacks(options = {}) {
|
|
111
|
+
const params = new URLSearchParams();
|
|
112
|
+
if (typeof options.limit === 'number') {
|
|
113
|
+
params.set('limit', String(options.limit));
|
|
114
|
+
}
|
|
115
|
+
if (typeof options.offset === 'number') {
|
|
116
|
+
params.set('offset', String(options.offset));
|
|
117
|
+
}
|
|
118
|
+
if (typeof options.containsCategory === 'string' && options.containsCategory.trim().length > 0) {
|
|
119
|
+
params.set('containsCategory', options.containsCategory.trim());
|
|
120
|
+
}
|
|
121
|
+
if (typeof options.containsSubcategory === 'string' && options.containsSubcategory.trim().length > 0) {
|
|
122
|
+
params.set('containsSubcategory', options.containsSubcategory.trim());
|
|
123
|
+
}
|
|
124
|
+
const query = params.toString();
|
|
125
|
+
const path = `/asset-packs${query ? `?${query}` : ''}`;
|
|
126
|
+
const response = await request({
|
|
127
|
+
method: 'GET',
|
|
128
|
+
path,
|
|
129
|
+
});
|
|
130
|
+
if (response.status !== 200) {
|
|
131
|
+
handleApiError(response, 'list_asset_packs');
|
|
132
|
+
}
|
|
133
|
+
return response.body;
|
|
134
|
+
},
|
|
135
|
+
async listAssetPacksForCreator(creatorUsername, options = {}) {
|
|
136
|
+
const params = new URLSearchParams();
|
|
137
|
+
if (typeof options.limit === 'number') {
|
|
138
|
+
params.set('limit', String(options.limit));
|
|
139
|
+
}
|
|
140
|
+
if (typeof options.offset === 'number') {
|
|
141
|
+
params.set('offset', String(options.offset));
|
|
142
|
+
}
|
|
143
|
+
if (typeof options.containsCategory === 'string' && options.containsCategory.trim().length > 0) {
|
|
144
|
+
params.set('containsCategory', options.containsCategory.trim());
|
|
145
|
+
}
|
|
146
|
+
if (typeof options.containsSubcategory === 'string' && options.containsSubcategory.trim().length > 0) {
|
|
147
|
+
params.set('containsSubcategory', options.containsSubcategory.trim());
|
|
148
|
+
}
|
|
149
|
+
const query = params.toString();
|
|
150
|
+
const path = `/creators/${encodeURIComponent(creatorUsername)}/asset-packs${query ? `?${query}` : ''}`;
|
|
151
|
+
const response = await request({
|
|
152
|
+
method: 'GET',
|
|
153
|
+
path,
|
|
154
|
+
});
|
|
155
|
+
if (response.status !== 200) {
|
|
156
|
+
handleApiError(response, 'list_asset_packs_for_creator');
|
|
157
|
+
}
|
|
158
|
+
return response.body;
|
|
159
|
+
},
|
|
160
|
+
async fetchAssetPackBySlug(creatorUsername, packName) {
|
|
161
|
+
const path = `/asset-packs/${encodeURIComponent(creatorUsername)}/${encodeURIComponent(packName)}`;
|
|
162
|
+
const response = await request({
|
|
163
|
+
method: 'GET',
|
|
164
|
+
path,
|
|
165
|
+
});
|
|
166
|
+
if (response.status !== 200) {
|
|
167
|
+
handleApiError(response, 'fetch_asset_pack_by_slug');
|
|
168
|
+
}
|
|
169
|
+
return response.body;
|
|
170
|
+
},
|
|
171
|
+
async downloadAssetPackSource(creatorUsername, packName, version) {
|
|
172
|
+
const creator = typeof creatorUsername === 'string' ? creatorUsername.trim() : '';
|
|
173
|
+
const name = typeof packName === 'string' ? packName.trim() : '';
|
|
174
|
+
if (!creator || !name) {
|
|
175
|
+
throw new Error('invalid_pack_key');
|
|
176
|
+
}
|
|
177
|
+
const normalizedVersion = normalizeSemverInput(version);
|
|
178
|
+
const path = `/asset-packs/${encodeURIComponent(creator)}/${encodeURIComponent(name)}/versions/${encodeURIComponent(normalizedVersion)}/source`;
|
|
179
|
+
const base = resolveBaseUrl();
|
|
180
|
+
const headers = new Headers();
|
|
181
|
+
for (const [key, value] of Object.entries(getClientHeaders())) {
|
|
182
|
+
headers.set(key, value);
|
|
183
|
+
}
|
|
184
|
+
const token = await resolveToken();
|
|
185
|
+
if (token) {
|
|
186
|
+
headers.set('authorization', `Bearer ${token}`);
|
|
187
|
+
}
|
|
188
|
+
const response = await fetchImpl(resolveUrl(base, path), {
|
|
189
|
+
method: 'GET',
|
|
190
|
+
headers,
|
|
191
|
+
});
|
|
192
|
+
if (!response.ok) {
|
|
193
|
+
const parsed = await parseResponseBody(response);
|
|
194
|
+
handleApiError({ status: response.status, body: parsed, headers: response.headers }, 'download_asset_pack_source');
|
|
195
|
+
}
|
|
196
|
+
const blob = await response.blob();
|
|
197
|
+
const filename = parseContentDispositionFilename(response.headers.get('content-disposition'))
|
|
198
|
+
?? `${name}-${normalizedVersion}-source.zip`;
|
|
199
|
+
const headerSize = response.headers.get('content-length');
|
|
200
|
+
const parsedSize = headerSize ? Number.parseInt(headerSize, 10) : Number.NaN;
|
|
201
|
+
const checksumHeader = response.headers.get('x-pack-source-checksum');
|
|
202
|
+
return {
|
|
203
|
+
blob,
|
|
204
|
+
metadata: {
|
|
205
|
+
filename,
|
|
206
|
+
sizeBytes: Number.isFinite(parsedSize) && parsedSize >= 0 ? parsedSize : blob.size,
|
|
207
|
+
checksum: checksumHeader ?? null,
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
},
|
|
211
|
+
async listAssetPackVersions(creatorUsername, packName, options = {}) {
|
|
212
|
+
const params = new URLSearchParams();
|
|
213
|
+
if (typeof options.limit === 'number') {
|
|
214
|
+
params.set('limit', String(options.limit));
|
|
215
|
+
}
|
|
216
|
+
if (typeof options.offset === 'number') {
|
|
217
|
+
params.set('offset', String(options.offset));
|
|
218
|
+
}
|
|
219
|
+
const query = params.toString();
|
|
220
|
+
const path = `/asset-packs/${encodeURIComponent(creatorUsername)}/${encodeURIComponent(packName)}/versions${query ? `?${query}` : ''}`;
|
|
221
|
+
const response = await request({
|
|
222
|
+
method: 'GET',
|
|
223
|
+
path,
|
|
224
|
+
});
|
|
225
|
+
if (response.status !== 200) {
|
|
226
|
+
handleApiError(response, 'list_asset_pack_versions');
|
|
227
|
+
}
|
|
228
|
+
return response.body;
|
|
229
|
+
},
|
|
230
|
+
async updateAssetPack(creatorUsername, name, requestBody) {
|
|
231
|
+
const packName = typeof name === 'string' ? name.trim() : '';
|
|
232
|
+
if (!packName) {
|
|
233
|
+
throw new Error('invalid_pack_name');
|
|
234
|
+
}
|
|
235
|
+
const response = await request({
|
|
236
|
+
method: 'PATCH',
|
|
237
|
+
path: buildCreatorAssetPackMutationPath(creatorUsername, packName),
|
|
238
|
+
body: requestBody,
|
|
239
|
+
});
|
|
240
|
+
if (response.status !== 200) {
|
|
241
|
+
handleApiError(response, 'update_asset_pack');
|
|
242
|
+
}
|
|
243
|
+
return response.body;
|
|
244
|
+
},
|
|
245
|
+
async updateAssetPackVersion(creatorUsername, name, version, requestBody) {
|
|
246
|
+
const packName = typeof name === 'string' ? name.trim() : '';
|
|
247
|
+
const versionValue = typeof version === 'string' ? version.trim() : '';
|
|
248
|
+
if (!packName) {
|
|
249
|
+
throw new Error('invalid_pack_name');
|
|
250
|
+
}
|
|
251
|
+
if (!versionValue) {
|
|
252
|
+
throw new Error('invalid_pack_version');
|
|
253
|
+
}
|
|
254
|
+
const response = await request({
|
|
255
|
+
method: 'PATCH',
|
|
256
|
+
path: `${buildCreatorAssetPackMutationPath(creatorUsername, packName)}/versions/${encodeURIComponent(versionValue)}`,
|
|
257
|
+
body: requestBody,
|
|
258
|
+
});
|
|
259
|
+
if (response.status !== 200) {
|
|
260
|
+
handleApiError(response, 'update_asset_pack_version');
|
|
261
|
+
}
|
|
262
|
+
return response.body;
|
|
263
|
+
},
|
|
264
|
+
async deleteAssetPackVersion(creatorUsername, name, version) {
|
|
265
|
+
const packName = typeof name === 'string' ? name.trim() : '';
|
|
266
|
+
const versionValue = typeof version === 'string' ? version.trim() : '';
|
|
267
|
+
if (!packName) {
|
|
268
|
+
throw new Error('invalid_pack_name');
|
|
269
|
+
}
|
|
270
|
+
if (!versionValue) {
|
|
271
|
+
throw new Error('invalid_pack_version');
|
|
272
|
+
}
|
|
273
|
+
const response = await request({
|
|
274
|
+
method: 'DELETE',
|
|
275
|
+
path: `${buildCreatorAssetPackMutationPath(creatorUsername, packName)}/versions/${encodeURIComponent(versionValue)}`,
|
|
276
|
+
});
|
|
277
|
+
if (response.status !== 200) {
|
|
278
|
+
handleApiError(response, 'delete_asset_pack_version');
|
|
279
|
+
}
|
|
280
|
+
return response.body;
|
|
281
|
+
},
|
|
282
|
+
async deleteAssetPack(creatorUsername, name) {
|
|
283
|
+
const packName = typeof name === 'string' ? name.trim() : '';
|
|
284
|
+
if (!packName) {
|
|
285
|
+
throw new Error('invalid_pack_name');
|
|
286
|
+
}
|
|
287
|
+
const response = await request({
|
|
288
|
+
method: 'DELETE',
|
|
289
|
+
path: buildCreatorAssetPackMutationPath(creatorUsername, packName),
|
|
290
|
+
});
|
|
291
|
+
if (response.status !== 200) {
|
|
292
|
+
handleApiError(response, 'delete_asset_pack');
|
|
293
|
+
}
|
|
294
|
+
return response.body;
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { AssetCategoriesResponse, AssetCategory, AssetDetailResponse, AssetListResponse, AssetSourceBundleResponse, AssetVersionsListResponse, CreateAssetVersionResponse, DeleteAssetResponse, DeleteAssetVersionResponse, UpdateAssetRequest, UpdateAssetResponse, UpdateAssetVersionRequest, UpdateAssetVersionResponse } from '@playdrop/types';
|
|
2
|
+
import type { UploadAssetVersionOptions } from '../client.js';
|
|
3
|
+
type ApiResponseLike<T> = {
|
|
4
|
+
status: number;
|
|
5
|
+
body: T;
|
|
6
|
+
headers: Headers;
|
|
7
|
+
};
|
|
8
|
+
type RequestExecutor = <T>(input: {
|
|
9
|
+
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
10
|
+
path: string;
|
|
11
|
+
body?: unknown;
|
|
12
|
+
headers?: Record<string, string>;
|
|
13
|
+
signal?: AbortSignal;
|
|
14
|
+
}) => Promise<ApiResponseLike<T>>;
|
|
15
|
+
type ErrorHandler = (response: ApiResponseLike<unknown>, defaultMessage: string) => never;
|
|
16
|
+
type ParseResponseBody = <T>(response: Response) => Promise<T>;
|
|
17
|
+
export declare function buildAssetsApiClientMethods(input: {
|
|
18
|
+
request: RequestExecutor;
|
|
19
|
+
handleApiError: ErrorHandler;
|
|
20
|
+
fetchImpl: typeof fetch;
|
|
21
|
+
resolveBaseUrl: () => string;
|
|
22
|
+
resolveUrl: (base: string, path: string) => string;
|
|
23
|
+
parseResponseBody: ParseResponseBody;
|
|
24
|
+
resolveToken: () => Promise<string | null>;
|
|
25
|
+
getClientHeaders: () => Record<string, string>;
|
|
26
|
+
buildCreatorAssetMutationPath: (creatorUsername: string, assetName?: string, suffix?: string) => string;
|
|
27
|
+
normalizeAssetRevisionInput: (revision: string | number) => string;
|
|
28
|
+
parseContentDispositionFilename: (headerValue: string | null) => string | null;
|
|
29
|
+
}): {
|
|
30
|
+
createAssetVersion(creatorUsername: string, name: string, options: UploadAssetVersionOptions): Promise<CreateAssetVersionResponse>;
|
|
31
|
+
listAssetCategories(): Promise<AssetCategoriesResponse>;
|
|
32
|
+
listAssets(options?: {
|
|
33
|
+
limit?: number;
|
|
34
|
+
offset?: number;
|
|
35
|
+
category?: AssetCategory;
|
|
36
|
+
subcategory?: string;
|
|
37
|
+
}): Promise<AssetListResponse>;
|
|
38
|
+
listAssetsForCreator(creatorUsername: string, options?: {
|
|
39
|
+
limit?: number;
|
|
40
|
+
offset?: number;
|
|
41
|
+
category?: AssetCategory;
|
|
42
|
+
subcategory?: string;
|
|
43
|
+
}): Promise<AssetListResponse>;
|
|
44
|
+
fetchAssetBySlug(creatorUsername: string, assetName: string): Promise<AssetDetailResponse>;
|
|
45
|
+
listAssetVersions(creatorUsername: string, assetName: string, options?: {
|
|
46
|
+
limit?: number;
|
|
47
|
+
offset?: number;
|
|
48
|
+
}): Promise<AssetVersionsListResponse>;
|
|
49
|
+
updateAsset(creatorUsername: string, name: string, requestBody: UpdateAssetRequest): Promise<UpdateAssetResponse>;
|
|
50
|
+
updateAssetVersion(creatorUsername: string, name: string, revision: string | number, requestBody: UpdateAssetVersionRequest): Promise<UpdateAssetVersionResponse>;
|
|
51
|
+
deleteAssetVersion(creatorUsername: string, name: string, revision: string | number): Promise<DeleteAssetVersionResponse>;
|
|
52
|
+
deleteAsset(creatorUsername: string, name: string): Promise<DeleteAssetResponse>;
|
|
53
|
+
downloadAssetFile(creatorUsername: string, assetName: string, revision: string | number, options?: {
|
|
54
|
+
role?: string;
|
|
55
|
+
}): Promise<Blob>;
|
|
56
|
+
downloadAssetSource(creatorUsername: string, assetName: string, revision: string | number): Promise<{
|
|
57
|
+
blob: Blob;
|
|
58
|
+
metadata: AssetSourceBundleResponse;
|
|
59
|
+
}>;
|
|
60
|
+
};
|
|
61
|
+
export {};
|
|
62
|
+
//# sourceMappingURL=assets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../../src/domains/assets.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
export function buildAssetsApiClientMethods(input) {
|
|
2
|
+
const { request, handleApiError, fetchImpl, resolveBaseUrl, resolveUrl, parseResponseBody, resolveToken, getClientHeaders, buildCreatorAssetMutationPath, normalizeAssetRevisionInput, parseContentDispositionFilename, } = input;
|
|
3
|
+
return {
|
|
4
|
+
async createAssetVersion(creatorUsername, name, options) {
|
|
5
|
+
const assetName = typeof name === 'string' ? name.trim() : '';
|
|
6
|
+
if (!assetName) {
|
|
7
|
+
throw new Error('invalid_asset_name');
|
|
8
|
+
}
|
|
9
|
+
if (!Array.isArray(options.files) || options.files.length === 0) {
|
|
10
|
+
throw new Error('missing_asset_files');
|
|
11
|
+
}
|
|
12
|
+
const form = new FormData();
|
|
13
|
+
form.set('category', options.category);
|
|
14
|
+
form.set('subcategory', options.subcategory);
|
|
15
|
+
form.set('format', options.format);
|
|
16
|
+
if (options.visibility) {
|
|
17
|
+
form.set('visibility', options.visibility);
|
|
18
|
+
}
|
|
19
|
+
if (options.sourceKind) {
|
|
20
|
+
form.set('sourceKind', options.sourceKind);
|
|
21
|
+
}
|
|
22
|
+
if (typeof options.sourceAppVersionId === 'number') {
|
|
23
|
+
form.set('sourceAppVersionId', String(options.sourceAppVersionId));
|
|
24
|
+
}
|
|
25
|
+
if (typeof options.sourceGenerationId === 'string' && options.sourceGenerationId.trim().length > 0) {
|
|
26
|
+
form.set('sourceGenerationId', options.sourceGenerationId.trim());
|
|
27
|
+
}
|
|
28
|
+
if (typeof options.shopListed === 'boolean') {
|
|
29
|
+
form.set('shopListed', options.shopListed ? 'true' : 'false');
|
|
30
|
+
}
|
|
31
|
+
if (typeof options.shopPriceCredits === 'number') {
|
|
32
|
+
form.set('shopPriceCredits', String(options.shopPriceCredits));
|
|
33
|
+
}
|
|
34
|
+
if (typeof options.displayName === 'string' && options.displayName.trim().length > 0) {
|
|
35
|
+
form.set('displayName', options.displayName.trim());
|
|
36
|
+
}
|
|
37
|
+
if (typeof options.description === 'string') {
|
|
38
|
+
form.set('description', options.description);
|
|
39
|
+
}
|
|
40
|
+
for (let index = 0; index < options.files.length; index++) {
|
|
41
|
+
const item = options.files[index];
|
|
42
|
+
const fieldName = typeof item.fieldName === 'string' && item.fieldName.trim().length > 0
|
|
43
|
+
? item.fieldName.trim()
|
|
44
|
+
: 'file';
|
|
45
|
+
if (typeof item.filename === 'string' && item.filename.trim().length > 0) {
|
|
46
|
+
form.append(fieldName, item.file, item.filename.trim());
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
form.append(fieldName, item.file);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const base = resolveBaseUrl();
|
|
53
|
+
const headers = new Headers();
|
|
54
|
+
for (const [key, value] of Object.entries(getClientHeaders())) {
|
|
55
|
+
headers.set(key, value);
|
|
56
|
+
}
|
|
57
|
+
const token = await resolveToken();
|
|
58
|
+
if (token) {
|
|
59
|
+
headers.set('authorization', `Bearer ${token}`);
|
|
60
|
+
}
|
|
61
|
+
const path = `${buildCreatorAssetMutationPath(creatorUsername, assetName)}/versions`;
|
|
62
|
+
const response = await fetchImpl(resolveUrl(base, path), {
|
|
63
|
+
method: 'POST',
|
|
64
|
+
headers,
|
|
65
|
+
body: form,
|
|
66
|
+
});
|
|
67
|
+
const parsed = await parseResponseBody(response);
|
|
68
|
+
const apiResponse = { status: response.status, body: parsed, headers: response.headers };
|
|
69
|
+
if (response.status !== 201 && response.status !== 200) {
|
|
70
|
+
handleApiError(apiResponse, 'create_asset_version');
|
|
71
|
+
}
|
|
72
|
+
return parsed;
|
|
73
|
+
},
|
|
74
|
+
async listAssetCategories() {
|
|
75
|
+
const response = await request({
|
|
76
|
+
method: 'GET',
|
|
77
|
+
path: '/asset-categories',
|
|
78
|
+
});
|
|
79
|
+
if (response.status !== 200) {
|
|
80
|
+
handleApiError(response, 'list_asset_categories');
|
|
81
|
+
}
|
|
82
|
+
return response.body;
|
|
83
|
+
},
|
|
84
|
+
async listAssets(options = {}) {
|
|
85
|
+
const params = new URLSearchParams();
|
|
86
|
+
if (typeof options.limit === 'number') {
|
|
87
|
+
params.set('limit', String(options.limit));
|
|
88
|
+
}
|
|
89
|
+
if (typeof options.offset === 'number') {
|
|
90
|
+
params.set('offset', String(options.offset));
|
|
91
|
+
}
|
|
92
|
+
if (typeof options.category === 'string' && options.category.trim().length > 0) {
|
|
93
|
+
params.set('category', options.category.trim());
|
|
94
|
+
}
|
|
95
|
+
if (typeof options.subcategory === 'string' && options.subcategory.trim().length > 0) {
|
|
96
|
+
params.set('subcategory', options.subcategory.trim());
|
|
97
|
+
}
|
|
98
|
+
const query = params.toString();
|
|
99
|
+
const path = `/assets${query ? `?${query}` : ''}`;
|
|
100
|
+
const response = await request({
|
|
101
|
+
method: 'GET',
|
|
102
|
+
path,
|
|
103
|
+
});
|
|
104
|
+
if (response.status !== 200) {
|
|
105
|
+
handleApiError(response, 'list_assets');
|
|
106
|
+
}
|
|
107
|
+
return response.body;
|
|
108
|
+
},
|
|
109
|
+
async listAssetsForCreator(creatorUsername, options = {}) {
|
|
110
|
+
const params = new URLSearchParams();
|
|
111
|
+
if (typeof options.limit === 'number') {
|
|
112
|
+
params.set('limit', String(options.limit));
|
|
113
|
+
}
|
|
114
|
+
if (typeof options.offset === 'number') {
|
|
115
|
+
params.set('offset', String(options.offset));
|
|
116
|
+
}
|
|
117
|
+
if (typeof options.category === 'string' && options.category.trim().length > 0) {
|
|
118
|
+
params.set('category', options.category.trim());
|
|
119
|
+
}
|
|
120
|
+
if (typeof options.subcategory === 'string' && options.subcategory.trim().length > 0) {
|
|
121
|
+
params.set('subcategory', options.subcategory.trim());
|
|
122
|
+
}
|
|
123
|
+
const query = params.toString();
|
|
124
|
+
const path = `/creators/${encodeURIComponent(creatorUsername)}/assets${query ? `?${query}` : ''}`;
|
|
125
|
+
const response = await request({
|
|
126
|
+
method: 'GET',
|
|
127
|
+
path,
|
|
128
|
+
});
|
|
129
|
+
if (response.status !== 200) {
|
|
130
|
+
handleApiError(response, 'list_assets_for_creator');
|
|
131
|
+
}
|
|
132
|
+
return response.body;
|
|
133
|
+
},
|
|
134
|
+
async fetchAssetBySlug(creatorUsername, assetName) {
|
|
135
|
+
const path = `/assets/${encodeURIComponent(creatorUsername)}/${encodeURIComponent(assetName)}`;
|
|
136
|
+
const response = await request({
|
|
137
|
+
method: 'GET',
|
|
138
|
+
path,
|
|
139
|
+
});
|
|
140
|
+
if (response.status !== 200) {
|
|
141
|
+
handleApiError(response, 'fetch_asset_by_slug');
|
|
142
|
+
}
|
|
143
|
+
return response.body;
|
|
144
|
+
},
|
|
145
|
+
async listAssetVersions(creatorUsername, assetName, options = {}) {
|
|
146
|
+
const params = new URLSearchParams();
|
|
147
|
+
if (typeof options.limit === 'number') {
|
|
148
|
+
params.set('limit', String(options.limit));
|
|
149
|
+
}
|
|
150
|
+
if (typeof options.offset === 'number') {
|
|
151
|
+
params.set('offset', String(options.offset));
|
|
152
|
+
}
|
|
153
|
+
const query = params.toString();
|
|
154
|
+
const path = `/assets/${encodeURIComponent(creatorUsername)}/${encodeURIComponent(assetName)}/versions${query ? `?${query}` : ''}`;
|
|
155
|
+
const response = await request({
|
|
156
|
+
method: 'GET',
|
|
157
|
+
path,
|
|
158
|
+
});
|
|
159
|
+
if (response.status !== 200) {
|
|
160
|
+
handleApiError(response, 'list_asset_versions');
|
|
161
|
+
}
|
|
162
|
+
return response.body;
|
|
163
|
+
},
|
|
164
|
+
async updateAsset(creatorUsername, name, requestBody) {
|
|
165
|
+
const assetName = typeof name === 'string' ? name.trim() : '';
|
|
166
|
+
if (!assetName) {
|
|
167
|
+
throw new Error('invalid_asset_name');
|
|
168
|
+
}
|
|
169
|
+
const response = await request({
|
|
170
|
+
method: 'PATCH',
|
|
171
|
+
path: buildCreatorAssetMutationPath(creatorUsername, assetName),
|
|
172
|
+
body: requestBody,
|
|
173
|
+
});
|
|
174
|
+
if (response.status !== 200) {
|
|
175
|
+
handleApiError(response, 'update_asset');
|
|
176
|
+
}
|
|
177
|
+
return response.body;
|
|
178
|
+
},
|
|
179
|
+
async updateAssetVersion(creatorUsername, name, revision, requestBody) {
|
|
180
|
+
const assetName = typeof name === 'string' ? name.trim() : '';
|
|
181
|
+
if (!assetName) {
|
|
182
|
+
throw new Error('invalid_asset_name');
|
|
183
|
+
}
|
|
184
|
+
const normalizedRevision = normalizeAssetRevisionInput(revision);
|
|
185
|
+
const response = await request({
|
|
186
|
+
method: 'PATCH',
|
|
187
|
+
path: `${buildCreatorAssetMutationPath(creatorUsername, assetName)}/versions/${encodeURIComponent(normalizedRevision)}`,
|
|
188
|
+
body: requestBody,
|
|
189
|
+
});
|
|
190
|
+
if (response.status !== 200) {
|
|
191
|
+
handleApiError(response, 'update_asset_version');
|
|
192
|
+
}
|
|
193
|
+
return response.body;
|
|
194
|
+
},
|
|
195
|
+
async deleteAssetVersion(creatorUsername, name, revision) {
|
|
196
|
+
const assetName = typeof name === 'string' ? name.trim() : '';
|
|
197
|
+
if (!assetName) {
|
|
198
|
+
throw new Error('invalid_asset_name');
|
|
199
|
+
}
|
|
200
|
+
const normalizedRevision = normalizeAssetRevisionInput(revision);
|
|
201
|
+
const response = await request({
|
|
202
|
+
method: 'DELETE',
|
|
203
|
+
path: `${buildCreatorAssetMutationPath(creatorUsername, assetName)}/versions/${encodeURIComponent(normalizedRevision)}`,
|
|
204
|
+
});
|
|
205
|
+
if (response.status !== 200) {
|
|
206
|
+
handleApiError(response, 'delete_asset_version');
|
|
207
|
+
}
|
|
208
|
+
return response.body;
|
|
209
|
+
},
|
|
210
|
+
async deleteAsset(creatorUsername, name) {
|
|
211
|
+
const assetName = typeof name === 'string' ? name.trim() : '';
|
|
212
|
+
if (!assetName) {
|
|
213
|
+
throw new Error('invalid_asset_name');
|
|
214
|
+
}
|
|
215
|
+
const response = await request({
|
|
216
|
+
method: 'DELETE',
|
|
217
|
+
path: buildCreatorAssetMutationPath(creatorUsername, assetName),
|
|
218
|
+
});
|
|
219
|
+
if (response.status !== 200) {
|
|
220
|
+
handleApiError(response, 'delete_asset');
|
|
221
|
+
}
|
|
222
|
+
return response.body;
|
|
223
|
+
},
|
|
224
|
+
async downloadAssetFile(creatorUsername, assetName, revision, options = {}) {
|
|
225
|
+
const creator = typeof creatorUsername === 'string' ? creatorUsername.trim() : '';
|
|
226
|
+
const name = typeof assetName === 'string' ? assetName.trim() : '';
|
|
227
|
+
if (!creator || !name) {
|
|
228
|
+
throw new Error('invalid_asset_key');
|
|
229
|
+
}
|
|
230
|
+
const normalizedRevision = normalizeAssetRevisionInput(revision);
|
|
231
|
+
const params = new URLSearchParams();
|
|
232
|
+
if (typeof options.role === 'string' && options.role.trim().length > 0) {
|
|
233
|
+
params.set('role', options.role.trim());
|
|
234
|
+
}
|
|
235
|
+
const query = params.toString();
|
|
236
|
+
const path = `/assets/${encodeURIComponent(creator)}/${encodeURIComponent(name)}/versions/${encodeURIComponent(normalizedRevision)}/file${query ? `?${query}` : ''}`;
|
|
237
|
+
const base = resolveBaseUrl();
|
|
238
|
+
const headers = new Headers();
|
|
239
|
+
for (const [key, value] of Object.entries(getClientHeaders())) {
|
|
240
|
+
headers.set(key, value);
|
|
241
|
+
}
|
|
242
|
+
const token = await resolveToken();
|
|
243
|
+
if (token) {
|
|
244
|
+
headers.set('authorization', `Bearer ${token}`);
|
|
245
|
+
}
|
|
246
|
+
const response = await fetchImpl(resolveUrl(base, path), {
|
|
247
|
+
method: 'GET',
|
|
248
|
+
headers,
|
|
249
|
+
});
|
|
250
|
+
if (!response.ok) {
|
|
251
|
+
const parsed = await parseResponseBody(response);
|
|
252
|
+
handleApiError({ status: response.status, body: parsed, headers: response.headers }, 'download_asset_file');
|
|
253
|
+
}
|
|
254
|
+
return response.blob();
|
|
255
|
+
},
|
|
256
|
+
async downloadAssetSource(creatorUsername, assetName, revision) {
|
|
257
|
+
const creator = typeof creatorUsername === 'string' ? creatorUsername.trim() : '';
|
|
258
|
+
const name = typeof assetName === 'string' ? assetName.trim() : '';
|
|
259
|
+
if (!creator || !name) {
|
|
260
|
+
throw new Error('invalid_asset_key');
|
|
261
|
+
}
|
|
262
|
+
const normalizedRevision = normalizeAssetRevisionInput(revision);
|
|
263
|
+
const path = `/assets/${encodeURIComponent(creator)}/${encodeURIComponent(name)}/versions/${encodeURIComponent(normalizedRevision)}/source`;
|
|
264
|
+
const base = resolveBaseUrl();
|
|
265
|
+
const headers = new Headers();
|
|
266
|
+
for (const [key, value] of Object.entries(getClientHeaders())) {
|
|
267
|
+
headers.set(key, value);
|
|
268
|
+
}
|
|
269
|
+
const token = await resolveToken();
|
|
270
|
+
if (token) {
|
|
271
|
+
headers.set('authorization', `Bearer ${token}`);
|
|
272
|
+
}
|
|
273
|
+
const response = await fetchImpl(resolveUrl(base, path), {
|
|
274
|
+
method: 'GET',
|
|
275
|
+
headers,
|
|
276
|
+
});
|
|
277
|
+
if (!response.ok) {
|
|
278
|
+
const parsed = await parseResponseBody(response);
|
|
279
|
+
handleApiError({ status: response.status, body: parsed, headers: response.headers }, 'download_asset_source');
|
|
280
|
+
}
|
|
281
|
+
const blob = await response.blob();
|
|
282
|
+
const filename = parseContentDispositionFilename(response.headers.get('content-disposition'))
|
|
283
|
+
?? `${name}-r${normalizedRevision}-source.zip`;
|
|
284
|
+
const headerSize = response.headers.get('content-length');
|
|
285
|
+
const parsedSize = headerSize ? Number.parseInt(headerSize, 10) : Number.NaN;
|
|
286
|
+
const checksumHeader = response.headers.get('x-asset-source-checksum');
|
|
287
|
+
return {
|
|
288
|
+
blob,
|
|
289
|
+
metadata: {
|
|
290
|
+
filename,
|
|
291
|
+
sizeBytes: Number.isFinite(parsedSize) && parsedSize >= 0 ? parsedSize : blob.size,
|
|
292
|
+
checksum: checksumHeader ?? null,
|
|
293
|
+
},
|
|
294
|
+
};
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
}
|