@baukit/suite-client

中文文档
0.18.3发布于 2026/11/07MITTypeScriptESM + CJS构建来源已验证近 30 天下载 8014

Headless suite linking, authorization state and connected app clients.

原始使用文档
文档目录5 节
  1. Client and session
  2. Pages and native intents
  3. Hosted authorize URLs
  4. Peer metadata at config time
  5. Offline entitlement tickets

@baukit/suite-client

Headless suite linking for web and native clients. The package exports a typed HTTP client, OAuth session handling, authorize and connected-app state, return URL and native intent guards, peer opening, notices, and English, German and Spanish messages. It imports no React, Expo or browser globals.

Client and session

Construct SuiteClient with the product's authenticated JSON transport. Prefix paths with the product API base. Decode Baukit errors into an Error with a string code, such as ApiError from @baukit/api-runtime. Successful replay and delete requests have empty bodies.

Construct one SuiteSession per signed-in session and share it between the native auth session and redirect handler. Supply OAuthSessionCoordinator storage, clock, nonce, web redirect and native session adapters from @baukit/integrations-client. Web adapters redirect the same tab. Native adapters open an auth session and pass its result back. Persist OAuth state across a cold launch. The coordinator checks the return endpoint, nonce and ten-minute expiry before completing the server request.

import { SuiteClient, ConnectedApps } from '@baukit/suite-client';

// Product adapters supply transport and the configured session instance.
const client = new SuiteClient(transport);
const connectedApps = new ConnectedApps(client, session);
await connectedApps.load();
const result = await connectedApps.connect('beta');
if ((result.type === 'ready' || result.type === 'failed') && result.completed) {
  if (navigation.claimSuiteConnectionAnnouncement(result.completed.requestId)) {
    announceConnected(result.completed.peerApp);
  }
}

A successful connection refreshes the lists. connect() returns completed: { peerApp, requestId } on the ready state, or on the failed state if that refresh fails. A failed state with completed means the server connected the apps; its code describes the refresh error. Handle that error separately from the connection announcement. A later load() clears completed.

Share one SuiteNavigationStore between this caller and SuiteLinkedMachine. Its announcement guard deduplicates the native auth-session result and redirect notice by request id. The session redeems the code once even if both paths fire.

Pages and native intents

Use parseSuiteAuthorizeQuery before constructing SuiteAuthorizeMachine. Its states cover login, consent, auto-approval, account hint mismatch, denial, framed-page refusal and native consent that must open the web page. Render those states in the product UI. switchSuiteAccount logs out before starting login.

SuiteLinkedMachine keeps the callback URL in memory and asks the product to scrub codes from history. Wait for identity restoration, then call restore. Completion runs once, refreshes connected apps and creates a notice in SuiteNavigationStore. Scope that store to the product's authenticated session.

createSuiteNativeIntentValidator(scheme) permits only the suite authorize and linked pages. openSuitePeer tries the peer scheme before the configured web fallback. HTTPS is required unless the product explicitly enables loopback HTTP.

Register suiteMessages with @baukit/localization-core. Products replace {product} and render labels for their own event types. Message key and interpolation parity is checked across en, de and es.

Hosted authorize URLs

Use validateSuiteAuthorizePeer(peer, options) when loading peer configuration. peer has webUrl and optional authorizeUrl. The latter is the full hosted page URL, including the authorizing product ID. HTTPS is required; enable options.allowLoopback for loopback HTTP development. Credentials, queries and fragments are rejected.

import { suiteAuthorizeUrl, validateSuiteAuthorizePeer } from '@baukit/suite-client';

const peer = {
  webUrl: 'https://beta.example',
  authorizeUrl: 'https://account.example/suite/authorize/beta',
};
validateSuiteAuthorizePeer(peer);
const url = suiteAuthorizeUrl(peer, {
  client: 'alpha', state, codeChallenge, hint, hintDomain,
});

The configured path is preserved, including a trailing slash. The query uses client, state, code_challenge, optional hint and hint_domain. Without authorizeUrl, the endpoint stays ${webUrl}/suite/authorize. SuiteClient.start already returns the server's configured authorizeUrl; SuiteSession uses it directly. Products building URLs themselves can use the helper. Keep the local authorize page for deployments without hosted consent.

Peer metadata at config time

The dependency-free @baukit/suite-client/peers subpath has ESM and CommonJS exports. Expo config plugins can require it without loading the client or its dependencies. Products own their peers file; none ships in this package.

const { readFileSync } = require('node:fs');
const { parsePeersFile, peerLinkQuerySchemes } = require('@baukit/suite-client/peers');

const peers = parsePeersFile(JSON.parse(readFileSync(peersPath, 'utf8')));
const schemes = peerLinkQuerySchemes(peers, ownAppId);

parsePeersFile(json: unknown): PeerMetadata[] validates the schema-version-1 file with the Rust registry rules. peerLinkQuerySchemes(peers: readonly PeerMetadata[], ownAppId: string): string[] excludes the own app by id, then deduplicates and sorts schemes. Use the result for iOS LSApplicationQueriesSchemes and Android <queries>. The adoption guide has a config plugin that preserves existing entries.

See suite adoption for server wiring and the protocol contract. This package adds no CLI template capability.

Offline entitlement tickets

Import verifyTicket and TicketVerificationError from @baukit/suite-client/entitlements. Pass the compact ticket, trusted TicketJwks and { issuer, audience, now }, with now in Unix seconds. The result is TicketClaims; compare its sub with the current suite subject before granting access. Products own public-key refresh and ticket storage.

Verification uses pure JavaScript Ed25519 on web and Hermes, without WebCrypto or Node globals. It enforces the hub's strict expiry, seven-day maximum lifetime, 60-second issue-time allowance and exact claims schema. See platform adoption for server setup and stable error codes.

版本与发布记录

@baukit/suite-client 共发布 50 个版本,首次发布于 2026/10/08;过去 12 个月发布了 50 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.18.3latest2026/11/07今天
0.18.22026/11/061 天前
0.18.12026/11/062 天前
0.18.02026/11/052 天前
0.17.12026/11/034 天前
0.17.02026/11/025 天前

关于 @baukit/suite-client 的常见问题

@baukit/suite-client 是什么?

Headless suite linking, authorization state and connected app clients.

如何安装 @baukit/suite-client?

在项目目录运行 npm install @baukit/suite-client,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@baukit/localization-core(^0.18.3)、@baukit/integrations-client(^0.18.3)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@baukit/suite-client 支持 TypeScript 吗?

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

@baukit/suite-client 支持 ESM 还是 CommonJS?

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

@baukit/suite-client 需要什么版本的 Node.js?

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

@baukit/suite-client 可以商用吗?

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

@baukit/suite-client 的下载量有多少?

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

@baukit/suite-client 还在维护吗?

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