PackagePass

TypeScript SDK

Automate package distribution from your product, CI, and internal tools.

Use @packagepass/sdk when registry access belongs inside an onboarding flow, customer workspace lifecycle, release pipeline, or generated-code publishing system.

install
npm install @packagepass/sdk

# or
pnpm add @packagepass/sdk
bun add @packagepass/sdk

Create a client

client.ts
import { PackagePassClient } from "@packagepass/sdk";

export const packagepass = new PackagePassClient({
  apiKey: process.env.PACKAGEPASS_API_KEY!,
  tenant: "acme",
  apiUrl: "https://api.preview.packagepass.dev/v1",
  registryUrl: "https://registry.preview.packagepass.dev/npm/",
  userAgent: "acme-control-plane/1.0"
});

Tenant header

The tenant option sends x-packagepass-tenant on API calls. You can also pass tenantId to many resource methods.

Custom fetch

Pass fetch when running in a framework, worker runtime, test harness, or environment that wraps outbound requests.

Packages

Create packages and publish tarballs

The SDK publish methods expect the already-built package manifest and tarball bytes. Use the CLI when you want PackagePass to run npm pack for you.

create package
await packagepass.packages.create({
  name: "@acme/payments",
  visibility: "private",
  description: "Customer payments SDK"
});
publish tarball
import { readFile } from "node:fs/promises";

const manifest = JSON.parse(
  await readFile("packages/payments/package.json", "utf8")
);
const tarball = await readFile("acme-payments-4.8.0.tgz");

await packagepass.versions.publishTarball({
  packageName: "@acme/payments",
  version: manifest.version,
  tag: "latest",
  manifest,
  tarball
});

Publish preview builds

preview
const preview = await packagepass.previews.publishTarball({
  packageName: "@acme/auth",
  channel: "pr-482",
  manifest,
  tarball,
  provenance: {
    pullRequest: 482,
    commit: process.env.GITHUB_SHA
  }
});

console.log(preview.install.npm);

Preview result

A preview publish returns the generated version, the preview-<channel> tag, and install commands for npm and Bun.

Access

Grant access and mint tokens

Use grants for policy and tokens for credentials. Install tokens should be short-lived and scoped to the smallest package and subject possible.

grant customer install
await packagepass.grants.create({
  subject: { type: "customer", slug: "globex" },
  resource: { type: "package", name: "@acme/payments" },
  actions: ["package:install"],
  conditions: {
    expiresAt: "2026-05-26T00:00:00.000Z"
  }
});
create install token
const token = await packagepass.tokens.createInstallToken({
  name: "globex payments install",
  subject: { type: "customer", slug: "globex" },
  resources: [{
    type: "package",
    name: "@acme/payments",
    actions: ["package:install"]
  }],
  expiresAt: new Date(Date.now() + 30 * 864e5).toISOString()
});

Generate installer config

install config
const config = await packagepass.config.generateInstallConfig({
  scope: "@acme",
  manager: "npm",
  tokenEnvVar: "PACKAGEPASS_TOKEN"
});

console.log(config.file);
console.log(config.content);

Policy, audit, and validation

policy
await packagepass.policy.explain({
  subject: { type: "user", email: "alice@example.com" },
  action: "package:install",
  resource: { type: "package", name: "@acme/payments" }
});
audit
await packagepass.audit.listEvents({
  packageName: "@acme/payments",
  type: "package.downloaded",
  limit: 50
});
validation
await packagepass.validation.validateManifest({
  name: "@acme/payments",
  version: "4.8.0",
  type: "module",
  types: "./dist/index.d.ts"
});

Handle errors

PackagePassError
import { PackagePassError } from "@packagepass/sdk";

try {
  await packagepass.packages.get("@acme/payments");
} catch (error) {
  if (error instanceof PackagePassError) {
    console.error(error.status);
    console.error(error.code);
    console.error(error.requestId);
    console.error(error.details);
  }
}

Keep the request ID

API errors include a request ID. Log it with the error code and status so a failed publish, grant, or install can be traced through audit and server logs.

SDK resource reference

ResourceMethodsUse
packagepass.tenantscreate, listTenant administration and bootstrap setup.
packagepass.scopescreate, listCreate npm scopes and read their registry URLs.
packagepass.packagescreate, list, get, update, archiveManage package metadata and lifecycle.
packagepass.versionspublishTarball, list, get, deprecate, yank, listDistTags, setDistTag, deleteDistTagPublish release tarballs and manage release metadata.
packagepass.previewspublishTarball, listPublish preview artifacts and read active preview versions.
packagepass.grantscreate, list, revokeGrant and revoke subject access.
packagepass.subjectscustomers, agents, groupsCreate, list, update, and delete product identities used in grants and tokens.
packagepass.tokenscreateApiToken, createInstallToken, exchangeCiToken, list, revokeMint, exchange, audit, and revoke scoped credentials.
packagepass.configgenerateInstallConfigGenerate .npmrc or bunfig.toml content.
packagepass.policyexplainDebug an authorization decision for a subject and resource.
packagepass.auditlistEventsRead audit events for packages and tenant operations.
packagepass.validationvalidateManifestRun package policy validation before publishing.

Subject and action types

SubjectUse
user:alice@example.comA person identified by email.
customer:globexA customer account or tenant in your product.
agent:code-reviewerA non-human actor such as an AI agent, service, or CI job.
group:platformA team or group.
package:read
package:install
package:publish
package:deprecate
package:yank
package:manage_dist_tags
grant:manage
token:mint
audit:read

The SDK re-exports shared PackagePass types such as SubjectRef, ResourceRef, PackageAction, RegistryPackage, RegistryVersion, and PackagePassError. See the API reference for endpoint-level details.