@agntcy/slim-bindings

中文文档
3.3.9发布于 2026/10/27Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 11.8万

SLIM Node.js bindings using UniFFI

原始使用文档
文档目录8 节
  1. Install
  2. Module shape
  3. Typical flow
  4. Transport authentication (gRPC connection)
  5. Examples
  6. Type notes
  7. Building from source / contributing
  8. Links

@agntcy/slim-bindings

Node.js (≥18) bindings for SLIM: connect apps to a SLIM server, open sessions, and exchange messages using the same Rust core as other language bindings.

Install

npm install @agntcy/slim-bindings

npm installs this package and, when published for your OS/arch, the matching optional native addon (@agntcy/slim-bindings-*). If install fails with a native-load error, your platform/version combo may not have a published binary yet.

Module shape

This package is native ESM (require() is not supported — use import). The published entry loads the generated UniFFI/Node bindings (see package.json main / types). Examples in this repo import from generated/index.js when running inside the bindings workspace.

import slimBindings from '@agntcy/slim-bindings';

slimBindings.initializeWithDefaults();
const service = slimBindings.getGlobalService();

Full TypeScript types ship under types/ in the published package (index.d.ts re-exports them).

Typical flow

  1. Initialize crypto/runtime once per process:

    slimBindings.initializeWithDefaults()

  2. Obtain the global service — entry point for apps, connections, and server mode:

    slimBindings.getGlobalService()

  3. Identity — SLIM names are three segments: organization/namespace/application (constructor new slimBindings.Name(org, ns, app)).

  4. Client: create an app — e.g. shared-secret auth:

    service.createAppWithSecret(name, secret)
    Use a secret that meets the minimum length required by your deployment (examples use a 32+ character demo string).

  5. Client: connect to the SLIM server — build a client config (see newInsecureClientConfig(url) for development-style HTTP to the server), then:

    await service.connectAsync(config)
    Returns a connection id used for routing/subscriptions.

  6. Subscribe the app to receive traffic for its name, passing the connection id as a real bigint (e.g. await app.subscribeAsync(name, connId) where connId is what connectAsync returned).

  7. Server — for a network node that accepts clients, initialize the same way, then build a server config (e.g. newInsecureServerConfig('0.0.0.0:46357')) and run:

    slimBindings.getGlobalService().runServer(config)
    The process must stay alive while the server runs (see examples).

Transport authentication (gRPC connection)

Separate from the app identity given to createAppWithSecret, the gRPC connection to a SLIM node can carry its own credentials via config.auth (and ServerConfig.auth when hosting). Supported modes are Basic, StaticJwt, Jwt, Spire, and Oidc.

OIDC, client side (client-credentials flow):

const config = slimBindings.newInsecureClientConfig('http://127.0.0.1:46357');
config.auth = new slimBindings.ClientAuthenticationConfig.Oidc({
  config: {
    issuerUrl: 'https://auth.example.com',
    clientId: 'my-client',
    clientSecret: 's3cr3t',
    scope: 'openid profile',
    timeout: 30_000, // durations are milliseconds
  },
});

const connId = await service.connectAsync(config);

For the refresh-token flow set refreshToken — or refreshTokenFile, which is rewritten in place as tokens rotate — instead of clientSecret.

Server side, verifying incoming JWTs against the issuer's JWKS endpoint, optionally restricting access by claim:

const config = slimBindings.newInsecureServerConfig('0.0.0.0:46357');
config.auth = new slimBindings.ServerAuthenticationConfig.Oidc({
  config: {
    issuerUrl: 'https://auth.example.com',
    audience: 'slim', // required for verification
    jwksTtl: 3_600_000,
    policy: new slimBindings.OidcPolicyConfig.Cel({ expression: '"admin" in claims.groups' }),
  },
});

policy accepts OidcPolicyConfig.Cel, OidcPolicyConfig.Rego (which must define package slim.auth with default allow = false), or OidcPolicyConfig.RegoFile. Client-only fields (scope, timeout) and server-only fields (jwksTtl, claimCacheTtl, policy) are ignored by the other side.

From a config file — newConfigFromJson(json) accepts a full gRPC client config, covering TLS material, backoff, and every authentication mode. The examples read the same document from SLIM_CLIENT_CONFIG:

{
  "endpoint": "http://127.0.0.1:46357",
  "tls": { "insecure": true },
  "auth": {
    "type": "oidc",
    "issuer_url": "https://auth.example.com",
    "client_id": "my-client",
    "client_secret": "s3cr3t",
    "audience": "slim",
    "policy": { "cel": "\"admin\" in claims.groups" }
  }
}

The schema matches data-plane/core/config/src/grpc/schema/client-config.schema.json in the slim repo.

Examples

Runnable scripts live under examples/ (from repo root, use the Taskfile targets example:server, example:alice, example:bob, example:group, or run them via npm from examples/ as documented in README_dev.md). example:group demonstrates multicast (group) sessions — a moderator creates a channel and invites participants; see README_dev.md for usage.

Type notes

64-bit values (like the connection id from connectAsync) are real bigint end to end — pass them through as-is rather than converting to Number. Enum-typed fields (like SessionConfig.sessionType) are real TypeScript enums (SessionType.PointToPoint), not string literals. See README_dev.md for details.

Building from source / contributing

Generator setup, Task commands, and publishing are documented for maintainers in README_dev.md.

版本与发布记录

@agntcy/slim-bindings 共发布 32 个版本,首次发布于 2026/02/26;过去 12 个月发布了 32 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
3.3.9latest2026/10/279 天前
3.3.82026/10/2115 天前
3.3.72026/10/2115 天前
3.3.62026/10/1818 天前
3.3.52026/10/1818 天前
3.3.42026/10/1818 天前

其他发布通道:alpha → 2.0.0-alpha.7,rc → 2.1.1-rc.3。

关于 @agntcy/slim-bindings 的常见问题

@agntcy/slim-bindings 是什么?

SLIM Node.js bindings using UniFFI

如何安装 @agntcy/slim-bindings?

在项目目录运行 npm install @agntcy/slim-bindings,或使用 pnpm add / yarn add / bun add。

@agntcy/slim-bindings 支持 TypeScript 吗?

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

@agntcy/slim-bindings 支持 ESM 还是 CommonJS?

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

@agntcy/slim-bindings 需要什么版本的 Node.js?

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

@agntcy/slim-bindings 可以商用吗?

@agntcy/slim-bindings 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@agntcy/slim-bindings 的下载量有多少?

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

@agntcy/slim-bindings 还在维护吗?

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