@azphalt/repository-client
v0.5.0
Published
Client SDK for the azphalt Repository API.
Readme
@azphalt/repository-client
A small client SDK for the azphalt Repository API — the standard HTTP interface any backend can expose so a host can discover and download .azp extensions. It's the caller side of @azphalt/repository-server; the two are tested against each other end-to-end.
Use it
import { RepositoryClient } from "@azphalt/repository-client";
const client = new RepositoryClient({ url: "https://packages.example.com" });
const index = await client.getIndex(); // GET /.well-known/azphalt-repository.json
const results = await client.search({ types: ["lut"], q: "cinematic", page: 1 });
const manifest = await client.getPackage("com.example.grade");
const bytes = await client.download("com.example.grade", "1.2.0"); // the raw .azpPaid packages
If a package is marked priceStatus: "paid", the download needs a Bearer token. Pass one at construction or set it later:
const client = new RepositoryClient({ url, token: "…" });
client.setToken("…"); // e.g. after an OAuth exchangedownload() throws a clear error on 401 Unauthorized (missing/invalid token) and 402 Payment Required (no license), matching the spec's gating.
API
new RepositoryClient({ url, token?, app? })—appis this host app's reverse-DNS id; when set, search results are scoped to it (global packages plus those whosetargetAppsinclude it).setToken(token)— set or replace the Bearer token.getIndex()→ the repository's discovery document (RepositoryIndex).search({ q?, types?, tags?, page?, kind?, app? })→ a paginatedPackageSearchResponse.kindis a list of package kinds to keep (e.g.["asset"]for a host with no code sandbox,["app"]for a host directory);appoverrides the client'sappfor this call.getPackage(id)→ the package's manifest / detail.getPack(id)→ thePackManifestof akind: "pack"extension pack (read from the detail's nestedmanifest, or a flat body). Throws ifidis not a pack.resolvePack(id)→{ entries: ResolvedPackEntry[] }: each pack member with a concreteversion(its pinned one, or the member'slatest/versionfrom the repository), plusnameandpriceStatuswhen looked up. Members are resolved concurrently; each still needs its owndownloadand licence.download(id, version, opts?)→ the binary.azpas aUint8Array. It fetches in HTTPRangewindows and retries failed chunks, so an interrupted download resumes the lost bytes; if the repository ignoresRange(answers200), the whole file comes back in the first response.DownloadOptions:concurrency— chunks fetched in parallel (default4;1is sequential). Only used when the repository supports ranges.chunkSize— bytes per chunk (default 8 MiB).retries— per-chunk retries on a network error or5xx, with exponential backoff (default3).signal— anAbortSignalthat aborts the whole download.onProgress(received, total)— called as bytes arrive.
publish(azp, { signal? })→POST /packageswith the signed.azpbytes (repository-api.md§ 9). Resolves to{ status: "pending-review", id, version, review, publisher }on202(queued for review — the flagship store opens a pull request), or{ status: "published", package }on201. Any refusal throwsPublishErrorwithstatus, the envelope'scodeand per-problemdetails;501means the repository takes no publishes.
Types (RepositoryIndex, PackageSummary, PackageSearchResponse, PackManifest) come from @azphalt/azdk. Verify downloaded bytes with @azphalt/azp's verifyAzp before use.
