@bielu/scalar-signalr

中文文档
1.0.1发布于 2026/11/04MITTypeScriptES Module构建来源已验证近 30 天下载 8155

Interactive SignalR console plugin for the Scalar API Reference. Reads SignalR AsyncAPI bindings and lets you connect to hubs, invoke methods and subscribe to server events.

原始使用文档
文档目录6 节
  1. Standalone usage (CDN)
  2. Programmatic usage
  3. Auth integration
  4. How credentials are mapped to the SignalR client
  5. Build
  6. License

@bielu/scalar-signalr

An interactive SignalR console plugin for the Scalar API Reference.

It reads the SignalR bindings (signalr or x-signalr) from your AsyncAPI document(s) and renders a panel where you can connect to a hub, invoke client-to-server methods, and watch server-to-client events live. It is built as a drop-in replacement for the default scalar.js bundle: loading it re-exposes window.Scalar.createApiReference with the SignalR plugin already registered.

This package is produced from, and consumed by, the Bielu.AspNetCore.AsyncApi.Scalar.SignalR .NET package (which embeds the built bundle), but it is also published standalone to npm so it can be loaded from a CDN or bundled by hand.

Standalone usage (CDN)

<div id="app"></div>
<!-- Replaces the default scalar.js bundle -->
<script src="https://cdn.jsdelivr.net/npm/@bielu/scalar-signalr/dist/standalone.js"></script>
<script>
  window.__BIELU_SCALAR_SIGNALR__ = {
    documents: [{ name: 'signalr', url: '/asyncapi/signalr.json' }],
  }
  Scalar.createApiReference('#app', {
    sources: [{ url: '/asyncapi/signalr.json' }],
  })
</script>

The SignalR documents can be provided either via the global window.__BIELU_SCALAR_SIGNALR__ or inline on the Scalar config as config.signalr.

Programmatic usage

import { createApiReference, createSignalRPlugin } from '@bielu/scalar-signalr'

// Either use the wrapper (auto-registers the plugin) …
createApiReference('#app', { sources: [{ url: '/asyncapi/signalr.json' }] })

// … or register the plugin yourself on the stock Scalar API Reference:
// plugins: [createSignalRPlugin([{ name: 'signalr', url: '/asyncapi/signalr.json' }])]

Auth integration

Scalar owns the top-level Authentication UI. When the user selects a security scheme there, the SignalR console picks up the credentials automatically at Connect time — no separate login step is needed.

Requires Scalar ≥ 2.16.12 (the plugin auth-state API, upstreamed in scalar/scalar#9639). On older Scalar versions that predate the API, the console connects without credentials (graceful no-op).

How credentials are mapped to the SignalR client

SchemeLocationSignalR mapping
apiKeyqueryKey appended to hub URL as ?<name>=<value>
apiKeyheaderWarning logged — browser WS/SSE cannot set headers; falls back to query
http bearer—accessTokenFactory: () => token
oauth2 / openIdConnect—accessTokenFactory: () => token
http basic—Warning logged — not sendable over WS/SSE; connect proceeds without auth

The scheme definition is read from components.securitySchemes in the AsyncAPI document. The console matches the Scalar document name to the selected scheme; if no exact match is found it falls back to the sole document in Scalar's exported auth state.

Build

npm install
npm run build      # -> dist/plugin.js (IIFE) + dist/scalar-plugin.mjs (ESM) + dist/standalone.js + dist/types
npm run typecheck

Three build outputs, with three different contracts — they are not interchangeable:

OutputContractUsed by
dist/plugin.jsIIFE; installs itself by hooking window.Scalar.createApiReferenceMapScalarSignalRAssets(), which serves it next to Scalar's own bundle
dist/scalar-plugin.mjsES module; default export is the plugin, registers nothing itselfScalar's pluginUrls option — how the Aspire package adds the console to the stock container
dist/standalone.jsScalar's prebuilt browser bundle with the plugin appendedpages where nothing else loads Scalar; replaces Scalar's own bundle

License

MIT © Arkadiusz Biel

版本与发布记录

@bielu/scalar-signalr 共发布 95 个版本,首次发布于 2026/07/16;过去 12 个月发布了 95 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.0.1latest2026/11/043 天前
1.0.1-beta.20261104151236beta2026/11/043 天前
1.0.1-beta.202611041331502026/11/043 天前
1.0.1-beta.202611030955042026/11/035 天前
1.0.1-beta.202611030953582026/11/035 天前
1.0.1-beta.202610250832222026/10/2514 天前

关于 @bielu/scalar-signalr 的常见问题

@bielu/scalar-signalr 是什么?

Interactive SignalR console plugin for the Scalar API Reference. Reads SignalR AsyncAPI bindings and lets you connect to hubs, invoke methods and subscribe to server events.

如何安装 @bielu/scalar-signalr?

在项目目录运行 npm install @bielu/scalar-signalr,或使用 pnpm add / yarn add / bun add。

@bielu/scalar-signalr 支持 TypeScript 吗?

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

@bielu/scalar-signalr 支持 ESM 还是 CommonJS?

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

@bielu/scalar-signalr 可以商用吗?

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

@bielu/scalar-signalr 的下载量有多少?

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

@bielu/scalar-signalr 还在维护吗?

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