@equinor/fusion-framework

中文文档
9.1.0发布于 2026/11/12ISCTypeScriptES Module近 30 天下载 1万
原始使用文档
文档目录13 节
  1. What is this package?
  2. Quick start
  3. Key concepts
  4. API surface
  5. Common patterns
  6. Configure a named HTTP client
  7. Optional authentication
  8. Extend with custom modules
  9. Diagnose HTTP transport failures
  10. Built-in modules
  11. Testing
  12. Documentation
  13. Further reading

@equinor/fusion-framework

Bootstrap and configure the core Fusion Framework module graph — authentication, HTTP, service discovery, context, telemetry, and more — in a single initialization call.

What is this package?

@equinor/fusion-framework is the top-level entry point for starting a Fusion Framework instance. It bundles the built-in module set (MSAL auth, HTTP client factory, service discovery, services, context, event bus, and telemetry) behind a single FrameworkConfigurator / init API so consumers do not have to wire each module individually.

Use this package when you are building a portal shell, a standalone application host, or any runtime that needs the full Fusion module stack. Micro-frontend applications that run inside an already-initialized portal typically use @equinor/fusion-framework-react-app instead.

Quick start

import { FrameworkConfigurator, init } from '@equinor/fusion-framework';

// 1. Create a configurator
const configurator = new FrameworkConfigurator();

// 2. Set up authentication (MSAL)
configurator.configureMsal({
  clientId: '<your-client-id>',
  authority: 'https://login.microsoftonline.com/<your-tenant-id>',
});

// 3. Point service discovery at your registry
configurator.configureServiceDiscovery({
  client: { baseUri: 'https://service-registry.example.com' },
});

// 4. Bootstrap — resolves all modules and assigns window.Fusion
const fusion = await init(configurator);
console.log(fusion.modules); // fully initialized module instances

Key concepts

ConceptDescription
FrameworkConfiguratorCollects configuration for every module before initialization. Provides typed helpers such as configureMsal, configureHttp, configureHttpClient, and configureServiceDiscovery.
initAsync function that takes a FrameworkConfigurator, initializes all modules, sets window.Fusion, and dispatches the onFrameworkLoaded event.
FusionModulesType alias describing every built-in module descriptor (context, event, HTTP, MSAL, services, service-discovery, telemetry) plus any additional custom modules.
FusionThe root runtime object returned by init. Contains the modules map with all live module instances.

API surface

ExportKindPurpose
FrameworkConfiguratorclassConfigure modules before initialization
FusionConfiguratoraliasDeprecated — use FrameworkConfigurator
init / defaultfunctionBootstrap the framework from a configurator
FusionModulestypeBuilt-in + custom module descriptor union
FusionModulesInstancetypeResolved instance map after initialization
FusioninterfaceRoot object exposed on window.Fusion
FusionRenderFntypeCallback signature for mounting an application into a DOM element

Common patterns

Configure a named HTTP client

configurator.configureHttpClient('my-api', {
  baseUri: 'https://api.example.com',
  defaultHeaders: { 'X-Custom': 'value' },
});

Optional authentication

// Pass `false` as second argument to make auth optional
configurator.configureMsal(msalConfig, false);

Extend with custom modules

import { FrameworkConfigurator, init } from '@equinor/fusion-framework';
import myCustomModule from './my-custom-module';

const configurator = new FrameworkConfigurator<[typeof myCustomModule]>();
configurator.addConfig({ module: myCustomModule, configure: (b) => { /* … */ } });
const fusion = await init(configurator);

Diagnose HTTP transport failures

FrameworkConfigurator instruments the framework's HTTP clients with createHttpTelemetry from @equinor/fusion-framework-module-telemetry/integrations. Each actual fetch attempt produces one fusion.http.request.duration metric with a success, failure (rejected fetch or non-2xx response) or cancelled (aborted signal) outcome, and a failed attempt adds one sanitized fusion.http.request.failure. URLs, headers, bodies, tokens and original errors are never recorded.

The middleware is appended after every configuration callback, so retry middleware you register wraps it and every retry is its own attempt. Timing ends when fetch resolves, not when a streamed body finishes. Token acquisition is reported separately by the auth module, and service discovery by its own records. Telemetry is connected after initialization, so requests made while modules initialize are not recorded. Exporter requests marked with markTelemetryExportRequest are excluded, and a client configured with its own middlewareHandler is not instrumented. No exporter is created.

// Opt out of framework HTTP diagnostics; other operational telemetry is unchanged.
const configurator = new FrameworkConfigurator({ httpTelemetry: false });

App modules configure their own HTTP module, which this setting does not instrument.

Built-in modules

The framework ships with the following modules enabled by default:

  • @equinor/fusion-framework-module-event — cross-module event bus
  • @equinor/fusion-framework-module-msal — MSAL / Azure AD authentication
  • @equinor/fusion-framework-module-http — HTTP client factory and named clients
  • @equinor/fusion-framework-module-service-discovery — runtime service endpoint resolution
  • @equinor/fusion-framework-module-services — typed service clients
  • @equinor/fusion-framework-module-context — application / project context selection
  • @equinor/fusion-framework-module-telemetry — telemetry, logging, and metadata

Testing

Import from @equinor/fusion-framework/mock to initialize the framework in a test without credentials, without network access and without configuration.

import { createMockToken, mockFramework } from '@equinor/fusion-framework/mock';

const fusion = await mockFramework((configurator) => {
  configurator.msal.setAcquireToken(({ clientId, scopes }) =>
    createMockToken({
      aud: clientId,
      scp: scopes.join(' '),
      name: 'Ada Lovelace',
      preferred_username: '[email protected]',
      oid: 'ada-lovelace',
    }),
  );
  configurator.serviceDiscovery.setBaseUri('http://localhost:6669');
});

const token = await fusion.modules.auth.acquireAccessToken();
const apps = await fusion.modules.serviceDiscovery.resolveService('apps');

The real configure → initialize pipeline runs with the real built-in modules; only the boundaries that leave the process — the MSAL client and the service discovery client — are substituted. Module wiring, configuration validation and lifecycle hooks therefore behave as they do in production, so a test still catches wiring mistakes.

The entry point has no test-runner dependency, and ships no mocking API of its own — spying on an individual call is your test runner's job.

Documentation

GuideCovers
Choosing a testing layerWhich import to use for React app, framework, module, HTTP, and runner-level tests
TestingChoosing the user, signed-out tests, composing the service registry, spying, and configuring as an application does
Testing — designWhat is substituted and why, where mocks live, determinism, and test-runner support
Testing — adding a mock for another moduleGiving your own module a test double, and which framework modules are not covered yet
Testing — APIEvery mock export and the package that owns it

Further reading

📚 Full documentation

版本与发布记录

@equinor/fusion-framework 共发布 339 个版本,首次发布于 2021/06/08;过去 12 个月发布了 53 个版本。

版本发布日期距今
9.1.0latest2026/11/121 天前
9.1.0-next.3next2026/11/112 天前
9.0.72026/11/112 天前
9.1.0-next.22026/10/2915 天前
9.1.0-next.12026/10/2816 天前
9.1.0-next.02026/10/2816 天前

其他发布通道:msal-v5 → 7.4.3-msal-v5.1,trusted-publishing-20261015 → 9.0.5-trusted-publishing-20261015-9dfe7602cd2a49a8a9df00d62c26e7304a82a85a,next → 9.1.0-next.3。

关于 @equinor/fusion-framework 的常见问题

如何安装 @equinor/fusion-framework?

在项目目录运行 npm install @equinor/fusion-framework,或使用 pnpm add / yarn add / bun add。

@equinor/fusion-framework 支持 TypeScript 吗?

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

@equinor/fusion-framework 支持 ESM 还是 CommonJS?

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

@equinor/fusion-framework 可以商用吗?

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

@equinor/fusion-framework 的下载量有多少?

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

@equinor/fusion-framework 还在维护吗?

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