import { createClient as createV1Client, type MarketV1Client, type MarketV1ClientOptions, } from './v1/client.js' import { lookupAssets } from './refs.js' /** The Market client — the v1 REST client; the RPC wire format is gone. */ export type MarketClient = MarketV1Client export type MarketClientOptions = MarketV1ClientOptions /** * A version's zip as bytes, fetched from the content-plane URL the v1 manifest mints. The stream * is deterministic (store-mode entries, fixed mtimes), so two calls for the same immutable version * are byte-identical — which is what upload's "unchanged, skip publishing" check compares against. */ export async function downloadAssetZipBytes(opts: { name: string version: string baseUrl?: string authToken?: string /** The asset's capability key, an alternative credential to identity for private/unapproved assets. */ key?: string fetch?: typeof globalThis.fetch }): Promise { const client = createV1Client({ baseUrl: opts.baseUrl, authToken: opts.authToken, fetch: opts.fetch, }) const [entry] = await lookupAssets(client.asset, [{ name: opts.name, version: opts.version }], { includeUnapproved: true, ...(opts.key ? { key: opts.key } : {}), }) if (!entry) { throw new Error(`Asset "${opts.name}@${opts.version}" not found`) } const doFetch = opts.fetch ?? globalThis.fetch const response = await doFetch(entry.zipUrl) if (!response.ok) { throw new Error(`Download of ${opts.name}@${opts.version} failed (${response.status})`) } return new Uint8Array(await response.arrayBuffer()) }