@baukit/integrations-client

中文文档
0.18.3发布于 2026/11/07MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 8450

Provider-neutral connection state, OAuth session coordination, and provider registration for web and native clients.

原始使用文档
文档目录3 节
  1. Connection state
  2. OAuth sessions
  3. Provider registry

@baukit/integrations-client

@baukit/integrations-client provides provider-neutral client behavior for integration settings:

  • a connection reducer with fixed states and actions;
  • an OAuth coordinator with persisted state checks and strict return URL validation; and
  • a typed provider registry built from product data.

The package has no runtime dependencies. Its root entry does not import React, Expo, or browser globals.

Connection state

Map the server's connection health before applying client events:

import { connectionStateFromServer, reduceConnectionState } from '@baukit/integrations-client';

const state = connectionStateFromServer({
  state: 'needs_reconnect',
  diagnosticCode: 'authorization_revoked',
  providerDiagnostic: upstreamError,
});
const connecting = reduceConnectionState(state, { type: 'connect_requested' });

providerDiagnostic is untrusted input and is always dropped. diagnostic.code accepts only a bounded snake_case code. Products map status and availableActions to their own localized copy. They must not render the diagnostic code.

OAuth sessions

Create one coordinator with product-owned ports for storage, timers, nonce creation, and the web or native authorization runner. The coordinator saves the nonce before it opens the authorization URL. It returns success, cancelled, timed_out, invalid_return, or storage_mismatch.

import { OAuthSessionCoordinator, createReturnUrlValidator } from '@baukit/integrations-client';

const coordinator = new OAuthSessionCoordinator({
  storage,
  clock,
  timeoutMs: 15_000,
  createStateNonce,
  validateReturnUrl: createReturnUrlValidator({
    origin: 'https://app.example',
    paths: ['/settings/integrations/callback'],
  }),
  browser,
  native,
  redirect,
});

const outcome = await coordinator.authorize({
  platform: 'web',
  returnUrl: 'https://app.example/settings/integrations/callback',
  createAuthorizationUrl: startConnection,
});

On web, browser.openPlaceholder runs before any asynchronous work so a click can reserve the popup. If it returns null, the coordinator uses the injected redirect handler. After a full-page return, call handleRedirect with the current URL. Native products supply native.run and native.cancel using their auth-session library.

The validator requires the exact configured origin and one exact allowlisted path. Callback checks reject lookalike origins, path prefixes, credentials in URLs, malformed URLs, and duplicate parameters.

Provider registry

Register static product data once. The connector type belongs to the product, so it can hold an OAuth starter, product hooks, icons, or other UI-specific values without adding those dependencies to Baukit:

import { createProviderRegistry } from '@baukit/integrations-client';

const providerDefinitions = createProviderRegistry([
  {
    id: 'calendar',
    labelKey: 'integrations.calendar',
    capabilities: ['read_events'],
    connector: {
      startOAuth: startCalendarOAuth,
      useConnection: useCalendarConnection,
      icon: CalendarIcon,
    },
  },
  {
    id: 'storage',
    labelKey: 'integrations.storage',
    capabilities: ['read_files'],
    connector: {
      startOAuth: startStorageOAuth,
      useConnection: useStorageConnection,
      icon: StorageIcon,
    },
  },
] as const);

const providers = providerDefinitions.withConnectionStates(
  new Map([
    ['calendar', calendarConnectionState],
    ['storage', storageConnectionState],
  ]),
);

await providers.get('calendar')?.connector?.startOAuth();

list() keeps registration order. get() returns the typed connector and returns undefined for an unknown ID. withConnectionStates() accepts a read-only map or partial record and returns a new registry; it does not change providerDefinitions. A provider omitted from the state collection has state disconnected and no available actions. Passing connection in a registration still works for callers using the 0.2.0 API.

The registry copies capability and action arrays and rejects duplicate IDs. It keeps connector objects by reference so hooks, functions, and component identities remain stable. Persistence, provider OAuth parameters, identity, copy, and policy stay in the product.

版本与发布记录

@baukit/integrations-client 共发布 64 个版本,首次发布于 2026/09/03;过去 12 个月发布了 64 个版本。最新版本附带 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/integrations-client 的常见问题

@baukit/integrations-client 是什么?

Provider-neutral connection state, OAuth session coordination, and provider registration for web and native clients.

如何安装 @baukit/integrations-client?

在项目目录运行 npm install @baukit/integrations-client,或使用 pnpm add / yarn add / bun add。

@baukit/integrations-client 支持 TypeScript 吗?

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

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

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

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

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

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

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

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

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

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

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