package-manager 0.0.1-preview.1
The Zena package manager's libraries: manifests, version selection, lockfiles, archives and the registry client
package-manager#
Client libraries for Zena packages published on AT Protocol: package manifests (zena-package.json), lockfiles (zena-lock.json), deterministic CAR source archives, dependency resolution, and registry queries. Versions and ranges are the package zena-lang:semver (packages/semver).
Usage#
import {readManifest} from 'package-manager/manifest';
import {Range} from 'zena-lang:semver';
let manifest = readManifest('{"name": "hello", "version": "1.0.0"}');
let version = manifest.version;
let matches = version != null && Range.parse('^1.0.0').includes(version);
Libraries#
package-manager/manifest: reading a package'szena-package.json, and rewriting its dependencies while keeping the rest of the file.package-manager/workspace: a workspace's packages, read from disk: the root's manifest, the packages it lists, and the ones they depend on by path.package-manager/files: which files a package publishes: its manifest'sfilespatterns, or by default every file but tests, and always the manifest, README, and license, never hidden files,node_modules, or the lockfile.package-manager/archive: source archives, the CAR files that hold a release's source. Packing is deterministic, so the same files always have the same CID, and unpacking accepts only what packing writes.package-manager/records: the profile, release, retraction, and maintainers records, an organization's members record, and the private membership entries it commits to, read from the atproto data model with the checks their lexicons describe, and written back. Also the rules for package names.package-manager/registry-methods: the NSIDs of the App View's XRPC methods.package-manager/registry: finding packages: resolving a DID, a handle, orscope:nameto a DID, a package's versions and retractions, its profile, and its releases with their proofs.package-manager/resolve: version selection, from the ranges in all of a workspace's manifests to what its lockfile pins, installing as few versions of each package as the ranges allow.package-manager/resolution: the packages a workspace's lockfile,zena-lock.json, pins, writing it, and what writing it changes in the pins already there (diffPins), including releases changed in place.package-manager/cache: the package cache, where each source archive is unpacked intosources/<CID>for the compiler to read.package-manager/fetch: fetching pinned packages into the cache. The release record's proof is checked against the account's signing key, the record and the source archive against the CIDs the lockfile pins, and the release's dependencies against the names it maps.package-manager/validate: checking a package directory and its manifest before publishing.package-manager/testing/fake-pds: an in-process PLC directory, DNS-over-HTTPS resolver, and PDS for package accounts, for testing code that finds and fetches packages.
3.9 KiB
Raw
/**
* What `zena pkg login` signs in as with OAuth: the client each App View
* describes at `CLI_CLIENT_METADATA_PATH` below its site, the page the
* person's PDS sends the browser back to, and the scope it asks for
* (package-manager.md, "Signing in from the command line"). The App View
* serves the metadata and the page (`registry/xrpc/web`,
* `registry/web/pages/sign-in`), and `zena` signs in with them, so both
* read them from here.
*/
import {JsonArray, JsonObject} from 'zena:json';
import {OAuthClient} from 'atproto/oauth';
import {ATTESTATION_TYPE} from './records.zena';
import {CREATE_WEB_SESSION, REGISTRY_METHODS} from './registry-methods.zena';
/** Where an App View serves `zena`'s client metadata, below its site: the client's `client_id`. */
export let CLI_CLIENT_METADATA_PATH = '/oauth/cli-client-metadata.json';
/** The page, below the site, that the person's PDS sends the browser back to, and that hands the answer to `zena`. */
export let CLI_CALLBACK_PATH = '/oauth/cli-callback';
/** Where `zena`'s own server takes the answer, on `127.0.0.1` and the port `state` names. */
export let LOOPBACK_CALLBACK_PATH = '/callback';
/**
* The scope `zena pkg login` asks for: writing attestation records, the
* only records `zena` writes to a maintainer's repository, and
* service-auth tokens for each of the registry's methods but the site's
* `createWebSession`, addressed to any service. A scope cannot name a
* prefix of methods, and a DID in one must name a service, which a
* `getServiceAuth` request's bare DID does not match.
*/
export function cliScope(): String {
var scope = `atproto repo:${ATTESTATION_TYPE}`;
for (let method in REGISTRY_METHODS) {
if (method != CREATE_WEB_SESSION) {
scope = `${scope} rpc:${method}?aud=*`;
}
}
return scope;
}
/** `zena`'s client at the App View whose site is at `site`, such as `https://pkg.zena-lang.dev`. */
export function cliClient(site: String): OAuthClient {
return new OAuthClient(`${site}${CLI_CLIENT_METADATA_PATH}`, `${site}${CLI_CALLBACK_PATH}`, cliScope());
}
/**
* The metadata document of `zena`'s client at the App View whose site is
* at `site`: a native public client, with DPoP, whose one redirect URI is
* the callback page on the same origin.
*/
export function cliClientMetadata(site: String): JsonObject {
let client = cliClient(site);
let redirects = new JsonArray();
redirects.push(client.redirectUri);
let grants = new JsonArray();
grants.push('authorization_code');
grants.push('refresh_token');
let responses = new JsonArray();
responses.push('code');
let metadata = new JsonObject();
metadata['client_id'] = client.clientId;
metadata['client_name'] = 'zena';
metadata['client_uri'] = site;
metadata['application_type'] = 'native';
metadata['redirect_uris'] = redirects;
metadata['scope'] = client.scope;
metadata['grant_types'] = grants;
metadata['response_types'] = responses;
metadata['token_endpoint_auth_method'] = 'none';
metadata['dpop_bound_access_tokens'] = new Box<boolean>(true);
return metadata;
}
/**
* The `state` of a sign-in whose answer the callback page hands to `zena`
* on `127.0.0.1:<port>`, or, with port 0, shows to be pasted:
* `<port>.<random>`. `random` is what makes it this sign-in's.
*/
export function callbackState(port: i32, random: String): String {
return `${port}.${random}`;
}
/**
* The port `state` names, as the callback page reads it: a number from
* 1024 to 65535 before the first `.`, or 0 when it names none, for the
* page to show the answer instead.
*/
export function portOfState(state: String): i32 {
var port = 0;
var i = 0;
while (i < state.length && i < 6) {
let b = state.getByteAt(i);
if (b == 46) { // '.'
break;
}
if (b < 48 || b > 57) {
return 0;
}
port = port * 10 + (b - 48);
i += 1;
}
if (i == 0 || i >= state.length || state.getByteAt(i) != 46 || port < 1024 || port > 65535) {
return 0;
}
return port;
}
- atproto atproto.zena-lang.pkg.zena-lang.dev ~0.0.1-preview.1
- zena-lang:semver semver.zena-lang.pkg.zena-lang.dev ~0.0.1-preview.1
| Version | Published | Dependencies | Approved by |
|---|---|---|---|
| 0.0.1-preview.1 | 2026-11-19 |
|
|