@equinor/fusion-framework-module-services

中文文档
8.2.0发布于 2026/11/12ISCTypeScriptES Module近 30 天下载 9298
原始使用文档
文档目录13 节
  1. Features
  2. Installation
  3. Usage
  4. Enable the module
  5. Custom client factory
  6. Create and use API clients
  7. API Reference
  8. Module setup
  9. Provider
  10. Domain clients
  11. Types and utilities
  12. Operational telemetry
  13. Configuration

@equinor/fusion-framework-module-services

Typed API service clients for the Fusion Framework. Provides factory-based access to platform backend services (app state, bookmarks, context, notification, people) with versioned endpoints, automatic HTTP client resolution, and response validation.

Features

  • Domain-specific API clients — AppStateApiClient, BookmarksApiClient, ContextApiClient, NotificationApiClient, PeopleApiClient
  • Versioned endpoints — each service exposes version-aware methods (e.g. v1, v2, v4) with type-safe request/response shapes
  • Dual consumption patterns — every endpoint supports both Promise (json) and observable (json$) return types
  • Automatic HTTP client resolution — resolves named clients through the HTTP module, falling back to service-discovery
  • Response validation — built-in response handler validates HTTP status codes and throws structured ApiProviderError on failure
  • Zod schema selectors — schemaSelector utility for runtime response parsing with Zod schemas
  • Bookmark Zod schemas — pre-built Zod schemas (ApiBookmarkSchema, ApiBookmarkPayload) for bookmark entities

Installation

pnpm add @equinor/fusion-framework-module-services

Usage

Enable the module

Register the services module during app configuration:

import { enableServices } from '@equinor/fusion-framework-module-services';

export const configure = (configurator) => {
  enableServices(configurator);
};

Custom client factory

Override HTTP client resolution with configureServices:

import { configureServices } from '@equinor/fusion-framework-module-services';

export const configure = (configurator) => {
  configurator.addConfig(
    configureServices((cfg) => {
      cfg.createClient = async (name) => myHttpClientFactory(name);
    }),
  );
};

Create and use API clients

Access the services provider at runtime to create domain clients:

// App State
const appState = await provider.services.createAppStateClient('json');
const apps = await appState.listMyApps('v1');
await appState.wipeMyAppState('v1', { appKey: 'my-app' });

// Bookmarks
const bookmarks = await provider.services.createBookmarksClient('json');
const allBookmarks = await bookmarks.query('v1');
const single = await bookmarks.get('v1', { bookmarkId: 'abc-123' });

// Context
const context = await provider.services.createContextClient('json');
const ctx = await context.get('v1', { id: 'context-id' });
const results = await context.query('v1', { query: 'my search' });

// Notifications
const notifications = await provider.services.createNotificationClient('json');
const all = await notifications.getAll('v1');
await notifications.setSeenByUser('v1', { notificationId: 'notif-id' });

// People
const people = await provider.services.createPeopleClient();
const person = await people.get('v4', 'json', { azureId: 'azure-unique-id' });
const photo = await people.photo('v2', 'blob', { azureId: 'azure-unique-id' });

API Reference

Module setup

ExportDescription
enableServicesRegister the services module with the framework configurator
configureServicesCreate a module config object with a custom configuration callback
moduleThe raw module definition

Provider

ExportDescription
ApiProvider / IApiProviderServices provider with factory methods for creating domain clients
ApiConfigurator / IApiConfiguratorConfiguration interface (set createClient to override HTTP client resolution)
ApiProviderErrorStructured error thrown on non-OK HTTP responses

Domain clients

ClientImport pathServices
AppStateApiClient@equinor/fusion-framework-module-services/app-stateGet/wipe own app state, admin get/wipe per-user or per-app state
BookmarksApiClient@equinor/fusion-framework-module-services/bookmarksCRUD bookmarks, favourites
ContextApiClient@equinor/fusion-framework-module-services/contextGet, query, related contexts
NotificationApiClient@equinor/fusion-framework-module-services/notificationCRUD notifications, settings
PeopleApiClient@equinor/fusion-framework-module-services/peopleGet, query, photo, suggest, resolve

Types and utilities

ExportDescription
ClientMethodMaps json / json$ to Promise / StreamResponse
ClientDataMethodMaps blob / blob$ for binary responses
ApiClientFactoryFactory function type for creating named HTTP clients
FilterAllowedApiVersionsUtility type for constraining API version unions
ExtractApiVersionUtility type for resolving a version key to its string value
UnsupportedApiVersionError class for invalid API version strings
extractVersionResolves a version key or value from an API-version enum
schemaSelectorCreates a response selector that validates with a Zod schema
isApiPersonType-guard factory for validating person entities by API version

Operational telemetry

When the telemetry module is available, ApiProvider records one fusion.services.create-client.duration metric per API client it creates, for named, service-discovery and custom factories alike, with one sanitized fusion.services.create-client.failure exception when no client can be created. Service names, URIs and errors are never recorded. Discovery resolution and HTTP attempts are reported by their own modules.

Configuration

The services module depends on:

  • @equinor/fusion-framework-module-http — provides named HTTP clients
  • @equinor/fusion-framework-module-service-discovery (optional) — automatic client resolution via service discovery

When neither a registered HTTP client nor service-discovery is available for a service name, the module throws an error during client creation.

版本与发布记录

@equinor/fusion-framework-module-services 共发布 165 个版本,首次发布于 2022/10/03;过去 12 个月发布了 24 个版本。

版本发布日期距今
8.2.0latest2026/11/121 天前
8.2.0-next.1next2026/11/112 天前
8.2.0-next.02026/10/2816 天前
8.1.52026/10/1727 天前
8.1.5-trusted-publishing-20261015-9dfe7602cd2a49a8a9df00d62c26e7304a82a85atrusted-publishing-202610152026/10/1629 天前
8.1.42026/10/1529 天前

其他发布通道:apploader → 6.0.3-apploader-be21a6b60eb13eee8bf869e75002d8634e9c50a9,cli-search-index → 7.1.5-cli-search-index.0,msal-v5 → 7.1.8-msal-v5.0,trusted-publishing-20261015 → 8.1.5-trusted-publishing-20261015-9dfe7602cd2a49a8a9df00d62c26e7304a82a85a,next → 8.2.0-next.1。

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

如何安装 @equinor/fusion-framework-module-services?

在项目目录运行 npm install @equinor/fusion-framework-module-services,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:odata-query(^8.0.0)、@equinor/fusion-framework-module(^6.2.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@equinor/fusion-framework-module-services 支持 TypeScript 吗?

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

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

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

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

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

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

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

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

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