var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var assets_exports = {};
__export(assets_exports, {
  buildAssetsApiClientMethods: () => buildAssetsApiClientMethods
});
module.exports = __toCommonJS(assets_exports);
var import_request = require("../core/request.js");
async function buildAuthorizedHeaders(getClientHeaders, resolveToken) {
  const headers = new Headers();
  for (const [key, value] of Object.entries(getClientHeaders())) {
    headers.set(key, value);
  }
  const token = await resolveToken();
  if (token) {
    headers.set("authorization", `Bearer ${token}`);
  }
  return headers;
}
function buildPublicAssetPath(normalizeCreatorItemSlug, creatorUsername, assetName, suffix = "") {
  const creator = normalizeCreatorItemSlug(creatorUsername, "creator");
  const name = normalizeCreatorItemSlug(assetName, "name");
  return `/assets/${encodeURIComponent(creator)}/${encodeURIComponent(name)}${suffix}`;
}
function appendNormalizedTagParams(params, tags) {
  if (!Array.isArray(tags)) {
    return;
  }
  for (const tag of tags) {
    if (typeof tag !== "string") {
      continue;
    }
    const normalized = tag.trim();
    if (normalized.length > 0) {
      params.append("tag", normalized);
    }
  }
}
function buildAssetVersionUploadForm(options) {
  if (!Array.isArray(options.files) || options.files.length === 0) {
    throw new Error("missing_asset_files");
  }
  const form = new FormData();
  if ("assetSpec" in options) {
    form.set("assetSpec", options.assetSpec);
  } else {
    form.set("category", options.category);
    form.set("subcategory", options.subcategory);
    form.set("format", options.format);
  }
  appendAssetVersionOptionalFields(form, options);
  appendAssetVersionFiles(form, options);
  return form;
}
function buildAssetSpecVersionUploadForm(options) {
  const form = new FormData();
  form.set("version", options.version);
  form.set("symbol", options.symbol, "symbol.svg");
  form.set("contract", options.contract, "contract.json");
  if (options.displayName) {
    form.set("displayName", options.displayName);
  }
  if (typeof options.description === "string") {
    form.set("description", options.description);
  }
  if (options.visibility) {
    form.set("visibility", options.visibility);
  }
  if (options.validationKind) {
    form.set("validationKind", options.validationKind);
  }
  if (options.status) {
    form.set("status", options.status);
  }
  if (typeof options.releaseNotes === "string") {
    form.set("releaseNotes", options.releaseNotes);
  }
  if (typeof options.successorVersion === "string" && options.successorVersion.trim().length > 0) {
    form.set("successorVersion", options.successorVersion.trim());
  }
  if (options.documentation) {
    form.set("documentation", options.documentation, "README.md");
  }
  return form;
}
function appendAssetVersionOptionalFields(form, options) {
  if (options.visibility)
    form.set("visibility", options.visibility);
  if (options.license)
    form.set("license", options.license);
  if (options.sourceKind)
    form.set("sourceKind", options.sourceKind);
  if (typeof options.sourceAppVersionId === "number") {
    form.set("sourceAppVersionId", String(options.sourceAppVersionId));
  }
  if (typeof options.runtimeKey === "string" && options.runtimeKey.trim().length > 0) {
    form.set("runtimeKey", options.runtimeKey.trim());
  }
  if (typeof options.sourceGenerationId === "string" && options.sourceGenerationId.trim().length > 0) {
    form.set("sourceGenerationId", options.sourceGenerationId.trim());
  }
  if (typeof options.remixRef === "string" && options.remixRef.trim().length > 0) {
    form.set("remixRef", options.remixRef.trim());
  }
  if (options.tags !== void 0) {
    form.set("tags", JSON.stringify(options.tags));
  }
  if (typeof options.clearTags === "boolean") {
    form.set("clearTags", options.clearTags ? "true" : "false");
  }
  if (typeof options.shopListed === "boolean") {
    form.set("shopListed", options.shopListed ? "true" : "false");
  }
  if (typeof options.shopPriceCredits === "number") {
    form.set("shopPriceCredits", String(options.shopPriceCredits));
  }
  if (typeof options.displayName === "string" && options.displayName.trim().length > 0) {
    form.set("displayName", options.displayName.trim());
  }
  if (typeof options.description === "string") {
    form.set("description", options.description);
  }
}
function appendAssetVersionFiles(form, options) {
  for (const item of options.files) {
    if (!item) {
      throw new Error("missing_asset_upload_file");
    }
    const fieldName = typeof item.fieldName === "string" && item.fieldName.trim().length > 0 ? item.fieldName.trim() : "file";
    if (typeof item.filename === "string" && item.filename.trim().length > 0) {
      form.append(fieldName, item.file, item.filename.trim());
    } else {
      form.append(fieldName, item.file);
    }
  }
}
async function fetchAssetRelatedRequest(request, handleApiError, normalizeCreatorItemSlug, creatorUsername, assetName) {
  const response = await request({
    method: "GET",
    path: buildPublicAssetPath(normalizeCreatorItemSlug, creatorUsername, assetName, "/related")
  });
  if (response.status !== 200) {
    handleApiError(response, "get_asset_related");
  }
  return response.body;
}
async function listAssetsRequest(request, handleApiError, options = {}) {
  const params = new URLSearchParams();
  if (typeof options.limit === "number")
    params.set("limit", String(options.limit));
  if (typeof options.offset === "number")
    params.set("offset", String(options.offset));
  if (typeof options.category === "string" && options.category.trim().length > 0) {
    params.set("category", options.category.trim());
  }
  if (typeof options.subcategory === "string" && options.subcategory.trim().length > 0) {
    params.set("subcategory", options.subcategory.trim());
  }
  if (typeof options.kind === "string" && options.kind.trim().length > 0) {
    params.set("kind", options.kind.trim());
  }
  if (typeof options.assetSpec === "string" && options.assetSpec.trim().length > 0) {
    params.set("assetSpec", options.assetSpec.trim());
  }
  if (typeof options.assetSpecOwner === "string" && options.assetSpecOwner.trim().length > 0) {
    params.set("assetSpecOwner", options.assetSpecOwner.trim());
  }
  if (typeof options.assetSpecName === "string" && options.assetSpecName.trim().length > 0) {
    params.set("assetSpecName", options.assetSpecName.trim());
  }
  if (typeof options.sort === "string" && options.sort.trim().length > 0) {
    params.set("sort", options.sort.trim());
  }
  appendNormalizedTagParams(params, options.tags);
  const query = params.toString();
  const path = `/assets${query ? `?${query}` : ""}`;
  const response = await request({ method: "GET", path });
  if (response.status !== 200) {
    handleApiError(response, "list_assets");
  }
  return response.body;
}
async function listAssetCategoriesRequest(request, handleApiError) {
  const response = await request({
    method: "GET",
    path: "/asset-categories"
  });
  if (response.status !== 200) {
    handleApiError(response, "list_asset_categories");
  }
  return response.body;
}
async function createAssetVersionRequest(input, creatorUsername, assetName, options) {
  const form = buildAssetVersionUploadForm(options);
  const base = input.resolveBaseUrl();
  const path = `${input.buildCreatorAssetMutationPath(creatorUsername, assetName)}/versions`;
  const headers = await buildAuthorizedHeaders(input.getClientHeaders, input.resolveToken);
  const response = await input.fetchImpl(input.resolveUrl(base, path), {
    method: "POST",
    headers,
    body: form,
    ...(0, import_request.buildBrowserCredentialsInit)(input.includeBrowserCredentials)
  });
  const parsed = await input.parseResponseBody(response);
  const apiResponse = { status: response.status, body: parsed, headers: response.headers };
  if (response.status !== 201 && response.status !== 200) {
    input.handleApiError(apiResponse, "create_asset_version");
  }
  return parsed;
}
async function createAssetSpecVersionRequest(input, creatorUsername, name, options) {
  const form = buildAssetSpecVersionUploadForm(options);
  const base = input.resolveBaseUrl();
  const path = `/creators/${encodeURIComponent(creatorUsername)}/asset-specs/${encodeURIComponent(name)}/versions`;
  const headers = await buildAuthorizedHeaders(input.getClientHeaders, input.resolveToken);
  const response = await input.fetchImpl(input.resolveUrl(base, path), {
    method: "POST",
    headers,
    body: form,
    ...(0, import_request.buildBrowserCredentialsInit)(input.includeBrowserCredentials)
  });
  const parsed = await input.parseResponseBody(response);
  const apiResponse = { status: response.status, body: parsed, headers: response.headers };
  if (response.status !== 201 && response.status !== 200) {
    input.handleApiError(apiResponse, "create_asset_spec_version");
  }
  return parsed;
}
function buildAssetsApiClientMethods(input) {
  const { request, handleApiError, fetchImpl, includeBrowserCredentials, resolveBaseUrl, resolveUrl, parseResponseBody, resolveToken, getClientHeaders, buildCreatorAssetMutationPath, normalizeCreatorItemSlug, normalizeAssetRevisionInput, parseContentDispositionFilename } = input;
  return {
    async createAssetVersion(creatorUsername, name, options) {
      const assetName = typeof name === "string" ? name.trim() : "";
      if (!assetName) {
        throw new Error("invalid_asset_name");
      }
      return createAssetVersionRequest({
        fetchImpl,
        includeBrowserCredentials,
        resolveBaseUrl,
        resolveUrl,
        parseResponseBody,
        resolveToken,
        getClientHeaders,
        buildCreatorAssetMutationPath,
        handleApiError
      }, creatorUsername, assetName, options);
    },
    async listOwnedCustomAssets(appId, options) {
      const params = new URLSearchParams();
      if (typeof options.assetSpecRef === "string" && options.assetSpecRef.trim().length > 0) {
        params.set("assetSpecRef", options.assetSpecRef.trim());
      }
      if (typeof options.limit === "number") {
        params.set("limit", String(options.limit));
      }
      if (typeof options.offset === "number") {
        params.set("offset", String(options.offset));
      }
      const query = params.toString();
      const response = await request({
        method: "GET",
        path: `/v1/apps/${encodeURIComponent(String(appId))}/custom-assets${query ? `?${query}` : ""}`
      });
      if (response.status !== 200) {
        handleApiError(response, "list_owned_custom_assets");
      }
      return response.body;
    },
    async loadOwnedCustomAsset(appId, assetName, revision, options) {
      const normalizedAssetName = typeof assetName === "string" ? assetName.trim() : "";
      if (!normalizedAssetName) {
        throw new Error("invalid_asset_name");
      }
      const normalizedRevision = normalizeAssetRevisionInput(revision);
      const params = new URLSearchParams();
      if (typeof options.assetSpecRef === "string" && options.assetSpecRef.trim().length > 0) {
        params.set("assetSpecRef", options.assetSpecRef.trim());
      }
      const query = params.toString();
      const response = await request({
        method: "GET",
        path: `/v1/apps/${encodeURIComponent(String(appId))}/custom-assets/${encodeURIComponent(normalizedAssetName)}/versions/${encodeURIComponent(normalizedRevision)}${query ? `?${query}` : ""}`
      });
      if (response.status !== 200) {
        handleApiError(response, "load_owned_custom_asset");
      }
      return response.body;
    },
    async saveOwnedCustomAsset(appId, requestBody) {
      const response = await request({
        method: "POST",
        path: `/v1/apps/${encodeURIComponent(String(appId))}/custom-assets`,
        body: requestBody
      });
      if (response.status !== 201 && response.status !== 200) {
        handleApiError(response, "save_owned_custom_asset");
      }
      return response.body;
    },
    async deleteOwnedCustomAsset(appId, assetName, options) {
      const normalizedAssetName = typeof assetName === "string" ? assetName.trim() : "";
      if (!normalizedAssetName) {
        throw new Error("invalid_asset_name");
      }
      const params = new URLSearchParams();
      if (typeof options.assetSpecRef === "string" && options.assetSpecRef.trim().length > 0) {
        params.set("assetSpecRef", options.assetSpecRef.trim());
      }
      if (options.revision !== void 0) {
        params.set("revision", normalizeAssetRevisionInput(options.revision));
      }
      const query = params.toString();
      const response = await request({
        method: "DELETE",
        path: `/v1/apps/${encodeURIComponent(String(appId))}/custom-assets/${encodeURIComponent(normalizedAssetName)}${query ? `?${query}` : ""}`
      });
      if (response.status !== 200) {
        handleApiError(response, "delete_owned_custom_asset");
      }
      return response.body;
    },
    async createAssetSpecVersion(creatorUsername, name, options) {
      const assetSpecName = typeof name === "string" ? name.trim() : "";
      if (!assetSpecName) {
        throw new Error("invalid_asset_spec_name");
      }
      return createAssetSpecVersionRequest({
        fetchImpl,
        includeBrowserCredentials,
        resolveBaseUrl,
        resolveUrl,
        parseResponseBody,
        resolveToken,
        getClientHeaders,
        handleApiError
      }, creatorUsername, assetSpecName, options);
    },
    async fetchAssetRelated(creatorUsername, assetName) {
      return fetchAssetRelatedRequest(request, handleApiError, normalizeCreatorItemSlug, creatorUsername, assetName);
    },
    async listAssetCategories() {
      return listAssetCategoriesRequest(request, handleApiError);
    },
    async listAssets(options = {}) {
      return listAssetsRequest(request, handleApiError, options);
    },
    async listAssetsForCreator(creatorUsername, options = {}) {
      const params = new URLSearchParams();
      if (typeof options.limit === "number") {
        params.set("limit", String(options.limit));
      }
      if (typeof options.offset === "number") {
        params.set("offset", String(options.offset));
      }
      if (typeof options.category === "string" && options.category.trim().length > 0) {
        params.set("category", options.category.trim());
      }
      if (typeof options.subcategory === "string" && options.subcategory.trim().length > 0) {
        params.set("subcategory", options.subcategory.trim());
      }
      if (typeof options.kind === "string" && options.kind.trim().length > 0) {
        params.set("kind", options.kind.trim());
      }
      if (typeof options.assetSpec === "string" && options.assetSpec.trim().length > 0) {
        params.set("assetSpec", options.assetSpec.trim());
      }
      if (typeof options.assetSpecOwner === "string" && options.assetSpecOwner.trim().length > 0) {
        params.set("assetSpecOwner", options.assetSpecOwner.trim());
      }
      if (typeof options.assetSpecName === "string" && options.assetSpecName.trim().length > 0) {
        params.set("assetSpecName", options.assetSpecName.trim());
      }
      if (typeof options.sort === "string" && options.sort.trim().length > 0) {
        params.set("sort", options.sort.trim());
      }
      appendNormalizedTagParams(params, options.tags);
      const query = params.toString();
      const path = `/creators/${encodeURIComponent(creatorUsername)}/assets${query ? `?${query}` : ""}`;
      const response = await request({
        method: "GET",
        path
      });
      if (response.status !== 200) {
        handleApiError(response, "list_assets_for_creator");
      }
      return response.body;
    },
    async listAssetSpecs(options = {}) {
      const params = new URLSearchParams();
      if (typeof options.limit === "number") {
        params.set("limit", String(options.limit));
      }
      if (typeof options.offset === "number") {
        params.set("offset", String(options.offset));
      }
      if (typeof options.sort === "string" && options.sort.trim().length > 0) {
        params.set("sort", options.sort.trim());
      }
      const query = params.toString();
      const response = await request({
        method: "GET",
        path: `/asset-specs${query ? `?${query}` : ""}`
      });
      if (response.status !== 200) {
        handleApiError(response, "list_asset_specs");
      }
      return response.body;
    },
    async listAssetSpecsForCreator(creatorUsername, options = {}) {
      const params = new URLSearchParams();
      if (typeof options.limit === "number") {
        params.set("limit", String(options.limit));
      }
      if (typeof options.offset === "number") {
        params.set("offset", String(options.offset));
      }
      if (typeof options.sort === "string" && options.sort.trim().length > 0) {
        params.set("sort", options.sort.trim());
      }
      const query = params.toString();
      const response = await request({
        method: "GET",
        path: `/creators/${encodeURIComponent(creatorUsername)}/asset-specs${query ? `?${query}` : ""}`
      });
      if (response.status !== 200) {
        handleApiError(response, "list_asset_specs_for_creator");
      }
      return response.body;
    },
    async fetchAssetSpecBySlug(creatorUsername, name) {
      const response = await request({
        method: "GET",
        path: `/asset-specs/${encodeURIComponent(creatorUsername)}/${encodeURIComponent(name)}`
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_asset_spec_by_slug");
      }
      return response.body;
    },
    async listAssetSpecVersions(creatorUsername, name, options = {}) {
      const params = new URLSearchParams();
      if (typeof options.limit === "number") {
        params.set("limit", String(options.limit));
      }
      if (typeof options.offset === "number") {
        params.set("offset", String(options.offset));
      }
      const query = params.toString();
      const response = await request({
        method: "GET",
        path: `/asset-specs/${encodeURIComponent(creatorUsername)}/${encodeURIComponent(name)}/versions${query ? `?${query}` : ""}`
      });
      if (response.status !== 200) {
        handleApiError(response, "list_asset_spec_versions");
      }
      return response.body;
    },
    async fetchAssetSpecVersion(creatorUsername, name, version) {
      const response = await request({
        method: "GET",
        path: `/asset-specs/${encodeURIComponent(creatorUsername)}/${encodeURIComponent(name)}/versions/${encodeURIComponent(version)}`
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_asset_spec_version");
      }
      return response.body;
    },
    async listAssetsByAssetSpec(creatorUsername, name, options = {}) {
      const params = new URLSearchParams();
      if (typeof options.limit === "number") {
        params.set("limit", String(options.limit));
      }
      if (typeof options.offset === "number") {
        params.set("offset", String(options.offset));
      }
      if (typeof options.sort === "string" && options.sort.trim().length > 0) {
        params.set("sort", options.sort.trim());
      }
      const query = params.toString();
      const response = await request({
        method: "GET",
        path: `/asset-specs/${encodeURIComponent(creatorUsername)}/${encodeURIComponent(name)}/assets${query ? `?${query}` : ""}`
      });
      if (response.status !== 200) {
        handleApiError(response, "list_assets_by_asset_spec");
      }
      return response.body;
    },
    async listAppsByAssetSpec(creatorUsername, name, options = {}) {
      const params = new URLSearchParams();
      if (typeof options.limit === "number") {
        params.set("limit", String(options.limit));
      }
      if (typeof options.offset === "number") {
        params.set("offset", String(options.offset));
      }
      const query = params.toString();
      const response = await request({
        method: "GET",
        path: `/asset-specs/${encodeURIComponent(creatorUsername)}/${encodeURIComponent(name)}/apps${query ? `?${query}` : ""}`
      });
      if (response.status !== 200) {
        handleApiError(response, "list_apps_by_asset_spec");
      }
      return response.body;
    },
    async fetchAssetBySlug(creatorUsername, assetName) {
      const path = `/assets/${encodeURIComponent(creatorUsername)}/${encodeURIComponent(assetName)}`;
      const response = await request({
        method: "GET",
        path
      });
      if (response.status !== 200) {
        handleApiError(response, "fetch_asset_by_slug");
      }
      return response.body;
    },
    async listAssetVersions(creatorUsername, assetName, options = {}) {
      const params = new URLSearchParams();
      if (typeof options.limit === "number") {
        params.set("limit", String(options.limit));
      }
      if (typeof options.offset === "number") {
        params.set("offset", String(options.offset));
      }
      const query = params.toString();
      const path = `/assets/${encodeURIComponent(creatorUsername)}/${encodeURIComponent(assetName)}/versions${query ? `?${query}` : ""}`;
      const response = await request({
        method: "GET",
        path
      });
      if (response.status !== 200) {
        handleApiError(response, "list_asset_versions");
      }
      return response.body;
    },
    async updateAsset(creatorUsername, name, requestBody) {
      const assetName = typeof name === "string" ? name.trim() : "";
      if (!assetName) {
        throw new Error("invalid_asset_name");
      }
      const response = await request({
        method: "PATCH",
        path: buildCreatorAssetMutationPath(creatorUsername, assetName),
        body: requestBody
      });
      if (response.status !== 200) {
        handleApiError(response, "update_asset");
      }
      return response.body;
    },
    async updateAssetVersion(creatorUsername, name, revision, requestBody) {
      const assetName = typeof name === "string" ? name.trim() : "";
      if (!assetName) {
        throw new Error("invalid_asset_name");
      }
      const normalizedRevision = normalizeAssetRevisionInput(revision);
      const response = await request({
        method: "PATCH",
        path: `${buildCreatorAssetMutationPath(creatorUsername, assetName)}/versions/${encodeURIComponent(normalizedRevision)}`,
        body: requestBody
      });
      if (response.status !== 200) {
        handleApiError(response, "update_asset_version");
      }
      return response.body;
    },
    async deleteAssetVersion(creatorUsername, name, revision) {
      const assetName = typeof name === "string" ? name.trim() : "";
      if (!assetName) {
        throw new Error("invalid_asset_name");
      }
      const normalizedRevision = normalizeAssetRevisionInput(revision);
      const response = await request({
        method: "DELETE",
        path: `${buildCreatorAssetMutationPath(creatorUsername, assetName)}/versions/${encodeURIComponent(normalizedRevision)}`
      });
      if (response.status !== 200) {
        handleApiError(response, "delete_asset_version");
      }
      return response.body;
    },
    async deleteAsset(creatorUsername, name) {
      const assetName = typeof name === "string" ? name.trim() : "";
      if (!assetName) {
        throw new Error("invalid_asset_name");
      }
      const response = await request({
        method: "DELETE",
        path: buildCreatorAssetMutationPath(creatorUsername, assetName)
      });
      if (response.status !== 200) {
        handleApiError(response, "delete_asset");
      }
      return response.body;
    },
    async updateAssetSpecVersion(creatorUsername, name, version, requestBody) {
      const response = await request({
        method: "PATCH",
        path: `/creators/${encodeURIComponent(creatorUsername)}/asset-specs/${encodeURIComponent(name)}/versions/${encodeURIComponent(version)}`,
        body: requestBody
      });
      if (response.status !== 200) {
        handleApiError(response, "update_asset_spec_version");
      }
      return response.body;
    },
    async deleteAssetSpecVersion(creatorUsername, name, version) {
      const response = await request({
        method: "DELETE",
        path: `/creators/${encodeURIComponent(creatorUsername)}/asset-specs/${encodeURIComponent(name)}/versions/${encodeURIComponent(version)}`
      });
      if (response.status !== 200) {
        handleApiError(response, "delete_asset_spec_version");
      }
      return response.body;
    },
    async deleteAssetSpec(creatorUsername, name) {
      const response = await request({
        method: "DELETE",
        path: `/creators/${encodeURIComponent(creatorUsername)}/asset-specs/${encodeURIComponent(name)}`
      });
      if (response.status !== 200) {
        handleApiError(response, "delete_asset_spec");
      }
      return response.body;
    },
    async downloadAssetFile(creatorUsername, assetName, revision, options = {}) {
      const creator = typeof creatorUsername === "string" ? creatorUsername.trim() : "";
      const name = typeof assetName === "string" ? assetName.trim() : "";
      if (!creator || !name) {
        throw new Error("invalid_asset_key");
      }
      const normalizedRevision = normalizeAssetRevisionInput(revision);
      const params = new URLSearchParams();
      if (typeof options.role === "string" && options.role.trim().length > 0) {
        params.set("role", options.role.trim());
      }
      const query = params.toString();
      const path = `/assets/${encodeURIComponent(creator)}/${encodeURIComponent(name)}/versions/${encodeURIComponent(normalizedRevision)}/file${query ? `?${query}` : ""}`;
      const base = resolveBaseUrl();
      const headers = new Headers();
      for (const [key, value] of Object.entries(getClientHeaders())) {
        headers.set(key, value);
      }
      const token = await resolveToken();
      if (token) {
        headers.set("authorization", `Bearer ${token}`);
      }
      const response = await fetchImpl(resolveUrl(base, path), {
        method: "GET",
        headers,
        ...(0, import_request.buildBrowserCredentialsInit)(includeBrowserCredentials)
      });
      if (!response.ok) {
        const parsed = await parseResponseBody(response);
        handleApiError({ status: response.status, body: parsed, headers: response.headers }, "download_asset_file");
      }
      return response.blob();
    },
    async downloadAssetSource(creatorUsername, assetName, revision) {
      const creator = typeof creatorUsername === "string" ? creatorUsername.trim() : "";
      const name = typeof assetName === "string" ? assetName.trim() : "";
      if (!creator || !name) {
        throw new Error("invalid_asset_key");
      }
      const normalizedRevision = normalizeAssetRevisionInput(revision);
      const path = `/assets/${encodeURIComponent(creator)}/${encodeURIComponent(name)}/versions/${encodeURIComponent(normalizedRevision)}/source`;
      const base = resolveBaseUrl();
      const headers = new Headers();
      for (const [key, value] of Object.entries(getClientHeaders())) {
        headers.set(key, value);
      }
      const token = await resolveToken();
      if (token) {
        headers.set("authorization", `Bearer ${token}`);
      }
      const response = await fetchImpl(resolveUrl(base, path), {
        method: "GET",
        headers,
        ...(0, import_request.buildBrowserCredentialsInit)(includeBrowserCredentials)
      });
      if (!response.ok) {
        const parsed = await parseResponseBody(response);
        handleApiError({ status: response.status, body: parsed, headers: response.headers }, "download_asset_source");
      }
      const blob = await response.blob();
      const filename = parseContentDispositionFilename(response.headers.get("content-disposition")) ?? `${name}-r${normalizedRevision}-source.zip`;
      const headerSize = response.headers.get("content-length");
      const parsedSize = headerSize ? Number.parseInt(headerSize, 10) : Number.NaN;
      const checksumHeader = response.headers.get("x-asset-source-checksum");
      return {
        blob,
        metadata: {
          filename,
          sizeBytes: Number.isFinite(parsedSize) && parsedSize >= 0 ? parsedSize : blob.size,
          checksum: checksumHeader ?? null
        }
      };
    }
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  buildAssetsApiClientMethods
});
