@playdrop/playdrop-cli 0.7.13 → 0.7.16
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/config/client-meta.json +1 -1
- package/node_modules/@playdrop/ai-client/dist/index.js +461 -444
- package/node_modules/@playdrop/ai-client/package.json +1 -1
- package/node_modules/@playdrop/api-client/dist/client.js +903 -882
- package/node_modules/@playdrop/api-client/dist/core/errors.js +69 -45
- package/node_modules/@playdrop/api-client/dist/core/request.js +188 -159
- package/node_modules/@playdrop/api-client/dist/domains/admin.js +516 -491
- package/node_modules/@playdrop/api-client/dist/domains/ai.js +40 -14
- package/node_modules/@playdrop/api-client/dist/domains/apps.js +480 -462
- package/node_modules/@playdrop/api-client/dist/domains/asset-packs.js +439 -419
- package/node_modules/@playdrop/api-client/dist/domains/assets.js +696 -676
- package/node_modules/@playdrop/api-client/dist/domains/auth.js +346 -320
- package/node_modules/@playdrop/api-client/dist/domains/comments.js +124 -98
- package/node_modules/@playdrop/api-client/dist/domains/free-credits.js +91 -65
- package/node_modules/@playdrop/api-client/dist/domains/me.js +71 -45
- package/node_modules/@playdrop/api-client/dist/domains/payments.js +407 -386
- package/node_modules/@playdrop/api-client/dist/domains/player-meta.js +144 -118
- package/node_modules/@playdrop/api-client/dist/domains/search.js +117 -104
- package/node_modules/@playdrop/api-client/dist/domains/tags.js +188 -162
- package/node_modules/@playdrop/api-client/dist/index.js +993 -552
- package/node_modules/@playdrop/api-client/package.json +1 -1
- package/node_modules/@playdrop/boxel-three/dist/src/animations.js +84 -62
- package/node_modules/@playdrop/boxel-three/dist/src/builders.js +341 -308
- package/node_modules/@playdrop/boxel-three/dist/src/context.js +55 -29
- package/node_modules/@playdrop/boxel-three/dist/src/exporters/glb.js +856 -858
- package/node_modules/@playdrop/boxel-three/dist/src/exporters/image.js +267 -261
- package/node_modules/@playdrop/boxel-three/dist/src/index.js +64 -15
- package/node_modules/@playdrop/boxel-three/dist/src/instantiate.js +89 -63
- package/node_modules/@playdrop/boxel-three/dist/src/nodes.js +81 -56
- package/node_modules/@playdrop/boxel-three/dist/src/overlays.js +112 -86
- package/node_modules/@playdrop/boxel-three/dist/src/primitives.js +45 -17
- package/node_modules/@playdrop/boxel-three/dist/src/scene.js +160 -136
- package/node_modules/@playdrop/boxel-three/dist/src/skinned-mesh.js +582 -584
- package/node_modules/@playdrop/boxel-three/dist/src/texture-atlas.js +123 -97
- package/node_modules/@playdrop/boxel-three/dist/src/textures.js +207 -182
- package/node_modules/@playdrop/boxel-three/dist/src/types.js +15 -1
- package/node_modules/@playdrop/boxel-three/dist/src/voxels/faces.js +451 -425
- package/node_modules/@playdrop/boxel-three/dist/src/voxels/mesher.js +109 -84
- package/node_modules/@playdrop/boxel-three/dist/test/export-image.playwright.test.js +127 -106
- package/node_modules/@playdrop/boxel-three/dist/test/fixtures/render-worker.js +73 -51
- package/node_modules/@playdrop/boxel-three/dist/test/glb-skinned.test.js +97 -79
- package/node_modules/@playdrop/boxel-three/dist/test/index.test.js +29 -7
- package/node_modules/@playdrop/boxel-three/dist/test/instantiate.test.js +80 -60
- package/node_modules/@playdrop/boxel-three/dist/test/overlays.test.js +41 -19
- package/node_modules/@playdrop/boxel-three/dist/test/scene-filter.test.js +72 -50
- package/node_modules/@playdrop/boxel-three/dist/test/scene-smoke.test.js +84 -62
- package/node_modules/@playdrop/boxel-three/dist/test/skinned-mesh.test.js +69 -47
- package/node_modules/@playdrop/boxel-three/dist/test/textured-overlay.test.js +129 -109
- package/node_modules/@playdrop/boxel-three/dist/test/voxels.test.js +40 -18
- package/node_modules/@playdrop/boxel-three/package.json +1 -1
- package/node_modules/@playdrop/config/client-meta.json +1 -1
- package/node_modules/@playdrop/config/dist/tsconfig.tsbuildinfo +1 -1
- package/node_modules/@playdrop/types/dist/api.js +289 -203
- package/node_modules/@playdrop/types/dist/app-capability-filters.js +112 -62
- package/node_modules/@playdrop/types/dist/app.js +91 -45
- package/node_modules/@playdrop/types/dist/asset-pack.js +37 -5
- package/node_modules/@playdrop/types/dist/asset-spec.js +170 -90
- package/node_modules/@playdrop/types/dist/asset.js +186 -108
- package/node_modules/@playdrop/types/dist/content-license.js +49 -15
- package/node_modules/@playdrop/types/dist/creator-public-image.js +60 -32
- package/node_modules/@playdrop/types/dist/ecs.js +102 -82
- package/node_modules/@playdrop/types/dist/engine-builtins.js +603 -573
- package/node_modules/@playdrop/types/dist/entity.js +63 -53
- package/node_modules/@playdrop/types/dist/graph.js +116 -80
- package/node_modules/@playdrop/types/dist/index.js +47 -20
- package/node_modules/@playdrop/types/dist/owned-assets.js +55 -33
- package/node_modules/@playdrop/types/dist/player-meta.js +151 -100
- package/node_modules/@playdrop/types/dist/realtime.js +27 -7
- package/node_modules/@playdrop/types/dist/version.js +182 -124
- package/node_modules/@playdrop/types/package.json +1 -1
- package/package.json +1 -1
|
@@ -1,702 +1,722 @@
|
|
|
1
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var assets_exports = {};
|
|
19
|
+
__export(assets_exports, {
|
|
20
|
+
buildAssetsApiClientMethods: () => buildAssetsApiClientMethods
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(assets_exports);
|
|
23
|
+
var import_request = require("../core/request.js");
|
|
2
24
|
async function buildAuthorizedHeaders(getClientHeaders, resolveToken) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
25
|
+
const headers = new Headers();
|
|
26
|
+
for (const [key, value] of Object.entries(getClientHeaders())) {
|
|
27
|
+
headers.set(key, value);
|
|
28
|
+
}
|
|
29
|
+
const token = await resolveToken();
|
|
30
|
+
if (token) {
|
|
31
|
+
headers.set("authorization", `Bearer ${token}`);
|
|
32
|
+
}
|
|
33
|
+
return headers;
|
|
12
34
|
}
|
|
13
|
-
function buildPublicAssetPath(normalizeCreatorItemSlug, creatorUsername, assetName, suffix =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
35
|
+
function buildPublicAssetPath(normalizeCreatorItemSlug, creatorUsername, assetName, suffix = "") {
|
|
36
|
+
const creator = normalizeCreatorItemSlug(creatorUsername, "creator");
|
|
37
|
+
const name = normalizeCreatorItemSlug(assetName, "name");
|
|
38
|
+
return `/assets/${encodeURIComponent(creator)}/${encodeURIComponent(name)}${suffix}`;
|
|
17
39
|
}
|
|
18
40
|
function appendNormalizedTagParams(params, tags) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
41
|
+
if (!Array.isArray(tags)) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
for (const tag of tags) {
|
|
45
|
+
if (typeof tag !== "string") {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const normalized = tag.trim();
|
|
49
|
+
if (normalized.length > 0) {
|
|
50
|
+
params.append("tag", normalized);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
31
53
|
}
|
|
32
54
|
function buildAssetVersionUploadForm(options) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return form;
|
|
55
|
+
if (!Array.isArray(options.files) || options.files.length === 0) {
|
|
56
|
+
throw new Error("missing_asset_files");
|
|
57
|
+
}
|
|
58
|
+
const form = new FormData();
|
|
59
|
+
if ("assetSpec" in options) {
|
|
60
|
+
form.set("assetSpec", options.assetSpec);
|
|
61
|
+
} else {
|
|
62
|
+
form.set("category", options.category);
|
|
63
|
+
form.set("subcategory", options.subcategory);
|
|
64
|
+
form.set("format", options.format);
|
|
65
|
+
}
|
|
66
|
+
appendAssetVersionOptionalFields(form, options);
|
|
67
|
+
appendAssetVersionFiles(form, options);
|
|
68
|
+
return form;
|
|
48
69
|
}
|
|
49
70
|
function buildAssetSpecVersionUploadForm(options) {
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
71
|
+
const form = new FormData();
|
|
72
|
+
form.set("version", options.version);
|
|
73
|
+
form.set("symbol", options.symbol, "symbol.svg");
|
|
74
|
+
form.set("contract", options.contract, "contract.json");
|
|
75
|
+
if (options.displayName) {
|
|
76
|
+
form.set("displayName", options.displayName);
|
|
77
|
+
}
|
|
78
|
+
if (typeof options.description === "string") {
|
|
79
|
+
form.set("description", options.description);
|
|
80
|
+
}
|
|
81
|
+
if (options.visibility) {
|
|
82
|
+
form.set("visibility", options.visibility);
|
|
83
|
+
}
|
|
84
|
+
if (options.validationKind) {
|
|
85
|
+
form.set("validationKind", options.validationKind);
|
|
86
|
+
}
|
|
87
|
+
if (options.status) {
|
|
88
|
+
form.set("status", options.status);
|
|
89
|
+
}
|
|
90
|
+
if (typeof options.releaseNotes === "string") {
|
|
91
|
+
form.set("releaseNotes", options.releaseNotes);
|
|
92
|
+
}
|
|
93
|
+
if (typeof options.successorVersion === "string" && options.successorVersion.trim().length > 0) {
|
|
94
|
+
form.set("successorVersion", options.successorVersion.trim());
|
|
95
|
+
}
|
|
96
|
+
if (options.documentation) {
|
|
97
|
+
form.set("documentation", options.documentation, "README.md");
|
|
98
|
+
}
|
|
99
|
+
return form;
|
|
79
100
|
}
|
|
80
101
|
function appendAssetVersionOptionalFields(form, options) {
|
|
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
|
-
|
|
102
|
+
if (options.visibility)
|
|
103
|
+
form.set("visibility", options.visibility);
|
|
104
|
+
if (options.license)
|
|
105
|
+
form.set("license", options.license);
|
|
106
|
+
if (options.sourceKind)
|
|
107
|
+
form.set("sourceKind", options.sourceKind);
|
|
108
|
+
if (typeof options.sourceAppVersionId === "number") {
|
|
109
|
+
form.set("sourceAppVersionId", String(options.sourceAppVersionId));
|
|
110
|
+
}
|
|
111
|
+
if (typeof options.runtimeKey === "string" && options.runtimeKey.trim().length > 0) {
|
|
112
|
+
form.set("runtimeKey", options.runtimeKey.trim());
|
|
113
|
+
}
|
|
114
|
+
if (typeof options.sourceGenerationId === "string" && options.sourceGenerationId.trim().length > 0) {
|
|
115
|
+
form.set("sourceGenerationId", options.sourceGenerationId.trim());
|
|
116
|
+
}
|
|
117
|
+
if (typeof options.remixRef === "string" && options.remixRef.trim().length > 0) {
|
|
118
|
+
form.set("remixRef", options.remixRef.trim());
|
|
119
|
+
}
|
|
120
|
+
if (options.tags !== void 0) {
|
|
121
|
+
form.set("tags", JSON.stringify(options.tags));
|
|
122
|
+
}
|
|
123
|
+
if (typeof options.clearTags === "boolean") {
|
|
124
|
+
form.set("clearTags", options.clearTags ? "true" : "false");
|
|
125
|
+
}
|
|
126
|
+
if (typeof options.shopListed === "boolean") {
|
|
127
|
+
form.set("shopListed", options.shopListed ? "true" : "false");
|
|
128
|
+
}
|
|
129
|
+
if (typeof options.shopPriceCredits === "number") {
|
|
130
|
+
form.set("shopPriceCredits", String(options.shopPriceCredits));
|
|
131
|
+
}
|
|
132
|
+
if (typeof options.displayName === "string" && options.displayName.trim().length > 0) {
|
|
133
|
+
form.set("displayName", options.displayName.trim());
|
|
134
|
+
}
|
|
135
|
+
if (typeof options.description === "string") {
|
|
136
|
+
form.set("description", options.description);
|
|
137
|
+
}
|
|
117
138
|
}
|
|
118
139
|
function appendAssetVersionFiles(form, options) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
form.append(fieldName, item.file);
|
|
131
|
-
}
|
|
140
|
+
for (const item of options.files) {
|
|
141
|
+
if (!item) {
|
|
142
|
+
throw new Error("missing_asset_upload_file");
|
|
143
|
+
}
|
|
144
|
+
const fieldName = typeof item.fieldName === "string" && item.fieldName.trim().length > 0 ? item.fieldName.trim() : "file";
|
|
145
|
+
if (typeof item.filename === "string" && item.filename.trim().length > 0) {
|
|
146
|
+
form.append(fieldName, item.file, item.filename.trim());
|
|
147
|
+
} else {
|
|
148
|
+
form.append(fieldName, item.file);
|
|
132
149
|
}
|
|
150
|
+
}
|
|
133
151
|
}
|
|
134
152
|
async function fetchAssetRelatedRequest(request, handleApiError, normalizeCreatorItemSlug, creatorUsername, assetName) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
153
|
+
const response = await request({
|
|
154
|
+
method: "GET",
|
|
155
|
+
path: buildPublicAssetPath(normalizeCreatorItemSlug, creatorUsername, assetName, "/related")
|
|
156
|
+
});
|
|
157
|
+
if (response.status !== 200) {
|
|
158
|
+
handleApiError(response, "get_asset_related");
|
|
159
|
+
}
|
|
160
|
+
return response.body;
|
|
143
161
|
}
|
|
144
162
|
async function listAssetsRequest(request, handleApiError, options = {}) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
163
|
+
const params = new URLSearchParams();
|
|
164
|
+
if (typeof options.limit === "number")
|
|
165
|
+
params.set("limit", String(options.limit));
|
|
166
|
+
if (typeof options.offset === "number")
|
|
167
|
+
params.set("offset", String(options.offset));
|
|
168
|
+
if (typeof options.category === "string" && options.category.trim().length > 0) {
|
|
169
|
+
params.set("category", options.category.trim());
|
|
170
|
+
}
|
|
171
|
+
if (typeof options.subcategory === "string" && options.subcategory.trim().length > 0) {
|
|
172
|
+
params.set("subcategory", options.subcategory.trim());
|
|
173
|
+
}
|
|
174
|
+
if (typeof options.kind === "string" && options.kind.trim().length > 0) {
|
|
175
|
+
params.set("kind", options.kind.trim());
|
|
176
|
+
}
|
|
177
|
+
if (typeof options.assetSpec === "string" && options.assetSpec.trim().length > 0) {
|
|
178
|
+
params.set("assetSpec", options.assetSpec.trim());
|
|
179
|
+
}
|
|
180
|
+
if (typeof options.assetSpecOwner === "string" && options.assetSpecOwner.trim().length > 0) {
|
|
181
|
+
params.set("assetSpecOwner", options.assetSpecOwner.trim());
|
|
182
|
+
}
|
|
183
|
+
if (typeof options.assetSpecName === "string" && options.assetSpecName.trim().length > 0) {
|
|
184
|
+
params.set("assetSpecName", options.assetSpecName.trim());
|
|
185
|
+
}
|
|
186
|
+
if (typeof options.sort === "string" && options.sort.trim().length > 0) {
|
|
187
|
+
params.set("sort", options.sort.trim());
|
|
188
|
+
}
|
|
189
|
+
appendNormalizedTagParams(params, options.tags);
|
|
190
|
+
const query = params.toString();
|
|
191
|
+
const path = `/assets${query ? `?${query}` : ""}`;
|
|
192
|
+
const response = await request({ method: "GET", path });
|
|
193
|
+
if (response.status !== 200) {
|
|
194
|
+
handleApiError(response, "list_assets");
|
|
195
|
+
}
|
|
196
|
+
return response.body;
|
|
179
197
|
}
|
|
180
198
|
async function listAssetCategoriesRequest(request, handleApiError) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
199
|
+
const response = await request({
|
|
200
|
+
method: "GET",
|
|
201
|
+
path: "/asset-categories"
|
|
202
|
+
});
|
|
203
|
+
if (response.status !== 200) {
|
|
204
|
+
handleApiError(response, "list_asset_categories");
|
|
205
|
+
}
|
|
206
|
+
return response.body;
|
|
189
207
|
}
|
|
190
208
|
async function createAssetVersionRequest(input, creatorUsername, assetName, options) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
209
|
+
const form = buildAssetVersionUploadForm(options);
|
|
210
|
+
const base = input.resolveBaseUrl();
|
|
211
|
+
const path = `${input.buildCreatorAssetMutationPath(creatorUsername, assetName)}/versions`;
|
|
212
|
+
const headers = await buildAuthorizedHeaders(input.getClientHeaders, input.resolveToken);
|
|
213
|
+
const response = await input.fetchImpl(input.resolveUrl(base, path), {
|
|
214
|
+
method: "POST",
|
|
215
|
+
headers,
|
|
216
|
+
body: form,
|
|
217
|
+
...(0, import_request.buildBrowserCredentialsInit)(input.includeBrowserCredentials)
|
|
218
|
+
});
|
|
219
|
+
const parsed = await input.parseResponseBody(response);
|
|
220
|
+
const apiResponse = { status: response.status, body: parsed, headers: response.headers };
|
|
221
|
+
if (response.status !== 201 && response.status !== 200) {
|
|
222
|
+
input.handleApiError(apiResponse, "create_asset_version");
|
|
223
|
+
}
|
|
224
|
+
return parsed;
|
|
207
225
|
}
|
|
208
226
|
async function createAssetSpecVersionRequest(input, creatorUsername, name, options) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
227
|
+
const form = buildAssetSpecVersionUploadForm(options);
|
|
228
|
+
const base = input.resolveBaseUrl();
|
|
229
|
+
const path = `/creators/${encodeURIComponent(creatorUsername)}/asset-specs/${encodeURIComponent(name)}/versions`;
|
|
230
|
+
const headers = await buildAuthorizedHeaders(input.getClientHeaders, input.resolveToken);
|
|
231
|
+
const response = await input.fetchImpl(input.resolveUrl(base, path), {
|
|
232
|
+
method: "POST",
|
|
233
|
+
headers,
|
|
234
|
+
body: form,
|
|
235
|
+
...(0, import_request.buildBrowserCredentialsInit)(input.includeBrowserCredentials)
|
|
236
|
+
});
|
|
237
|
+
const parsed = await input.parseResponseBody(response);
|
|
238
|
+
const apiResponse = { status: response.status, body: parsed, headers: response.headers };
|
|
239
|
+
if (response.status !== 201 && response.status !== 200) {
|
|
240
|
+
input.handleApiError(apiResponse, "create_asset_spec_version");
|
|
241
|
+
}
|
|
242
|
+
return parsed;
|
|
243
|
+
}
|
|
244
|
+
function buildAssetsApiClientMethods(input) {
|
|
245
|
+
const { request, handleApiError, fetchImpl, includeBrowserCredentials, resolveBaseUrl, resolveUrl, parseResponseBody, resolveToken, getClientHeaders, buildCreatorAssetMutationPath, normalizeCreatorItemSlug, normalizeAssetRevisionInput, parseContentDispositionFilename } = input;
|
|
246
|
+
return {
|
|
247
|
+
async createAssetVersion(creatorUsername, name, options) {
|
|
248
|
+
const assetName = typeof name === "string" ? name.trim() : "";
|
|
249
|
+
if (!assetName) {
|
|
250
|
+
throw new Error("invalid_asset_name");
|
|
251
|
+
}
|
|
252
|
+
return createAssetVersionRequest({
|
|
253
|
+
fetchImpl,
|
|
254
|
+
includeBrowserCredentials,
|
|
255
|
+
resolveBaseUrl,
|
|
256
|
+
resolveUrl,
|
|
257
|
+
parseResponseBody,
|
|
258
|
+
resolveToken,
|
|
259
|
+
getClientHeaders,
|
|
260
|
+
buildCreatorAssetMutationPath,
|
|
261
|
+
handleApiError
|
|
262
|
+
}, creatorUsername, assetName, options);
|
|
263
|
+
},
|
|
264
|
+
async listOwnedCustomAssets(appId, options) {
|
|
265
|
+
const params = new URLSearchParams();
|
|
266
|
+
if (typeof options.assetSpecRef === "string" && options.assetSpecRef.trim().length > 0) {
|
|
267
|
+
params.set("assetSpecRef", options.assetSpecRef.trim());
|
|
268
|
+
}
|
|
269
|
+
if (typeof options.limit === "number") {
|
|
270
|
+
params.set("limit", String(options.limit));
|
|
271
|
+
}
|
|
272
|
+
if (typeof options.offset === "number") {
|
|
273
|
+
params.set("offset", String(options.offset));
|
|
274
|
+
}
|
|
275
|
+
const query = params.toString();
|
|
276
|
+
const response = await request({
|
|
277
|
+
method: "GET",
|
|
278
|
+
path: `/v1/apps/${encodeURIComponent(String(appId))}/custom-assets${query ? `?${query}` : ""}`
|
|
279
|
+
});
|
|
280
|
+
if (response.status !== 200) {
|
|
281
|
+
handleApiError(response, "list_owned_custom_assets");
|
|
282
|
+
}
|
|
283
|
+
return response.body;
|
|
284
|
+
},
|
|
285
|
+
async loadOwnedCustomAsset(appId, assetName, revision, options) {
|
|
286
|
+
const normalizedAssetName = typeof assetName === "string" ? assetName.trim() : "";
|
|
287
|
+
if (!normalizedAssetName) {
|
|
288
|
+
throw new Error("invalid_asset_name");
|
|
289
|
+
}
|
|
290
|
+
const normalizedRevision = normalizeAssetRevisionInput(revision);
|
|
291
|
+
const params = new URLSearchParams();
|
|
292
|
+
if (typeof options.assetSpecRef === "string" && options.assetSpecRef.trim().length > 0) {
|
|
293
|
+
params.set("assetSpecRef", options.assetSpecRef.trim());
|
|
294
|
+
}
|
|
295
|
+
const query = params.toString();
|
|
296
|
+
const response = await request({
|
|
297
|
+
method: "GET",
|
|
298
|
+
path: `/v1/apps/${encodeURIComponent(String(appId))}/custom-assets/${encodeURIComponent(normalizedAssetName)}/versions/${encodeURIComponent(normalizedRevision)}${query ? `?${query}` : ""}`
|
|
299
|
+
});
|
|
300
|
+
if (response.status !== 200) {
|
|
301
|
+
handleApiError(response, "load_owned_custom_asset");
|
|
302
|
+
}
|
|
303
|
+
return response.body;
|
|
304
|
+
},
|
|
305
|
+
async saveOwnedCustomAsset(appId, requestBody) {
|
|
306
|
+
const response = await request({
|
|
307
|
+
method: "POST",
|
|
308
|
+
path: `/v1/apps/${encodeURIComponent(String(appId))}/custom-assets`,
|
|
309
|
+
body: requestBody
|
|
310
|
+
});
|
|
311
|
+
if (response.status !== 201 && response.status !== 200) {
|
|
312
|
+
handleApiError(response, "save_owned_custom_asset");
|
|
313
|
+
}
|
|
314
|
+
return response.body;
|
|
315
|
+
},
|
|
316
|
+
async deleteOwnedCustomAsset(appId, assetName, options) {
|
|
317
|
+
const normalizedAssetName = typeof assetName === "string" ? assetName.trim() : "";
|
|
318
|
+
if (!normalizedAssetName) {
|
|
319
|
+
throw new Error("invalid_asset_name");
|
|
320
|
+
}
|
|
321
|
+
const params = new URLSearchParams();
|
|
322
|
+
if (typeof options.assetSpecRef === "string" && options.assetSpecRef.trim().length > 0) {
|
|
323
|
+
params.set("assetSpecRef", options.assetSpecRef.trim());
|
|
324
|
+
}
|
|
325
|
+
if (options.revision !== void 0) {
|
|
326
|
+
params.set("revision", normalizeAssetRevisionInput(options.revision));
|
|
327
|
+
}
|
|
328
|
+
const query = params.toString();
|
|
329
|
+
const response = await request({
|
|
330
|
+
method: "DELETE",
|
|
331
|
+
path: `/v1/apps/${encodeURIComponent(String(appId))}/custom-assets/${encodeURIComponent(normalizedAssetName)}${query ? `?${query}` : ""}`
|
|
332
|
+
});
|
|
333
|
+
if (response.status !== 200) {
|
|
334
|
+
handleApiError(response, "delete_owned_custom_asset");
|
|
335
|
+
}
|
|
336
|
+
return response.body;
|
|
337
|
+
},
|
|
338
|
+
async createAssetSpecVersion(creatorUsername, name, options) {
|
|
339
|
+
const assetSpecName = typeof name === "string" ? name.trim() : "";
|
|
340
|
+
if (!assetSpecName) {
|
|
341
|
+
throw new Error("invalid_asset_spec_name");
|
|
342
|
+
}
|
|
343
|
+
return createAssetSpecVersionRequest({
|
|
344
|
+
fetchImpl,
|
|
345
|
+
includeBrowserCredentials,
|
|
346
|
+
resolveBaseUrl,
|
|
347
|
+
resolveUrl,
|
|
348
|
+
parseResponseBody,
|
|
349
|
+
resolveToken,
|
|
350
|
+
getClientHeaders,
|
|
351
|
+
handleApiError
|
|
352
|
+
}, creatorUsername, assetSpecName, options);
|
|
353
|
+
},
|
|
354
|
+
async fetchAssetRelated(creatorUsername, assetName) {
|
|
355
|
+
return fetchAssetRelatedRequest(request, handleApiError, normalizeCreatorItemSlug, creatorUsername, assetName);
|
|
356
|
+
},
|
|
357
|
+
async listAssetCategories() {
|
|
358
|
+
return listAssetCategoriesRequest(request, handleApiError);
|
|
359
|
+
},
|
|
360
|
+
async listAssets(options = {}) {
|
|
361
|
+
return listAssetsRequest(request, handleApiError, options);
|
|
362
|
+
},
|
|
363
|
+
async listAssetsForCreator(creatorUsername, options = {}) {
|
|
364
|
+
const params = new URLSearchParams();
|
|
365
|
+
if (typeof options.limit === "number") {
|
|
366
|
+
params.set("limit", String(options.limit));
|
|
367
|
+
}
|
|
368
|
+
if (typeof options.offset === "number") {
|
|
369
|
+
params.set("offset", String(options.offset));
|
|
370
|
+
}
|
|
371
|
+
if (typeof options.category === "string" && options.category.trim().length > 0) {
|
|
372
|
+
params.set("category", options.category.trim());
|
|
373
|
+
}
|
|
374
|
+
if (typeof options.subcategory === "string" && options.subcategory.trim().length > 0) {
|
|
375
|
+
params.set("subcategory", options.subcategory.trim());
|
|
376
|
+
}
|
|
377
|
+
if (typeof options.kind === "string" && options.kind.trim().length > 0) {
|
|
378
|
+
params.set("kind", options.kind.trim());
|
|
379
|
+
}
|
|
380
|
+
if (typeof options.assetSpec === "string" && options.assetSpec.trim().length > 0) {
|
|
381
|
+
params.set("assetSpec", options.assetSpec.trim());
|
|
382
|
+
}
|
|
383
|
+
if (typeof options.assetSpecOwner === "string" && options.assetSpecOwner.trim().length > 0) {
|
|
384
|
+
params.set("assetSpecOwner", options.assetSpecOwner.trim());
|
|
385
|
+
}
|
|
386
|
+
if (typeof options.assetSpecName === "string" && options.assetSpecName.trim().length > 0) {
|
|
387
|
+
params.set("assetSpecName", options.assetSpecName.trim());
|
|
388
|
+
}
|
|
389
|
+
if (typeof options.sort === "string" && options.sort.trim().length > 0) {
|
|
390
|
+
params.set("sort", options.sort.trim());
|
|
391
|
+
}
|
|
392
|
+
appendNormalizedTagParams(params, options.tags);
|
|
393
|
+
const query = params.toString();
|
|
394
|
+
const path = `/creators/${encodeURIComponent(creatorUsername)}/assets${query ? `?${query}` : ""}`;
|
|
395
|
+
const response = await request({
|
|
396
|
+
method: "GET",
|
|
397
|
+
path
|
|
398
|
+
});
|
|
399
|
+
if (response.status !== 200) {
|
|
400
|
+
handleApiError(response, "list_assets_for_creator");
|
|
401
|
+
}
|
|
402
|
+
return response.body;
|
|
403
|
+
},
|
|
404
|
+
async listAssetSpecs(options = {}) {
|
|
405
|
+
const params = new URLSearchParams();
|
|
406
|
+
if (typeof options.limit === "number") {
|
|
407
|
+
params.set("limit", String(options.limit));
|
|
408
|
+
}
|
|
409
|
+
if (typeof options.offset === "number") {
|
|
410
|
+
params.set("offset", String(options.offset));
|
|
411
|
+
}
|
|
412
|
+
if (typeof options.sort === "string" && options.sort.trim().length > 0) {
|
|
413
|
+
params.set("sort", options.sort.trim());
|
|
414
|
+
}
|
|
415
|
+
const query = params.toString();
|
|
416
|
+
const response = await request({
|
|
417
|
+
method: "GET",
|
|
418
|
+
path: `/asset-specs${query ? `?${query}` : ""}`
|
|
419
|
+
});
|
|
420
|
+
if (response.status !== 200) {
|
|
421
|
+
handleApiError(response, "list_asset_specs");
|
|
422
|
+
}
|
|
423
|
+
return response.body;
|
|
424
|
+
},
|
|
425
|
+
async listAssetSpecsForCreator(creatorUsername, options = {}) {
|
|
426
|
+
const params = new URLSearchParams();
|
|
427
|
+
if (typeof options.limit === "number") {
|
|
428
|
+
params.set("limit", String(options.limit));
|
|
429
|
+
}
|
|
430
|
+
if (typeof options.offset === "number") {
|
|
431
|
+
params.set("offset", String(options.offset));
|
|
432
|
+
}
|
|
433
|
+
if (typeof options.sort === "string" && options.sort.trim().length > 0) {
|
|
434
|
+
params.set("sort", options.sort.trim());
|
|
435
|
+
}
|
|
436
|
+
const query = params.toString();
|
|
437
|
+
const response = await request({
|
|
438
|
+
method: "GET",
|
|
439
|
+
path: `/creators/${encodeURIComponent(creatorUsername)}/asset-specs${query ? `?${query}` : ""}`
|
|
440
|
+
});
|
|
441
|
+
if (response.status !== 200) {
|
|
442
|
+
handleApiError(response, "list_asset_specs_for_creator");
|
|
443
|
+
}
|
|
444
|
+
return response.body;
|
|
445
|
+
},
|
|
446
|
+
async fetchAssetSpecBySlug(creatorUsername, name) {
|
|
447
|
+
const response = await request({
|
|
448
|
+
method: "GET",
|
|
449
|
+
path: `/asset-specs/${encodeURIComponent(creatorUsername)}/${encodeURIComponent(name)}`
|
|
450
|
+
});
|
|
451
|
+
if (response.status !== 200) {
|
|
452
|
+
handleApiError(response, "fetch_asset_spec_by_slug");
|
|
453
|
+
}
|
|
454
|
+
return response.body;
|
|
455
|
+
},
|
|
456
|
+
async listAssetSpecVersions(creatorUsername, name, options = {}) {
|
|
457
|
+
const params = new URLSearchParams();
|
|
458
|
+
if (typeof options.limit === "number") {
|
|
459
|
+
params.set("limit", String(options.limit));
|
|
460
|
+
}
|
|
461
|
+
if (typeof options.offset === "number") {
|
|
462
|
+
params.set("offset", String(options.offset));
|
|
463
|
+
}
|
|
464
|
+
const query = params.toString();
|
|
465
|
+
const response = await request({
|
|
466
|
+
method: "GET",
|
|
467
|
+
path: `/asset-specs/${encodeURIComponent(creatorUsername)}/${encodeURIComponent(name)}/versions${query ? `?${query}` : ""}`
|
|
468
|
+
});
|
|
469
|
+
if (response.status !== 200) {
|
|
470
|
+
handleApiError(response, "list_asset_spec_versions");
|
|
471
|
+
}
|
|
472
|
+
return response.body;
|
|
473
|
+
},
|
|
474
|
+
async fetchAssetSpecVersion(creatorUsername, name, version) {
|
|
475
|
+
const response = await request({
|
|
476
|
+
method: "GET",
|
|
477
|
+
path: `/asset-specs/${encodeURIComponent(creatorUsername)}/${encodeURIComponent(name)}/versions/${encodeURIComponent(version)}`
|
|
478
|
+
});
|
|
479
|
+
if (response.status !== 200) {
|
|
480
|
+
handleApiError(response, "fetch_asset_spec_version");
|
|
481
|
+
}
|
|
482
|
+
return response.body;
|
|
483
|
+
},
|
|
484
|
+
async listAssetsByAssetSpec(creatorUsername, name, options = {}) {
|
|
485
|
+
const params = new URLSearchParams();
|
|
486
|
+
if (typeof options.limit === "number") {
|
|
487
|
+
params.set("limit", String(options.limit));
|
|
488
|
+
}
|
|
489
|
+
if (typeof options.offset === "number") {
|
|
490
|
+
params.set("offset", String(options.offset));
|
|
491
|
+
}
|
|
492
|
+
if (typeof options.sort === "string" && options.sort.trim().length > 0) {
|
|
493
|
+
params.set("sort", options.sort.trim());
|
|
494
|
+
}
|
|
495
|
+
const query = params.toString();
|
|
496
|
+
const response = await request({
|
|
497
|
+
method: "GET",
|
|
498
|
+
path: `/asset-specs/${encodeURIComponent(creatorUsername)}/${encodeURIComponent(name)}/assets${query ? `?${query}` : ""}`
|
|
499
|
+
});
|
|
500
|
+
if (response.status !== 200) {
|
|
501
|
+
handleApiError(response, "list_assets_by_asset_spec");
|
|
502
|
+
}
|
|
503
|
+
return response.body;
|
|
504
|
+
},
|
|
505
|
+
async listAppsByAssetSpec(creatorUsername, name, options = {}) {
|
|
506
|
+
const params = new URLSearchParams();
|
|
507
|
+
if (typeof options.limit === "number") {
|
|
508
|
+
params.set("limit", String(options.limit));
|
|
509
|
+
}
|
|
510
|
+
if (typeof options.offset === "number") {
|
|
511
|
+
params.set("offset", String(options.offset));
|
|
512
|
+
}
|
|
513
|
+
const query = params.toString();
|
|
514
|
+
const response = await request({
|
|
515
|
+
method: "GET",
|
|
516
|
+
path: `/asset-specs/${encodeURIComponent(creatorUsername)}/${encodeURIComponent(name)}/apps${query ? `?${query}` : ""}`
|
|
517
|
+
});
|
|
518
|
+
if (response.status !== 200) {
|
|
519
|
+
handleApiError(response, "list_apps_by_asset_spec");
|
|
520
|
+
}
|
|
521
|
+
return response.body;
|
|
522
|
+
},
|
|
523
|
+
async fetchAssetBySlug(creatorUsername, assetName) {
|
|
524
|
+
const path = `/assets/${encodeURIComponent(creatorUsername)}/${encodeURIComponent(assetName)}`;
|
|
525
|
+
const response = await request({
|
|
526
|
+
method: "GET",
|
|
527
|
+
path
|
|
528
|
+
});
|
|
529
|
+
if (response.status !== 200) {
|
|
530
|
+
handleApiError(response, "fetch_asset_by_slug");
|
|
531
|
+
}
|
|
532
|
+
return response.body;
|
|
533
|
+
},
|
|
534
|
+
async listAssetVersions(creatorUsername, assetName, options = {}) {
|
|
535
|
+
const params = new URLSearchParams();
|
|
536
|
+
if (typeof options.limit === "number") {
|
|
537
|
+
params.set("limit", String(options.limit));
|
|
538
|
+
}
|
|
539
|
+
if (typeof options.offset === "number") {
|
|
540
|
+
params.set("offset", String(options.offset));
|
|
541
|
+
}
|
|
542
|
+
const query = params.toString();
|
|
543
|
+
const path = `/assets/${encodeURIComponent(creatorUsername)}/${encodeURIComponent(assetName)}/versions${query ? `?${query}` : ""}`;
|
|
544
|
+
const response = await request({
|
|
545
|
+
method: "GET",
|
|
546
|
+
path
|
|
547
|
+
});
|
|
548
|
+
if (response.status !== 200) {
|
|
549
|
+
handleApiError(response, "list_asset_versions");
|
|
550
|
+
}
|
|
551
|
+
return response.body;
|
|
552
|
+
},
|
|
553
|
+
async updateAsset(creatorUsername, name, requestBody) {
|
|
554
|
+
const assetName = typeof name === "string" ? name.trim() : "";
|
|
555
|
+
if (!assetName) {
|
|
556
|
+
throw new Error("invalid_asset_name");
|
|
557
|
+
}
|
|
558
|
+
const response = await request({
|
|
559
|
+
method: "PATCH",
|
|
560
|
+
path: buildCreatorAssetMutationPath(creatorUsername, assetName),
|
|
561
|
+
body: requestBody
|
|
562
|
+
});
|
|
563
|
+
if (response.status !== 200) {
|
|
564
|
+
handleApiError(response, "update_asset");
|
|
565
|
+
}
|
|
566
|
+
return response.body;
|
|
567
|
+
},
|
|
568
|
+
async updateAssetVersion(creatorUsername, name, revision, requestBody) {
|
|
569
|
+
const assetName = typeof name === "string" ? name.trim() : "";
|
|
570
|
+
if (!assetName) {
|
|
571
|
+
throw new Error("invalid_asset_name");
|
|
572
|
+
}
|
|
573
|
+
const normalizedRevision = normalizeAssetRevisionInput(revision);
|
|
574
|
+
const response = await request({
|
|
575
|
+
method: "PATCH",
|
|
576
|
+
path: `${buildCreatorAssetMutationPath(creatorUsername, assetName)}/versions/${encodeURIComponent(normalizedRevision)}`,
|
|
577
|
+
body: requestBody
|
|
578
|
+
});
|
|
579
|
+
if (response.status !== 200) {
|
|
580
|
+
handleApiError(response, "update_asset_version");
|
|
581
|
+
}
|
|
582
|
+
return response.body;
|
|
583
|
+
},
|
|
584
|
+
async deleteAssetVersion(creatorUsername, name, revision) {
|
|
585
|
+
const assetName = typeof name === "string" ? name.trim() : "";
|
|
586
|
+
if (!assetName) {
|
|
587
|
+
throw new Error("invalid_asset_name");
|
|
588
|
+
}
|
|
589
|
+
const normalizedRevision = normalizeAssetRevisionInput(revision);
|
|
590
|
+
const response = await request({
|
|
591
|
+
method: "DELETE",
|
|
592
|
+
path: `${buildCreatorAssetMutationPath(creatorUsername, assetName)}/versions/${encodeURIComponent(normalizedRevision)}`
|
|
593
|
+
});
|
|
594
|
+
if (response.status !== 200) {
|
|
595
|
+
handleApiError(response, "delete_asset_version");
|
|
596
|
+
}
|
|
597
|
+
return response.body;
|
|
598
|
+
},
|
|
599
|
+
async deleteAsset(creatorUsername, name) {
|
|
600
|
+
const assetName = typeof name === "string" ? name.trim() : "";
|
|
601
|
+
if (!assetName) {
|
|
602
|
+
throw new Error("invalid_asset_name");
|
|
603
|
+
}
|
|
604
|
+
const response = await request({
|
|
605
|
+
method: "DELETE",
|
|
606
|
+
path: buildCreatorAssetMutationPath(creatorUsername, assetName)
|
|
607
|
+
});
|
|
608
|
+
if (response.status !== 200) {
|
|
609
|
+
handleApiError(response, "delete_asset");
|
|
610
|
+
}
|
|
611
|
+
return response.body;
|
|
612
|
+
},
|
|
613
|
+
async updateAssetSpecVersion(creatorUsername, name, version, requestBody) {
|
|
614
|
+
const response = await request({
|
|
615
|
+
method: "PATCH",
|
|
616
|
+
path: `/creators/${encodeURIComponent(creatorUsername)}/asset-specs/${encodeURIComponent(name)}/versions/${encodeURIComponent(version)}`,
|
|
617
|
+
body: requestBody
|
|
618
|
+
});
|
|
619
|
+
if (response.status !== 200) {
|
|
620
|
+
handleApiError(response, "update_asset_spec_version");
|
|
621
|
+
}
|
|
622
|
+
return response.body;
|
|
623
|
+
},
|
|
624
|
+
async deleteAssetSpecVersion(creatorUsername, name, version) {
|
|
625
|
+
const response = await request({
|
|
626
|
+
method: "DELETE",
|
|
627
|
+
path: `/creators/${encodeURIComponent(creatorUsername)}/asset-specs/${encodeURIComponent(name)}/versions/${encodeURIComponent(version)}`
|
|
628
|
+
});
|
|
629
|
+
if (response.status !== 200) {
|
|
630
|
+
handleApiError(response, "delete_asset_spec_version");
|
|
631
|
+
}
|
|
632
|
+
return response.body;
|
|
633
|
+
},
|
|
634
|
+
async deleteAssetSpec(creatorUsername, name) {
|
|
635
|
+
const response = await request({
|
|
636
|
+
method: "DELETE",
|
|
637
|
+
path: `/creators/${encodeURIComponent(creatorUsername)}/asset-specs/${encodeURIComponent(name)}`
|
|
638
|
+
});
|
|
639
|
+
if (response.status !== 200) {
|
|
640
|
+
handleApiError(response, "delete_asset_spec");
|
|
641
|
+
}
|
|
642
|
+
return response.body;
|
|
643
|
+
},
|
|
644
|
+
async downloadAssetFile(creatorUsername, assetName, revision, options = {}) {
|
|
645
|
+
const creator = typeof creatorUsername === "string" ? creatorUsername.trim() : "";
|
|
646
|
+
const name = typeof assetName === "string" ? assetName.trim() : "";
|
|
647
|
+
if (!creator || !name) {
|
|
648
|
+
throw new Error("invalid_asset_key");
|
|
649
|
+
}
|
|
650
|
+
const normalizedRevision = normalizeAssetRevisionInput(revision);
|
|
651
|
+
const params = new URLSearchParams();
|
|
652
|
+
if (typeof options.role === "string" && options.role.trim().length > 0) {
|
|
653
|
+
params.set("role", options.role.trim());
|
|
654
|
+
}
|
|
655
|
+
const query = params.toString();
|
|
656
|
+
const path = `/assets/${encodeURIComponent(creator)}/${encodeURIComponent(name)}/versions/${encodeURIComponent(normalizedRevision)}/file${query ? `?${query}` : ""}`;
|
|
657
|
+
const base = resolveBaseUrl();
|
|
658
|
+
const headers = new Headers();
|
|
659
|
+
for (const [key, value] of Object.entries(getClientHeaders())) {
|
|
660
|
+
headers.set(key, value);
|
|
661
|
+
}
|
|
662
|
+
const token = await resolveToken();
|
|
663
|
+
if (token) {
|
|
664
|
+
headers.set("authorization", `Bearer ${token}`);
|
|
665
|
+
}
|
|
666
|
+
const response = await fetchImpl(resolveUrl(base, path), {
|
|
667
|
+
method: "GET",
|
|
668
|
+
headers,
|
|
669
|
+
...(0, import_request.buildBrowserCredentialsInit)(includeBrowserCredentials)
|
|
670
|
+
});
|
|
671
|
+
if (!response.ok) {
|
|
672
|
+
const parsed = await parseResponseBody(response);
|
|
673
|
+
handleApiError({ status: response.status, body: parsed, headers: response.headers }, "download_asset_file");
|
|
674
|
+
}
|
|
675
|
+
return response.blob();
|
|
676
|
+
},
|
|
677
|
+
async downloadAssetSource(creatorUsername, assetName, revision) {
|
|
678
|
+
const creator = typeof creatorUsername === "string" ? creatorUsername.trim() : "";
|
|
679
|
+
const name = typeof assetName === "string" ? assetName.trim() : "";
|
|
680
|
+
if (!creator || !name) {
|
|
681
|
+
throw new Error("invalid_asset_key");
|
|
682
|
+
}
|
|
683
|
+
const normalizedRevision = normalizeAssetRevisionInput(revision);
|
|
684
|
+
const path = `/assets/${encodeURIComponent(creator)}/${encodeURIComponent(name)}/versions/${encodeURIComponent(normalizedRevision)}/source`;
|
|
685
|
+
const base = resolveBaseUrl();
|
|
686
|
+
const headers = new Headers();
|
|
687
|
+
for (const [key, value] of Object.entries(getClientHeaders())) {
|
|
688
|
+
headers.set(key, value);
|
|
689
|
+
}
|
|
690
|
+
const token = await resolveToken();
|
|
691
|
+
if (token) {
|
|
692
|
+
headers.set("authorization", `Bearer ${token}`);
|
|
693
|
+
}
|
|
694
|
+
const response = await fetchImpl(resolveUrl(base, path), {
|
|
695
|
+
method: "GET",
|
|
215
696
|
headers,
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
697
|
+
...(0, import_request.buildBrowserCredentialsInit)(includeBrowserCredentials)
|
|
698
|
+
});
|
|
699
|
+
if (!response.ok) {
|
|
700
|
+
const parsed = await parseResponseBody(response);
|
|
701
|
+
handleApiError({ status: response.status, body: parsed, headers: response.headers }, "download_asset_source");
|
|
702
|
+
}
|
|
703
|
+
const blob = await response.blob();
|
|
704
|
+
const filename = parseContentDispositionFilename(response.headers.get("content-disposition")) ?? `${name}-r${normalizedRevision}-source.zip`;
|
|
705
|
+
const headerSize = response.headers.get("content-length");
|
|
706
|
+
const parsedSize = headerSize ? Number.parseInt(headerSize, 10) : Number.NaN;
|
|
707
|
+
const checksumHeader = response.headers.get("x-asset-source-checksum");
|
|
708
|
+
return {
|
|
709
|
+
blob,
|
|
710
|
+
metadata: {
|
|
711
|
+
filename,
|
|
712
|
+
sizeBytes: Number.isFinite(parsedSize) && parsedSize >= 0 ? parsedSize : blob.size,
|
|
713
|
+
checksum: checksumHeader ?? null
|
|
714
|
+
}
|
|
715
|
+
};
|
|
223
716
|
}
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
// eslint-disable-next-line max-lines-per-function
|
|
227
|
-
export function buildAssetsApiClientMethods(input) {
|
|
228
|
-
const { request, handleApiError, fetchImpl, includeBrowserCredentials, resolveBaseUrl, resolveUrl, parseResponseBody, resolveToken, getClientHeaders, buildCreatorAssetMutationPath, normalizeCreatorItemSlug, normalizeAssetRevisionInput, parseContentDispositionFilename, } = input;
|
|
229
|
-
return {
|
|
230
|
-
async createAssetVersion(creatorUsername, name, options) {
|
|
231
|
-
const assetName = typeof name === 'string' ? name.trim() : '';
|
|
232
|
-
if (!assetName) {
|
|
233
|
-
throw new Error('invalid_asset_name');
|
|
234
|
-
}
|
|
235
|
-
return createAssetVersionRequest({
|
|
236
|
-
fetchImpl,
|
|
237
|
-
includeBrowserCredentials,
|
|
238
|
-
resolveBaseUrl,
|
|
239
|
-
resolveUrl,
|
|
240
|
-
parseResponseBody,
|
|
241
|
-
resolveToken,
|
|
242
|
-
getClientHeaders,
|
|
243
|
-
buildCreatorAssetMutationPath,
|
|
244
|
-
handleApiError,
|
|
245
|
-
}, creatorUsername, assetName, options);
|
|
246
|
-
},
|
|
247
|
-
async listOwnedCustomAssets(appId, options) {
|
|
248
|
-
const params = new URLSearchParams();
|
|
249
|
-
if (typeof options.assetSpecRef === 'string' && options.assetSpecRef.trim().length > 0) {
|
|
250
|
-
params.set('assetSpecRef', options.assetSpecRef.trim());
|
|
251
|
-
}
|
|
252
|
-
if (typeof options.limit === 'number') {
|
|
253
|
-
params.set('limit', String(options.limit));
|
|
254
|
-
}
|
|
255
|
-
if (typeof options.offset === 'number') {
|
|
256
|
-
params.set('offset', String(options.offset));
|
|
257
|
-
}
|
|
258
|
-
const query = params.toString();
|
|
259
|
-
const response = await request({
|
|
260
|
-
method: 'GET',
|
|
261
|
-
path: `/v1/apps/${encodeURIComponent(String(appId))}/custom-assets${query ? `?${query}` : ''}`,
|
|
262
|
-
});
|
|
263
|
-
if (response.status !== 200) {
|
|
264
|
-
handleApiError(response, 'list_owned_custom_assets');
|
|
265
|
-
}
|
|
266
|
-
return response.body;
|
|
267
|
-
},
|
|
268
|
-
async loadOwnedCustomAsset(appId, assetName, revision, options) {
|
|
269
|
-
const normalizedAssetName = typeof assetName === 'string' ? assetName.trim() : '';
|
|
270
|
-
if (!normalizedAssetName) {
|
|
271
|
-
throw new Error('invalid_asset_name');
|
|
272
|
-
}
|
|
273
|
-
const normalizedRevision = normalizeAssetRevisionInput(revision);
|
|
274
|
-
const params = new URLSearchParams();
|
|
275
|
-
if (typeof options.assetSpecRef === 'string' && options.assetSpecRef.trim().length > 0) {
|
|
276
|
-
params.set('assetSpecRef', options.assetSpecRef.trim());
|
|
277
|
-
}
|
|
278
|
-
const query = params.toString();
|
|
279
|
-
const response = await request({
|
|
280
|
-
method: 'GET',
|
|
281
|
-
path: `/v1/apps/${encodeURIComponent(String(appId))}/custom-assets/${encodeURIComponent(normalizedAssetName)}/versions/${encodeURIComponent(normalizedRevision)}${query ? `?${query}` : ''}`,
|
|
282
|
-
});
|
|
283
|
-
if (response.status !== 200) {
|
|
284
|
-
handleApiError(response, 'load_owned_custom_asset');
|
|
285
|
-
}
|
|
286
|
-
return response.body;
|
|
287
|
-
},
|
|
288
|
-
async saveOwnedCustomAsset(appId, requestBody) {
|
|
289
|
-
const response = await request({
|
|
290
|
-
method: 'POST',
|
|
291
|
-
path: `/v1/apps/${encodeURIComponent(String(appId))}/custom-assets`,
|
|
292
|
-
body: requestBody,
|
|
293
|
-
});
|
|
294
|
-
if (response.status !== 201 && response.status !== 200) {
|
|
295
|
-
handleApiError(response, 'save_owned_custom_asset');
|
|
296
|
-
}
|
|
297
|
-
return response.body;
|
|
298
|
-
},
|
|
299
|
-
async deleteOwnedCustomAsset(appId, assetName, options) {
|
|
300
|
-
const normalizedAssetName = typeof assetName === 'string' ? assetName.trim() : '';
|
|
301
|
-
if (!normalizedAssetName) {
|
|
302
|
-
throw new Error('invalid_asset_name');
|
|
303
|
-
}
|
|
304
|
-
const params = new URLSearchParams();
|
|
305
|
-
if (typeof options.assetSpecRef === 'string' && options.assetSpecRef.trim().length > 0) {
|
|
306
|
-
params.set('assetSpecRef', options.assetSpecRef.trim());
|
|
307
|
-
}
|
|
308
|
-
if (options.revision !== undefined) {
|
|
309
|
-
params.set('revision', normalizeAssetRevisionInput(options.revision));
|
|
310
|
-
}
|
|
311
|
-
const query = params.toString();
|
|
312
|
-
const response = await request({
|
|
313
|
-
method: 'DELETE',
|
|
314
|
-
path: `/v1/apps/${encodeURIComponent(String(appId))}/custom-assets/${encodeURIComponent(normalizedAssetName)}${query ? `?${query}` : ''}`,
|
|
315
|
-
});
|
|
316
|
-
if (response.status !== 200) {
|
|
317
|
-
handleApiError(response, 'delete_owned_custom_asset');
|
|
318
|
-
}
|
|
319
|
-
return response.body;
|
|
320
|
-
},
|
|
321
|
-
async createAssetSpecVersion(creatorUsername, name, options) {
|
|
322
|
-
const assetSpecName = typeof name === 'string' ? name.trim() : '';
|
|
323
|
-
if (!assetSpecName) {
|
|
324
|
-
throw new Error('invalid_asset_spec_name');
|
|
325
|
-
}
|
|
326
|
-
return createAssetSpecVersionRequest({
|
|
327
|
-
fetchImpl,
|
|
328
|
-
includeBrowserCredentials,
|
|
329
|
-
resolveBaseUrl,
|
|
330
|
-
resolveUrl,
|
|
331
|
-
parseResponseBody,
|
|
332
|
-
resolveToken,
|
|
333
|
-
getClientHeaders,
|
|
334
|
-
handleApiError,
|
|
335
|
-
}, creatorUsername, assetSpecName, options);
|
|
336
|
-
},
|
|
337
|
-
async fetchAssetRelated(creatorUsername, assetName) {
|
|
338
|
-
return fetchAssetRelatedRequest(request, handleApiError, normalizeCreatorItemSlug, creatorUsername, assetName);
|
|
339
|
-
},
|
|
340
|
-
async listAssetCategories() {
|
|
341
|
-
return listAssetCategoriesRequest(request, handleApiError);
|
|
342
|
-
},
|
|
343
|
-
async listAssets(options = {}) {
|
|
344
|
-
return listAssetsRequest(request, handleApiError, options);
|
|
345
|
-
},
|
|
346
|
-
async listAssetsForCreator(creatorUsername, options = {}) {
|
|
347
|
-
const params = new URLSearchParams();
|
|
348
|
-
if (typeof options.limit === 'number') {
|
|
349
|
-
params.set('limit', String(options.limit));
|
|
350
|
-
}
|
|
351
|
-
if (typeof options.offset === 'number') {
|
|
352
|
-
params.set('offset', String(options.offset));
|
|
353
|
-
}
|
|
354
|
-
if (typeof options.category === 'string' && options.category.trim().length > 0) {
|
|
355
|
-
params.set('category', options.category.trim());
|
|
356
|
-
}
|
|
357
|
-
if (typeof options.subcategory === 'string' && options.subcategory.trim().length > 0) {
|
|
358
|
-
params.set('subcategory', options.subcategory.trim());
|
|
359
|
-
}
|
|
360
|
-
if (typeof options.kind === 'string' && options.kind.trim().length > 0) {
|
|
361
|
-
params.set('kind', options.kind.trim());
|
|
362
|
-
}
|
|
363
|
-
if (typeof options.assetSpec === 'string' && options.assetSpec.trim().length > 0) {
|
|
364
|
-
params.set('assetSpec', options.assetSpec.trim());
|
|
365
|
-
}
|
|
366
|
-
if (typeof options.assetSpecOwner === 'string' && options.assetSpecOwner.trim().length > 0) {
|
|
367
|
-
params.set('assetSpecOwner', options.assetSpecOwner.trim());
|
|
368
|
-
}
|
|
369
|
-
if (typeof options.assetSpecName === 'string' && options.assetSpecName.trim().length > 0) {
|
|
370
|
-
params.set('assetSpecName', options.assetSpecName.trim());
|
|
371
|
-
}
|
|
372
|
-
if (typeof options.sort === 'string' && options.sort.trim().length > 0) {
|
|
373
|
-
params.set('sort', options.sort.trim());
|
|
374
|
-
}
|
|
375
|
-
appendNormalizedTagParams(params, options.tags);
|
|
376
|
-
const query = params.toString();
|
|
377
|
-
const path = `/creators/${encodeURIComponent(creatorUsername)}/assets${query ? `?${query}` : ''}`;
|
|
378
|
-
const response = await request({
|
|
379
|
-
method: 'GET',
|
|
380
|
-
path,
|
|
381
|
-
});
|
|
382
|
-
if (response.status !== 200) {
|
|
383
|
-
handleApiError(response, 'list_assets_for_creator');
|
|
384
|
-
}
|
|
385
|
-
return response.body;
|
|
386
|
-
},
|
|
387
|
-
async listAssetSpecs(options = {}) {
|
|
388
|
-
const params = new URLSearchParams();
|
|
389
|
-
if (typeof options.limit === 'number') {
|
|
390
|
-
params.set('limit', String(options.limit));
|
|
391
|
-
}
|
|
392
|
-
if (typeof options.offset === 'number') {
|
|
393
|
-
params.set('offset', String(options.offset));
|
|
394
|
-
}
|
|
395
|
-
if (typeof options.sort === 'string' && options.sort.trim().length > 0) {
|
|
396
|
-
params.set('sort', options.sort.trim());
|
|
397
|
-
}
|
|
398
|
-
const query = params.toString();
|
|
399
|
-
const response = await request({
|
|
400
|
-
method: 'GET',
|
|
401
|
-
path: `/asset-specs${query ? `?${query}` : ''}`,
|
|
402
|
-
});
|
|
403
|
-
if (response.status !== 200) {
|
|
404
|
-
handleApiError(response, 'list_asset_specs');
|
|
405
|
-
}
|
|
406
|
-
return response.body;
|
|
407
|
-
},
|
|
408
|
-
async listAssetSpecsForCreator(creatorUsername, options = {}) {
|
|
409
|
-
const params = new URLSearchParams();
|
|
410
|
-
if (typeof options.limit === 'number') {
|
|
411
|
-
params.set('limit', String(options.limit));
|
|
412
|
-
}
|
|
413
|
-
if (typeof options.offset === 'number') {
|
|
414
|
-
params.set('offset', String(options.offset));
|
|
415
|
-
}
|
|
416
|
-
if (typeof options.sort === 'string' && options.sort.trim().length > 0) {
|
|
417
|
-
params.set('sort', options.sort.trim());
|
|
418
|
-
}
|
|
419
|
-
const query = params.toString();
|
|
420
|
-
const response = await request({
|
|
421
|
-
method: 'GET',
|
|
422
|
-
path: `/creators/${encodeURIComponent(creatorUsername)}/asset-specs${query ? `?${query}` : ''}`,
|
|
423
|
-
});
|
|
424
|
-
if (response.status !== 200) {
|
|
425
|
-
handleApiError(response, 'list_asset_specs_for_creator');
|
|
426
|
-
}
|
|
427
|
-
return response.body;
|
|
428
|
-
},
|
|
429
|
-
async fetchAssetSpecBySlug(creatorUsername, name) {
|
|
430
|
-
const response = await request({
|
|
431
|
-
method: 'GET',
|
|
432
|
-
path: `/asset-specs/${encodeURIComponent(creatorUsername)}/${encodeURIComponent(name)}`,
|
|
433
|
-
});
|
|
434
|
-
if (response.status !== 200) {
|
|
435
|
-
handleApiError(response, 'fetch_asset_spec_by_slug');
|
|
436
|
-
}
|
|
437
|
-
return response.body;
|
|
438
|
-
},
|
|
439
|
-
async listAssetSpecVersions(creatorUsername, name, options = {}) {
|
|
440
|
-
const params = new URLSearchParams();
|
|
441
|
-
if (typeof options.limit === 'number') {
|
|
442
|
-
params.set('limit', String(options.limit));
|
|
443
|
-
}
|
|
444
|
-
if (typeof options.offset === 'number') {
|
|
445
|
-
params.set('offset', String(options.offset));
|
|
446
|
-
}
|
|
447
|
-
const query = params.toString();
|
|
448
|
-
const response = await request({
|
|
449
|
-
method: 'GET',
|
|
450
|
-
path: `/asset-specs/${encodeURIComponent(creatorUsername)}/${encodeURIComponent(name)}/versions${query ? `?${query}` : ''}`,
|
|
451
|
-
});
|
|
452
|
-
if (response.status !== 200) {
|
|
453
|
-
handleApiError(response, 'list_asset_spec_versions');
|
|
454
|
-
}
|
|
455
|
-
return response.body;
|
|
456
|
-
},
|
|
457
|
-
async fetchAssetSpecVersion(creatorUsername, name, version) {
|
|
458
|
-
const response = await request({
|
|
459
|
-
method: 'GET',
|
|
460
|
-
path: `/asset-specs/${encodeURIComponent(creatorUsername)}/${encodeURIComponent(name)}/versions/${encodeURIComponent(version)}`,
|
|
461
|
-
});
|
|
462
|
-
if (response.status !== 200) {
|
|
463
|
-
handleApiError(response, 'fetch_asset_spec_version');
|
|
464
|
-
}
|
|
465
|
-
return response.body;
|
|
466
|
-
},
|
|
467
|
-
async listAssetsByAssetSpec(creatorUsername, name, options = {}) {
|
|
468
|
-
const params = new URLSearchParams();
|
|
469
|
-
if (typeof options.limit === 'number') {
|
|
470
|
-
params.set('limit', String(options.limit));
|
|
471
|
-
}
|
|
472
|
-
if (typeof options.offset === 'number') {
|
|
473
|
-
params.set('offset', String(options.offset));
|
|
474
|
-
}
|
|
475
|
-
if (typeof options.sort === 'string' && options.sort.trim().length > 0) {
|
|
476
|
-
params.set('sort', options.sort.trim());
|
|
477
|
-
}
|
|
478
|
-
const query = params.toString();
|
|
479
|
-
const response = await request({
|
|
480
|
-
method: 'GET',
|
|
481
|
-
path: `/asset-specs/${encodeURIComponent(creatorUsername)}/${encodeURIComponent(name)}/assets${query ? `?${query}` : ''}`,
|
|
482
|
-
});
|
|
483
|
-
if (response.status !== 200) {
|
|
484
|
-
handleApiError(response, 'list_assets_by_asset_spec');
|
|
485
|
-
}
|
|
486
|
-
return response.body;
|
|
487
|
-
},
|
|
488
|
-
async listAppsByAssetSpec(creatorUsername, name, options = {}) {
|
|
489
|
-
const params = new URLSearchParams();
|
|
490
|
-
if (typeof options.limit === 'number') {
|
|
491
|
-
params.set('limit', String(options.limit));
|
|
492
|
-
}
|
|
493
|
-
if (typeof options.offset === 'number') {
|
|
494
|
-
params.set('offset', String(options.offset));
|
|
495
|
-
}
|
|
496
|
-
const query = params.toString();
|
|
497
|
-
const response = await request({
|
|
498
|
-
method: 'GET',
|
|
499
|
-
path: `/asset-specs/${encodeURIComponent(creatorUsername)}/${encodeURIComponent(name)}/apps${query ? `?${query}` : ''}`,
|
|
500
|
-
});
|
|
501
|
-
if (response.status !== 200) {
|
|
502
|
-
handleApiError(response, 'list_apps_by_asset_spec');
|
|
503
|
-
}
|
|
504
|
-
return response.body;
|
|
505
|
-
},
|
|
506
|
-
async fetchAssetBySlug(creatorUsername, assetName) {
|
|
507
|
-
const path = `/assets/${encodeURIComponent(creatorUsername)}/${encodeURIComponent(assetName)}`;
|
|
508
|
-
const response = await request({
|
|
509
|
-
method: 'GET',
|
|
510
|
-
path,
|
|
511
|
-
});
|
|
512
|
-
if (response.status !== 200) {
|
|
513
|
-
handleApiError(response, 'fetch_asset_by_slug');
|
|
514
|
-
}
|
|
515
|
-
return response.body;
|
|
516
|
-
},
|
|
517
|
-
async listAssetVersions(creatorUsername, assetName, options = {}) {
|
|
518
|
-
const params = new URLSearchParams();
|
|
519
|
-
if (typeof options.limit === 'number') {
|
|
520
|
-
params.set('limit', String(options.limit));
|
|
521
|
-
}
|
|
522
|
-
if (typeof options.offset === 'number') {
|
|
523
|
-
params.set('offset', String(options.offset));
|
|
524
|
-
}
|
|
525
|
-
const query = params.toString();
|
|
526
|
-
const path = `/assets/${encodeURIComponent(creatorUsername)}/${encodeURIComponent(assetName)}/versions${query ? `?${query}` : ''}`;
|
|
527
|
-
const response = await request({
|
|
528
|
-
method: 'GET',
|
|
529
|
-
path,
|
|
530
|
-
});
|
|
531
|
-
if (response.status !== 200) {
|
|
532
|
-
handleApiError(response, 'list_asset_versions');
|
|
533
|
-
}
|
|
534
|
-
return response.body;
|
|
535
|
-
},
|
|
536
|
-
async updateAsset(creatorUsername, name, requestBody) {
|
|
537
|
-
const assetName = typeof name === 'string' ? name.trim() : '';
|
|
538
|
-
if (!assetName) {
|
|
539
|
-
throw new Error('invalid_asset_name');
|
|
540
|
-
}
|
|
541
|
-
const response = await request({
|
|
542
|
-
method: 'PATCH',
|
|
543
|
-
path: buildCreatorAssetMutationPath(creatorUsername, assetName),
|
|
544
|
-
body: requestBody,
|
|
545
|
-
});
|
|
546
|
-
if (response.status !== 200) {
|
|
547
|
-
handleApiError(response, 'update_asset');
|
|
548
|
-
}
|
|
549
|
-
return response.body;
|
|
550
|
-
},
|
|
551
|
-
async updateAssetVersion(creatorUsername, name, revision, requestBody) {
|
|
552
|
-
const assetName = typeof name === 'string' ? name.trim() : '';
|
|
553
|
-
if (!assetName) {
|
|
554
|
-
throw new Error('invalid_asset_name');
|
|
555
|
-
}
|
|
556
|
-
const normalizedRevision = normalizeAssetRevisionInput(revision);
|
|
557
|
-
const response = await request({
|
|
558
|
-
method: 'PATCH',
|
|
559
|
-
path: `${buildCreatorAssetMutationPath(creatorUsername, assetName)}/versions/${encodeURIComponent(normalizedRevision)}`,
|
|
560
|
-
body: requestBody,
|
|
561
|
-
});
|
|
562
|
-
if (response.status !== 200) {
|
|
563
|
-
handleApiError(response, 'update_asset_version');
|
|
564
|
-
}
|
|
565
|
-
return response.body;
|
|
566
|
-
},
|
|
567
|
-
async deleteAssetVersion(creatorUsername, name, revision) {
|
|
568
|
-
const assetName = typeof name === 'string' ? name.trim() : '';
|
|
569
|
-
if (!assetName) {
|
|
570
|
-
throw new Error('invalid_asset_name');
|
|
571
|
-
}
|
|
572
|
-
const normalizedRevision = normalizeAssetRevisionInput(revision);
|
|
573
|
-
const response = await request({
|
|
574
|
-
method: 'DELETE',
|
|
575
|
-
path: `${buildCreatorAssetMutationPath(creatorUsername, assetName)}/versions/${encodeURIComponent(normalizedRevision)}`,
|
|
576
|
-
});
|
|
577
|
-
if (response.status !== 200) {
|
|
578
|
-
handleApiError(response, 'delete_asset_version');
|
|
579
|
-
}
|
|
580
|
-
return response.body;
|
|
581
|
-
},
|
|
582
|
-
async deleteAsset(creatorUsername, name) {
|
|
583
|
-
const assetName = typeof name === 'string' ? name.trim() : '';
|
|
584
|
-
if (!assetName) {
|
|
585
|
-
throw new Error('invalid_asset_name');
|
|
586
|
-
}
|
|
587
|
-
const response = await request({
|
|
588
|
-
method: 'DELETE',
|
|
589
|
-
path: buildCreatorAssetMutationPath(creatorUsername, assetName),
|
|
590
|
-
});
|
|
591
|
-
if (response.status !== 200) {
|
|
592
|
-
handleApiError(response, 'delete_asset');
|
|
593
|
-
}
|
|
594
|
-
return response.body;
|
|
595
|
-
},
|
|
596
|
-
async updateAssetSpecVersion(creatorUsername, name, version, requestBody) {
|
|
597
|
-
const response = await request({
|
|
598
|
-
method: 'PATCH',
|
|
599
|
-
path: `/creators/${encodeURIComponent(creatorUsername)}/asset-specs/${encodeURIComponent(name)}/versions/${encodeURIComponent(version)}`,
|
|
600
|
-
body: requestBody,
|
|
601
|
-
});
|
|
602
|
-
if (response.status !== 200) {
|
|
603
|
-
handleApiError(response, 'update_asset_spec_version');
|
|
604
|
-
}
|
|
605
|
-
return response.body;
|
|
606
|
-
},
|
|
607
|
-
async deleteAssetSpecVersion(creatorUsername, name, version) {
|
|
608
|
-
const response = await request({
|
|
609
|
-
method: 'DELETE',
|
|
610
|
-
path: `/creators/${encodeURIComponent(creatorUsername)}/asset-specs/${encodeURIComponent(name)}/versions/${encodeURIComponent(version)}`,
|
|
611
|
-
});
|
|
612
|
-
if (response.status !== 200) {
|
|
613
|
-
handleApiError(response, 'delete_asset_spec_version');
|
|
614
|
-
}
|
|
615
|
-
return response.body;
|
|
616
|
-
},
|
|
617
|
-
async deleteAssetSpec(creatorUsername, name) {
|
|
618
|
-
const response = await request({
|
|
619
|
-
method: 'DELETE',
|
|
620
|
-
path: `/creators/${encodeURIComponent(creatorUsername)}/asset-specs/${encodeURIComponent(name)}`,
|
|
621
|
-
});
|
|
622
|
-
if (response.status !== 200) {
|
|
623
|
-
handleApiError(response, 'delete_asset_spec');
|
|
624
|
-
}
|
|
625
|
-
return response.body;
|
|
626
|
-
},
|
|
627
|
-
async downloadAssetFile(creatorUsername, assetName, revision, options = {}) {
|
|
628
|
-
const creator = typeof creatorUsername === 'string' ? creatorUsername.trim() : '';
|
|
629
|
-
const name = typeof assetName === 'string' ? assetName.trim() : '';
|
|
630
|
-
if (!creator || !name) {
|
|
631
|
-
throw new Error('invalid_asset_key');
|
|
632
|
-
}
|
|
633
|
-
const normalizedRevision = normalizeAssetRevisionInput(revision);
|
|
634
|
-
const params = new URLSearchParams();
|
|
635
|
-
if (typeof options.role === 'string' && options.role.trim().length > 0) {
|
|
636
|
-
params.set('role', options.role.trim());
|
|
637
|
-
}
|
|
638
|
-
const query = params.toString();
|
|
639
|
-
const path = `/assets/${encodeURIComponent(creator)}/${encodeURIComponent(name)}/versions/${encodeURIComponent(normalizedRevision)}/file${query ? `?${query}` : ''}`;
|
|
640
|
-
const base = resolveBaseUrl();
|
|
641
|
-
const headers = new Headers();
|
|
642
|
-
for (const [key, value] of Object.entries(getClientHeaders())) {
|
|
643
|
-
headers.set(key, value);
|
|
644
|
-
}
|
|
645
|
-
const token = await resolveToken();
|
|
646
|
-
if (token) {
|
|
647
|
-
headers.set('authorization', `Bearer ${token}`);
|
|
648
|
-
}
|
|
649
|
-
const response = await fetchImpl(resolveUrl(base, path), {
|
|
650
|
-
method: 'GET',
|
|
651
|
-
headers,
|
|
652
|
-
...buildBrowserCredentialsInit(includeBrowserCredentials),
|
|
653
|
-
});
|
|
654
|
-
if (!response.ok) {
|
|
655
|
-
const parsed = await parseResponseBody(response);
|
|
656
|
-
handleApiError({ status: response.status, body: parsed, headers: response.headers }, 'download_asset_file');
|
|
657
|
-
}
|
|
658
|
-
return response.blob();
|
|
659
|
-
},
|
|
660
|
-
async downloadAssetSource(creatorUsername, assetName, revision) {
|
|
661
|
-
const creator = typeof creatorUsername === 'string' ? creatorUsername.trim() : '';
|
|
662
|
-
const name = typeof assetName === 'string' ? assetName.trim() : '';
|
|
663
|
-
if (!creator || !name) {
|
|
664
|
-
throw new Error('invalid_asset_key');
|
|
665
|
-
}
|
|
666
|
-
const normalizedRevision = normalizeAssetRevisionInput(revision);
|
|
667
|
-
const path = `/assets/${encodeURIComponent(creator)}/${encodeURIComponent(name)}/versions/${encodeURIComponent(normalizedRevision)}/source`;
|
|
668
|
-
const base = resolveBaseUrl();
|
|
669
|
-
const headers = new Headers();
|
|
670
|
-
for (const [key, value] of Object.entries(getClientHeaders())) {
|
|
671
|
-
headers.set(key, value);
|
|
672
|
-
}
|
|
673
|
-
const token = await resolveToken();
|
|
674
|
-
if (token) {
|
|
675
|
-
headers.set('authorization', `Bearer ${token}`);
|
|
676
|
-
}
|
|
677
|
-
const response = await fetchImpl(resolveUrl(base, path), {
|
|
678
|
-
method: 'GET',
|
|
679
|
-
headers,
|
|
680
|
-
...buildBrowserCredentialsInit(includeBrowserCredentials),
|
|
681
|
-
});
|
|
682
|
-
if (!response.ok) {
|
|
683
|
-
const parsed = await parseResponseBody(response);
|
|
684
|
-
handleApiError({ status: response.status, body: parsed, headers: response.headers }, 'download_asset_source');
|
|
685
|
-
}
|
|
686
|
-
const blob = await response.blob();
|
|
687
|
-
const filename = parseContentDispositionFilename(response.headers.get('content-disposition'))
|
|
688
|
-
?? `${name}-r${normalizedRevision}-source.zip`;
|
|
689
|
-
const headerSize = response.headers.get('content-length');
|
|
690
|
-
const parsedSize = headerSize ? Number.parseInt(headerSize, 10) : Number.NaN;
|
|
691
|
-
const checksumHeader = response.headers.get('x-asset-source-checksum');
|
|
692
|
-
return {
|
|
693
|
-
blob,
|
|
694
|
-
metadata: {
|
|
695
|
-
filename,
|
|
696
|
-
sizeBytes: Number.isFinite(parsedSize) && parsedSize >= 0 ? parsedSize : blob.size,
|
|
697
|
-
checksum: checksumHeader ?? null,
|
|
698
|
-
},
|
|
699
|
-
};
|
|
700
|
-
},
|
|
701
|
-
};
|
|
717
|
+
};
|
|
702
718
|
}
|
|
719
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
720
|
+
0 && (module.exports = {
|
|
721
|
+
buildAssetsApiClientMethods
|
|
722
|
+
});
|