@dofe/sso-node

中文文档
0.1.86发布于 2026/11/11MITTypeScriptCommonJS零依赖近 30 天下载 2723

Runtime-neutral Node SDK for sso.dofe.ai internal service APIs.

原始使用文档
文档目录6 节
  1. Install
  2. Usage
  3. Auth Modes
  4. Validation
  5. Boundary
  6. Optional session timing

@dofe/sso-node

Runtime-neutral Node SDK for sso.dofe.ai internal service APIs.

Install

pnpm add @dofe/sso-node

Usage

import { createSsoInternalClient } from '@dofe/sso-node';

const sso = createSsoInternalClient({
  baseUrl: process.env.SSO_INTERNAL_API_URL!,
  internalSecret: process.env.INTERNAL_API_SECRET!,
  serviceName: 'agents.dofe.ai',
});

const user = await sso.users.get('00000000-0000-0000-0000-000000000000');
const permissions = await sso.permissions.getUserPermissions(user.id);

For migration from older local clients that expose flat methods, use createSsoLegacyClient:

import { createSsoLegacyClient } from '@dofe/sso-node/legacy';

const sso = createSsoLegacyClient({
  baseUrl: process.env.SSO_INTERNAL_API_URL!,
  internalSecret: process.env.INTERNAL_API_SECRET!,
  internalBasePath: '/api/internal',
  authMode: 'x-internal-secret',
  serviceName: 'agents.dofe.ai',
});

const user = await sso.getUser('00000000-0000-0000-0000-000000000000');
const hasPermission = await sso.checkPermission(user.id, 'team.read', 'team-id');
const role = await sso.getUserTeamRole('team-id', user.id);

Auth Modes

ModeHeader
bearerAuthorization: Bearer <internalSecret>
x-internal-secretX-Internal-Secret: <internalSecret>

The default mode is bearer. Use x-internal-secret only for legacy services while they migrate.

The default fetcher rejects HTTP redirects for both typed methods and raw requests, including redirects to the same origin. Set baseUrl and internalBasePath to the final internal API address. This prevents forwarding service proofs or legacy secret headers to a redirect destination. A custom fetcher must enforce the same rule.

Validation

Run pnpm --filter @dofe/sso-node test to build and test the package. Redirect tests use local HTTP servers and synthetic credentials; they require no live SSO access.

Boundary

This package is a client-only SDK. It does not include NestJS modules, Redis subscribers, Prisma, migrations, seeds, or database connection logic.

Optional session timing

SessionV2ClientOptions.onTiming and SessionV2BffOptions.onTiming accept SessionV2TimingObserver, (event: SessionV2TimingEvent) => void | Promise<void>. All timing types are exported from the package root. The hook is optional; synchronous throws and asynchronous rejections are ignored, and promises are never awaited. Keep observer synchronous work short.

Events contain only phase, operation, nonnegative durationMs, outcome (success or error), and optional numeric HTTP status. No identifiers, request objects, URLs, credentials, or response payloads are emitted.

PhaseOperationBoundary
remoteexchange-code, rotate, introspect, renew-ticket, confirmation, bootstrap-exchange, logout-confirmation, logout, callSSO fetch through JSON body parsing and HTTP error handling. call is the fixed fallback for other paths. Method-level schema checks after the call are outside this span.
active-entryreadVault read, expiry and revocation checks.
admissionbegin-dispatch, begin-window-dispatchVault admission, including its remote introspection and lease acquisition.
completioncompleteVault completion commit.
compat-dispatchdispatchCompatibility upstream fetch through buffered body and completion, or stream handoff; excludes subsequent streaming duration.

Nested spans overlap: do not sum admission/completion and their remote spans. status is the original HTTP response status, even when the SDK normalizes an error to 503. A remote success describes HTTP/JSON completion, not an active session grant. Compatibility HTTP statuses >= 400 produce error outcomes without changing the upstream response. Direct transport remains in-process and emits no compat-dispatch span. Compatibility response forwarding preserves Server-Timing and the existing x-request-id; it does not inject or rewrite proof-bound request headers or forward arbitrary upstream headers. No correlation identifier is added to events; applications may associate events using their own async context.

版本与发布记录

@dofe/sso-node 共发布 83 个版本,首次发布于 2026/06/05;过去 12 个月发布了 83 个版本。

版本发布日期距今
0.1.86latest2026/11/112 天前
0.1.852026/11/0211 天前
0.1.842026/10/2816 天前
0.1.832026/10/2717 天前
0.1.822026/10/2717 天前
0.1.812026/10/2717 天前

关于 @dofe/sso-node 的常见问题

@dofe/sso-node 是什么?

Runtime-neutral Node SDK for sso.dofe.ai internal service APIs.

如何安装 @dofe/sso-node?

在项目目录运行 npm install @dofe/sso-node,或使用 pnpm add / yarn add / bun add。

@dofe/sso-node 支持 TypeScript 吗?

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

@dofe/sso-node 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@dofe/sso-node 需要什么版本的 Node.js?

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

@dofe/sso-node 可以商用吗?

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

@dofe/sso-node 的下载量有多少?

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

@dofe/sso-node 还在维护吗?

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