@agntcy/slim-bindings
节点.js(≥18) 斯林姆语:将应用程序连接到一个SLIM服务器,打开会话,并使用与其他语言绑定相同的Rust核心交换消息.
安装
npm install @agntcy/slim-bindings
npm 安装此软件包, 当为您的 OS/ arch 发布时, 匹配的可选本地加通 (@agntcy/slim-bindings-*) (中文(简体) ). 如果安装失败并发生本地装入错误, 您的平台/ 版本组合可能还没有发布二进制 .
模块形状
这个软件包是 本地无害环境管理 (单位:千美元)require() 不支持 – 使用 import) (中文(简体) ). 已发布的条目加载生成的 UniFFI/节点绑定( 见 package.json main 编号 : types) (中文(简体) ). 从 generated/index.js 当运行在绑定的工作空间.
import slimBindings from '@agntcy/slim-bindings';
slimBindings.initializeWithDefaults();
const service = slimBindings.getGlobalService();
全部类型脚本船 types/ 在已发布的软件包中(index.d.ts (再出口).
典型流动
-
初始化 每个进程一次加密/运行时间 :
slimBindings.initializeWithDefaults() -
获得全球服务 应用程序、连接和服务器模式的切入点:
slimBindings.getGlobalService() -
身份 ——SLIM名称为三段:
organization/namespace/application(建筑师)new slimBindings.Name(org, ns, app)) (中文(简体) ). -
客户端: 创建应用程序 例如,共享机密认证:
service.createAppWithSecret(name, secret)
使用符合您部署所需的最小长度的秘密( 例如使用 32+ 字符演示字符串) . -
客户端: 连接到 SLIM 服务器 ——构建客户端配置(参见:
newInsecureClientConfig(url)然后:await service.connectAsync(config)
返回用于路由/订阅的连接 ID. -
订阅 以它的名字接收流量的应用程序, 将连接 id 作为真实
bigint(例如:.await app.subscribeAsync(name, connId)地点connId这是什么connectAsync) (中文(简体) ). -
服务器 ——对于接受客户端的网络节点,初始化方式相同,然后构建服务器配置(例如.
newInsecureServerConfig('0.0.0.0:46357'))并运行:slimBindings.getGlobalService().runServer(config)
进程必须在服务器运行时保持活性(见示例).
运输认证( gRPC 连接)
与应用程序身份分离 createAppWithSecret,GRPC连接到 SLIM
节点可通过 config.auth (和 ServerConfig.auth 在托管时).
支持的模式是 Basic, (中文(简体) ), StaticJwt, (中文(简体) ), Jwt, (中文(简体) ), Spire,以及 Oidc。 。 。 .
OIDC, 客户端( 客户证书流) :
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);
用于刷新音源的流程 refreshToken -或者说 refreshTokenFile中重写为
位置作为符号旋转——而不是 clientSecret。 。 。 .
服务器侧面, 对照发行商的 JWKS 端点验证收到的 JWT, 可选 通过索赔限制进入:
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 接受 OidcPolicyConfig.Cel, (中文(简体) ), OidcPolicyConfig.Rego (必须界定
package slim.auth 与 default allow = false),或 OidcPolicyConfig.RegoFile。仅限客户
字段( r)scope, (中文(简体) ), timeout)和只使用服务器的字段(jwksTtl, (中文(简体) ), claimCacheTtl, (中文(简体) ), policy已经
被对方忽略.
从一个配置文件 - newConfigFromJson(json) 接受完整的 gRPC 客户端配置, 覆盖 TLS
材质 后退 以及每个认证模式。 这些例子读取了同一个文件:
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" }
}
}
计划匹配 data-plane/core/config/src/grpc/schema/client-config.schema.json 输入
细 复发.
实例
可运行的脚本在下面 examples/ (从 repo 根,使用 Taskfile 目标 example:server, (中文(简体) ), example:alice, (中文(简体) ), example:bob, (中文(简体) ), example:group,或通过 npm 从 examples/ 载于 读取( README dev.md)) (中文(简体) ). example:group 演示多播(分组)会议——主持人创建频道并邀请与会者;见 读取( README dev.md) 用于使用.
类型注释
64位值( 如连接 id 从 connectAsync真实 bigint 结束至结束——按原样通过而不是转换为 Number。 。 enum 类型字段( 如 SessionConfig.sessionType)是真正的类型Script enums (SessionType.PointToPoint),不是弦词. 见 读取( README dev.md) 详细情况.
从来源建立/贡献
用于维护者的生成器设置、任务命令和出版文件 读取( README dev.md)。 。 。 .