@fluidframework/test-client-utils

中文文档
1.4.0发布于 2024/04/10MITTypeScriptESM + CJS近 30 天下载 2.4万

Fluid client development and test utilities

原始使用文档
文档目录5 节
  1. InsecureTokenProvider
  2. Usage for Development with Local Tinylicious Instance
  3. Usage for Development with Azure Fluid Relay service
  4. generateTestUser
  5. Usage

@fluidframework/test-client-utils

Utilities to use while developing and testing using the service-specific clients (i.e. AzureClient, TinyliciousClient) supplied by the FluidFramework.

InsecureTokenProvider

The InsecureTokenProvider provides a class for locally generating JWT tokens, signed using a tenant key, that can be sent to Fluid services. These tokens will be used to authenticate and identify which user is sending operations from the client.

It takes in two parameters:

  • tenantKey - Used for signing the token for use with the tenantId that we are attempting to connect to on the service
  • user - Used to populate the current user's details in the audience currently editing the container

The AzureClient, from the @fluidframework/azure-client package, takes in a tokenProvider parameter as part of its constructor. This parameter can be fulfilled by using the InsecureTokenProvider that is exported here. However, it is advised to only use this for development or testing purposes as it risks exposing your Azure Fluid Relay service tenant key secret on your client side code.

Usage for Development with Local Tinylicious Instance

When using the AzureClient, you can configure it to run against a local Tinylicous instance. Please see the client's documentation on local development for more information on how to do so. In this scenario, the InsecureTokenProvider will take any value for its tenantKey parameter since we're working with a local Tinylicious instance that doesn't require any authentication. As such, we can create an instance of it like this:

const tokenProvider = new InsecureTokenProvider("fooBar", { id: "123", name: "Test User" });

Usage for Development with Azure Fluid Relay service

The AzureClient can also be configured to a deployed Azure Fluid Relay service instance as described here. Now, the configuration is using a real tenantId and the InsecureTokenProvider will need the matching tenantKey as provided during the service onboarding.

const tokenProvider = new InsecureTokenProvider("YOUR-TENANT-KEY-HERE", { id: "123", name: "Test User" });

Again, this should ONLY be used for local development as including the tenant key in the client code risks allowing malicious users to sniff it from the client bundle. Please consider using the AzureFunctionTokenProvider or your own implementation that fulfills the ITokenProvider interface as an alternative for production scenarios.

generateTestUser

A simple function that will generate a test user. This is to be used in conjuntion with InsecureTokenProvider. The response object will be { id: string, name: string}. id will be a uuid and name will be a randomly generated friendly first and last name seperated by a space.

Usage

const tokenProvider = new InsecureTokenProvider("YOUR-TENANT-KEY-HERE", generateTestUser());

版本与发布记录

@fluidframework/test-client-utils 共发布 247 个版本,首次发布于 2021/09/21;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.4.0latest2024/04/102 年前
2.0.0-internal.4.3.2canary2023/09/123 年前
1.3.72023/09/013 年前
2.0.0-internal.5.4.22023/08/203 年前
2.0.0-internal.5.3.42023/08/083 年前
2.0.0-internal.5.4.02023/08/043 年前

其他发布通道:next → 2.0.0-dev.5.2.0.169897,canary → 2.0.0-internal.4.3.2。

关于 @fluidframework/test-client-utils 的常见问题

@fluidframework/test-client-utils 是什么?

Fluid client development and test utilities

如何安装 @fluidframework/test-client-utils?

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

@fluidframework/test-client-utils 支持 TypeScript 吗?

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

@fluidframework/test-client-utils 支持 ESM 还是 CommonJS?

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

@fluidframework/test-client-utils 可以商用吗?

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

@fluidframework/test-client-utils 的下载量有多少?

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

@fluidframework/test-client-utils 还在维护吗?

最新版本 1.4.0 发布于 2024/04/10(2 年前);至今共发布 247 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/09/21。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。