@defra/lis-hubs-infra-registry

中文文档
0.13.8发布于 2026/11/10OGL-UK-3.0ES Module零依赖构建来源已验证近 30 天下载 8864

Shared infra registry metadata for the livestock platform.

原始使用文档
文档目录17 节
  1. Installation
  2. Usage
  3. Constants
  4. Lookups
  5. Module entries
  6. Adding a module
  7. Prerequisites
  8. Setup
  9. Development
  10. Test
  11. Running in development
  12. Running tests
  13. Pipelines
  14. Branching policy
  15. Contributing to this project
  16. Licence
  17. About the licence

lis-hubs-infra-registry

Part of the Livestock Information Service (LIS), which lets livestock keepers, owners, agents and delegates record and manage their animals.

@defra/lis-hubs-infra-registry is a shared npm package that holds the registry of LIS modules (the spoke apps, with their paths, ports, species, taxonomies and hubs), plus the supported species and taxonomies, and small helpers to look them up.

It holds facts only. It does not make permission or capability decisions (see lis-hubs-infra-access).

Used by:

It is a peer dependency of lis-hubs-infra-core, lis-hubs-infra-access and lis-infra-ui-services.

Installation

npm install @defra/lis-hubs-infra-registry

If your app uses one of the packages that lists it as a peer dependency, install it alongside them.

Usage

All exports come from the package root.

Constants

import {
  HUBS,
  TAXONOMIES,
  SPECIES,
  MODULES
} from '@defra/lis-hubs-infra-registry'

HUBS // ['front-office', 'back-office']
TAXONOMIES // [{ id: 'register', label: 'Register', summary: '...' }, ...]
SPECIES // [{ id: 'cattle', code: 'ctt', label: 'Cattle', summary: '...' }, ...]
MODULES // every module entry from src/modules.json

The supported taxonomies are register, move, death, status and home. The supported species are cattle (ctt), sheep (shp), camlid (cml), chicken (chk) and goat (gt).

Lookups

Each lookup returns null when nothing matches, except getMountsForModule and getMountPath, which throw.

import {
  getTaxonomyById,
  getSpeciesByCode,
  getModuleById,
  getModulesForHub,
  hydrateModuleMetadata
} from '@defra/lis-hubs-infra-registry'

getTaxonomyById('move') // { id: 'move', label: 'Move', summary: '...' }
getSpeciesByCode('ctt') // { id: 'cattle', code: 'ctt', label: 'Cattle', ... }
getModuleById('cattle-move') // { id: 'cattle-move', mounts: { holding: ..., assets: ... }, port: 3204, ... }
getMountsForModule('cattle-home') // { holding: '/holdings/{cph*3}/cattle', animal: '/animals/cattle', assets: '/assets/cattle-home' }
getMountPath('cattle-home', 'holding', { cph: '12/345/0001' }) // '/holdings/12/345/0001/cattle'
getModulesForHub('front-office') // every module whose `hubs` includes 'front-office'

hydrateModuleMetadata(getModuleById('cattle-move'))
// the module plus `taxonomyLabel: 'Move'` and `speciesLabel: 'Cattle'`
// (falls back to the raw id or code if there is no match; returns null for null)

Module entries

src/modules.json is an array. Each entry has these fields:

FieldTypeMeaning
idstringModule id. Matches the spoke's repo name without the lis-apps- prefix.
labelstringName shown to users.
mountsobjectURL patterns the hubs mount the spoke on, keyed by mount name (see below).
portnumberPort the spoke listens on in local development and lis-dev.
taxonomystringid of an entry in src/supported-taxonomies.json.
speciesstringcode of an entry in src/supported-species.json.
hubsstring[]Hubs that serve the module. Each must be one of HUBS.

For example:

{
  "id": "cattle-move",
  "label": "Move for Cattle",
  "mounts": {
    "holding": "/holdings/{cph*3}/cattle/move",
    "assets": "/assets/cattle-move"
  },
  "port": 3204,
  "taxonomy": "move",
  "species": "ctt",
  "hubs": ["front-office", "back-office"]
}

Mounts

A mount is a URL pattern, in hapi parameter syntax, that the hubs serve the spoke on. The URL tree puts the holding first and the species beneath it, so every spoke is reachable from a holding, and a species' home spoke is also reachable from an animal:

MountPatternServed by
holding/holdings/{cph*3}/<species>the species home
holding/holdings/{cph*3}/<species>/<taxonomy>each verb spoke
animal/animals/<species>the species home

<species> is the species id (cattle), not its code. The spoke registers its routes with the full pattern (/holdings/{cph*3}/cattle/animals), the hub forwards the request path unchanged, and both build links with getMountPath. A spoke serves its built CSS and JavaScript at its assets mount, which has no parameters so the browser can cache them across holdings.

Adding a module

  1. Create the spoke app. Name the repo lis-apps-<id>.
  2. Add the entry to src/modules.json. Use a unique id, mounts and port.
  3. If the species or taxonomy is new, add it to src/supported-species.json or src/supported-taxonomies.json first.
  4. Add a compose file for the spoke under .tools/compose in lis-dev, published on the same port.
  5. Release this package, then bump it in the hubs and other consumers.

The hubs need no route changes. createProxyPlugin in lis-hubs-infra-core reads getModulesForHub and adds a proxy route for each of the module's mounts, forwarding to the service lis-apps-<id> on its port (in local development) with the path unchanged. Spokes also read their mounts from here through lis-infra-ui-services.

Prerequisites

  • Node.js 24 (see .nvmrc, use nvm use)
  • To check changes against a consuming app: a local clone of lis-dev with its one-time setup done

Setup

Development

nvm use
npm install

Test

There are no tools to install beyond npm install. Tests use Vitest.

Running in development

This is a library, so it has no server of its own. To try a change in a consuming app without publishing, link the local copy into the lis-dev stack:

cd lis-dev
.bin/sideload link hubs/infra-registry # every installed copy now points at this repo
.bin/sideload up front-office           # optional: run a consumer locally with hot reload
.bin/sideload unlink hubs/infra-registry # when done

Running tests

npm test                 # unit tests
npm run test:coverage    # with coverage
npm run lint             # ESLint
npm run format:check     # Prettier

Before releasing a change, also run the tests of each consuming repo against the linked package.

Pipelines

Build, versioning and publishing run in GitHub Actions (.github/workflows) using Cake scripts (*.cake):

  • Pull request to main: validate (format, lint, test), Sonar analysis, version check
  • Push to a feature/ or hotfix/ branch: prerelease version and tag
  • Merge to main: release tag, then publish to npm

Versions come from git tags (SemVer). After a merge, wait for the publish job to finish before bumping the package in consuming repos.

Branching policy

The repo uses mainline development. Branch from main and name the branch:

  • feature/LREG-<ticket>-<short-kebab-description>
  • hotfix/LREG-<ticket>-<short-kebab-description>

LREG must be uppercase, because the GitHub ruleset rejects other branch names. Rebase onto main rather than merging main in.

Contributing to this project

  • Follow the Defra software development standards.
  • npm install sets up a pre-commit hook (Husky) that runs the security audit, format check and lint.
  • Feature branches bump the minor version and hotfix branches the patch version. While the package is on 0.x, a breaking change to the public API, or to the shape of a module entry, ships as a minor version, so call it out in the PR so consumers can update.
  • Open a pull request against main using the PR template. CI must pass and the Sonar quality gate must be green before merge.

Licence

THIS INFORMATION IS LICENSED UNDER THE CONDITIONS OF THE OPEN GOVERNMENT LICENCE found at:

http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3

The following attribution statement MUST be cited in your products and applications when using this information.

Contains public sector information licensed under the Open Government licence v3

About the licence

The Open Government Licence (OGL) was developed by the Controller of His Majesty's Stationery Office (HMSO) to enable information providers in the public sector to license the use and re-use of their information under a common open licence.

It is designed to encourage use and re-use of information freely and flexibly, with only a few conditions.

版本与发布记录

@defra/lis-hubs-infra-registry 共发布 40 个版本,首次发布于 2026/08/10;过去 12 个月发布了 40 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.13.8latest2026/11/101 天前
0.13.72026/11/092 天前
0.13.62026/11/092 天前
0.13.52026/11/092 天前
0.13.42026/11/092 天前
0.13.4-lreg-000.alpha.1alpha2026/11/092 天前

关于 @defra/lis-hubs-infra-registry 的常见问题

@defra/lis-hubs-infra-registry 是什么?

Shared infra registry metadata for the livestock platform.

如何安装 @defra/lis-hubs-infra-registry?

在项目目录运行 npm install @defra/lis-hubs-infra-registry,或使用 pnpm add / yarn add / bun add。

@defra/lis-hubs-infra-registry 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/defra__lis-hubs-infra-registry 是否存在。

@defra/lis-hubs-infra-registry 支持 ESM 还是 CommonJS?

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

@defra/lis-hubs-infra-registry 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@defra/lis-hubs-infra-registry 可以商用吗?

@defra/lis-hubs-infra-registry 使用 OGL-UK-3.0 许可。声明的许可为 OGL-UK-3.0,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@defra/lis-hubs-infra-registry 的下载量有多少?

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

@defra/lis-hubs-infra-registry 还在维护吗?

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