@depot/sdk-node

中文文档
2.3.1发布于 2026/11/05MITTypeScriptESM + CJS构建来源已验证近 30 天下载 14.1万

Node SDK for the Depot API

原始使用文档
文档目录9 节
  1. Installation
  2. Usage
  3. Example
  4. Create a client
  5. Project OIDC trust policies
  6. Registry retention policies
  7. Testing
  8. License
  9. Usage analysis

Depot API SDK for Node.js

CI npm Powered by TypeScript

A Node.js SDK for the Depot API.

👉 API Documentation

Installation

Use pnpm or your favorite package manager:

pnpm add @depot/sdk-node

Usage

Each of the Depot API services is exposed on the main depot export. The service paths match their corresponding gRPC service names. Set the DEPOT_TOKEN environment variable to authenticate requests:

export DEPOT_TOKEN=your-access-token

Example

List projects:

import {depot} from '@depot/sdk-node'

async function example() {
  const result = await depot.core.v1.ProjectService.listProjects({})
  console.log(result.projects)
}

Create a client

Use createClient() to configure a client explicitly:

import {createClient} from '@depot/sdk-node'

const client = createClient({token: 'your-access-token'})
const result = await client.core.v1.ProjectService.listProjects({})
console.log(result.projects)

createClient() accepts an optional token and baseURL. It defaults to https://api.depot.dev and does not read environment variables. If you omit token, supply an authorization header on each call that requires authentication.

To use a different token for an individual call, pass an authorization header:

const result = await depot.core.v1.ProjectService.listProjects({}, {headers: {Authorization: `Bearer ${token}`}})

Project OIDC trust policies

Use core.v1.ProjectService with an organization API token to manage which CI identities can authenticate to a Depot project. Project tokens and read-only organization tokens cannot authorize these operations.

For GitLab, use numeric namespace and project IDs. The GitLab project ID is separate from the Depot project ID:

import {createClient} from '@depot/sdk-node'

const projects = createClient({token: process.env.DEPOT_TOKEN}).core.v1.ProjectService
const projectId = 'your-depot-project-id'

const {trustPolicy} = await projects.addTrustPolicy({
  projectId,
  provider: {
    case: 'gitlab',
    value: {namespaceId: '12345', projectId: '67890', protectedRefsOnly: true},
  },
})
if (!trustPolicy) throw new Error('No trust policy returned')
console.log(trustPolicy) // Check the saved settings, especially when adding an existing policy.

const page = await projects.listTrustPolicies({projectId, pageSize: 100})
console.log(page.trustPolicies)
// When page.nextPageToken is present, pass it as pageToken with the same project/filter.

await projects.updateTrustPolicy({
  projectId,
  trustPolicyId: trustPolicy.trustPolicyId,
  protectedRefsOnly: false,
})

protectedRefsOnly: true restricts GitLab authentication to protected refs. Omitting it on a new policy defaults to false. Adding an existing policy preserves its saved restrictions; use updateTrustPolicy to change them. Updates preserve omitted fields, while explicit false disables the selected restriction. GitHub policies similarly support allowPublicPullRequests; that field is only valid for GitHub, and protectedRefsOnly is only valid for GitLab. The API also supports CircleCI and Buildkite policies.

To revoke a policy, call removeTrustPolicy({projectId, trustPolicyId}). The runnable GitLab example performs one explicit operation per invocation. From this repository, run pnpm run build, set DEPOT_TOKEN, and choose an operation:

node examples/gitlab-trust-policy.mjs list <depot-project-id>
node examples/gitlab-trust-policy.mjs add <depot-project-id> <namespace-id> <gitlab-project-id> true
node examples/gitlab-trust-policy.mjs update <depot-project-id> <policy-id> false
node examples/gitlab-trust-policy.mjs remove <depot-project-id> <policy-id>

The example lists one page of policies for all providers. Pass the returned nextPageToken as the final argument to list to fetch the next page. It prints the saved restrictions after additions and updates.

Registry retention policies

Use depot.registry.v1beta1.RegistryService with an organization API token. The token determines the organization; you don't need an organization ID or x-depot-org header. Project tokens and Registry pull/push tokens don't authorize these management calls.

Set repository to a repository path such as team/app, without a registry host or organization prefix. Use ** for the organization-default policy. Supply exactly one positive integer strategy: keepCount or keepDays. The enabled field isn't a disable switch: to remove an explicit policy, call deleteRetentionPolicy.

import {createClient} from '@depot/sdk-node'

const registry = createClient({token: process.env.DEPOT_TOKEN}).registry.v1beta1.RegistryService

// Keep the most recent 10 images for this repository.
await registry.upsertRetentionPolicy({repository: 'team/app', enabled: true, keepCount: 10})

const {policy} = await registry.getRetentionPolicy({repository: 'team/app'})
// policy is undefined when this scope has no explicit policy.

// Alternatively, set a time-based organization default.
await registry.upsertRetentionPolicy({repository: '**', enabled: true, keepDays: 30})

// Remove only the explicit repository policy; an inherited policy may still apply.
await registry.deleteRetentionPolicy({repository: 'team/app'})

getRetentionPolicy reads the explicit policy for the requested scope, not the effective inherited policy. Deleting ** removes the explicit organization default. Deleting a policy doesn't delete the repository or its images and doesn't restore images already removed by retention.

The runnable example performs one operation at a time. From this repository, build the SDK with pnpm run build, set DEPOT_TOKEN, and choose an operation:

node examples/registry-retention.mjs get team/app
node examples/registry-retention.mjs keep-count team/app 10
node examples/registry-retention.mjs keep-days '**' 30
node examples/registry-retention.mjs delete team/app

Testing

Use pnpm run fmt:check (Oxfmt), pnpm run lint (Oxlint), and pnpm run type-check for source checks. Run pnpm run package:check to build and validate the packed package with Publint and Are the Types Wrong?. See Releasing for npm setup, staged releases, and approval.

Run pnpm test to build the ESM and CommonJS packages and run the Vitest suite. Automated tests live in test/ and use local HTTP/2 endpoints without Depot credentials. The suite covers configuration, authorization, service serialization, errors, and cancellation through both package entrypoints. Default-client configuration is tested in isolated Node processes; even the default API URL is redirected locally. The src/manual-smoke.ts script is a separate manual smoke test against the live API and is excluded from automated discovery.

License

MIT License, see LICENSE.

Usage analysis

depot.core.v1.UsageAnalyticsService exposes UTC daily usage series and paginated product/project/repository/workflow breakdowns. These methods require an API deployment with UsageAnalyticsService support; older deployments return Unimplemented.

See the usage analysis guide for coverage, units, filters, pagination, and freshness. The contract is owned by depot/proto. pnpm run generate regenerates the SDK from the latest published buf.build/depot/api contract. MCP consumes this SDK through the API repository's @depot/sdk-node package dependency.

With an organization token in DEPOT_TOKEN, compare equal-length periods using:

node examples/usage-compare.mjs 2026-10-01T00:00:00Z 2026-10-08T00:00:00Z 2026-10-15T00:00:00Z owner/repo

The example follows every page, compares stable workflow keys, preserves unattributed usage, and returns vCPU-minute deltas. It does not estimate invoice amounts or send notifications.

版本与发布记录

@depot/sdk-node 共发布 16 个版本,首次发布于 2023/02/04;过去 12 个月发布了 3 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.3.1latest2026/11/057 天前
2.2.02026/10/061 个月前
2.1.02026/09/122 个月前
2.0.02025/09/171.1 年前
1.4.02025/09/121.2 年前
1.3.02025/06/251.4 年前

关于 @depot/sdk-node 的常见问题

@depot/sdk-node 是什么?

Node SDK for the Depot API

如何安装 @depot/sdk-node?

在项目目录运行 npm install @depot/sdk-node,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@bufbuild/protobuf(^2.16.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@depot/sdk-node 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@depot/sdk-node 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@depot/sdk-node 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@depot/sdk-node 可以商用吗?

@depot/sdk-node 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@depot/sdk-node 的下载量有多少?

根据 npm 官方下载统计,@depot/sdk-node 在 2026/10/12 – 2026/11/10 这 30 天内被下载 141,153 次,日均约 4,705 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@depot/sdk-node 还在维护吗?

最新版本 2.3.1 发布于 2026/11/05(7 天前);至今共发布 16 个版本,其中过去 12 个月发布了 3 个;首次发布于 2023/02/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。